allow db-tools to edit meta information about schema, currently what is stored in integer columns, eg: "timestamp", "account", "account-commasep" or "category"

This commit is contained in:
Ralf Becker 2013-06-11 14:48:25 +00:00
parent 754e93486e
commit 8d07c880ad
3 changed files with 115 additions and 47 deletions

View File

@ -4,7 +4,7 @@
* *
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker@outdoor-training.de> * @author Ralf Becker <RalfBecker@outdoor-training.de>
* @copyright 2002-9 by RalfBecker@outdoor-training.de * @copyright 2002-13 by RalfBecker@outdoor-training.de
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate * @package etemplate
* @subpackage tools * @subpackage tools
@ -71,6 +71,26 @@ class db_tools
'bool' => 'boolean', 'bool' => 'boolean',
// 'abstime' => 'abstime (mysql:timestamp)', // 'abstime' => 'abstime (mysql:timestamp)',
); );
/**
* Available meta-types
*
* @var array
*/
protected static $meta_types = array(
'' => '',
'account' => 'user or group',
'account-commasep' => 'multiple comma-separated users or groups',
'account-abs' => 'user or group (with positiv id)',
'user' => 'a single user',
'user-commasep' => 'multiple comma-separated users',
'user-serialized' => 'multiple serialized users or groups (do NOT use!)',
'group' => 'a single group',
'group-commasep' => 'multiple comma-separated groups',
'group-abs' => 'single group (with positive id)',
'timestamp' => 'unix timestamp',
'category' => 'category id',
'percent' => '0 - 100',
);
/** /**
* constructor of class * constructor of class
@ -223,8 +243,32 @@ class db_tools
} }
$sel_options = array( $sel_options = array(
'table_name' => $table_names, 'table_name' => $table_names,
'type' => $this->types 'type' => $this->types,
); );
foreach(self::$meta_types as $value => $title)
{
$sel_options['meta'][$value] = $value ? array(
'label' => $value,
'title' => $title,
) : $title;
}
foreach($this->data[$this->table]['fd'] as $col => $data)
{
$meta = $title = $data['meta'];
if (empty($meta)) continue;
if (is_array($meta))
{
$this->data[$this->table]['fd'][$col]['meta'] = $meta = serialize($meta);
$title = $this->write_array($data['meta'], 0);
}
if (!isset($sel_options['meta'][$meta]))
{
$sel_options['meta'][$meta] = array(
'label' => lang('Custom'),
'title' => $title,
);
}
}
if ($this->table != '' && isset($this->data[$this->table])) if ($this->table != '' && isset($this->data[$this->table]))
{ {
$content += $this->table2content($this->data[$this->table],$sel_options['Index'],$add_index); $content += $this->table2content($this->data[$this->table],$sel_options['Index'],$add_index);
@ -492,6 +536,7 @@ class db_tools
{ {
case 'default': case 'default':
case 'type': // selectbox ensures type is not empty case 'type': // selectbox ensures type is not empty
case 'meta':
case 'precision': case 'precision':
case 'scale': case 'scale':
case 'comment': case 'comment':
@ -625,7 +670,20 @@ class db_tools
{ {
if (!is_int($key)) if (!is_int($key))
{ {
$def .= "'$key' => "; if (strpos($key, "'") !== false && strpos($key, '"') === false)
{
$def .= '"'.$key.'"';
}
else
{
$def .= "'".addslashes($key)."'";
}
$def .= ' => ';
}
// unserialize custom meta values
if ($key === 'meta' && is_string($val) && (($v = @unserialize($val)) !== false || $val === serialize(false)))
{
$val = $v;
} }
if (is_array($val)) if (is_array($val))
{ {
@ -637,9 +695,13 @@ class db_tools
{ {
$def .= $val ? 'True' : 'False'; $def .= $val ? 'True' : 'False';
} }
elseif (strpos($val, "'") !== false && strpos($val, '"') === false)
{
$def .= '"'.$val.'"';
}
else else
{ {
$def .= "'$val'"; $def .= "'".addslashes($val)."'";
} }
} }
if ($n < count($arr)-1) if ($n < count($arr)-1)
@ -1044,6 +1106,7 @@ function $app"."_upgrade$old_version_()
'nullable' => !isset($props['nullable']) || !!$props['nullable'], 'nullable' => !isset($props['nullable']) || !!$props['nullable'],
'default' => (string)$props['default'], 'default' => (string)$props['default'],
'comment' => (string)$props['comment'], 'comment' => (string)$props['comment'],
'meta' => is_array($props['meta']) ? serialize($props['meta']) : $props['meta'],
); );
} }
return array( return array(

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- $Id$ --> <!-- $Id$ -->
<overlay> <overlay>
<template id="etemplate.db-tools.cols" template="" lang="" group="0" version="1.7.001"> <template id="etemplate.db-tools.cols" template="" lang="" group="0" version="1.9.001">
<grid> <grid>
<columns> <columns>
<column/> <column/>
@ -18,12 +18,14 @@
<column/> <column/>
<column/> <column/>
<column/> <column/>
<column/>
</columns> </columns>
<rows> <rows>
<row class="nmh"> <row class="nmh">
<description value="#" no_lang="1" align="center"/> <description align="center" value="#" no_lang="1"/>
<description value="ColumnName"/> <description value="ColumnName"/>
<description value="Type"/> <description value="Type"/>
<description value="Meta-type"/>
<description value="Precision"/> <description value="Precision"/>
<description value="Scale"/> <description value="Scale"/>
<description value="NOT NULL"/> <description value="NOT NULL"/>
@ -34,25 +36,28 @@
<description value="Comment"/> <description value="Comment"/>
<description value="Indexoptions"/> <description value="Indexoptions"/>
<description value="Foreign Key"/> <description value="Foreign Key"/>
<button label="Add Column" align="center" id="add_column" statustext="Add a new column (after the existing ones)"/> <button align="center" statustext="Add a new column (after the existing ones)" label="Add Column" id="add_column"/>
</row> </row>
<row class="nmr"> <row class="nmr">
<description no_lang="1" align="center" id="Row${row}[n]"/> <description align="center" id="Row${row}[n]" no_lang="1"/>
<textbox size="15" no_lang="1" id="Row${row}[name]" statustext="need to be unique in the table and no reseved word from SQL, best prefix all with a common 2-digit short for the app, eg. 'et_'"/> <textbox statustext="need to be unique in the table and no reseved word from SQL, best prefix all with a common 2-digit short for the app, eg. 'et_'" id="Row${row}[name]" no_lang="1" size="15"/>
<menulist> <menulist>
<menupopup no_lang="1" id="Row${row}[type]" statustext="type of the column"/> <menupopup statustext="type of the column" id="Row${row}[type]" no_lang="1"/>
</menulist> </menulist>
<int align="center" id="Row${row}[precision]" statustext="length for char+varchar, precisions int: 2, 4, 8 and float: 4, 8"/> <menulist class="selectboxFullWidth">
<int id="Row${row}[scale]" statustext="scale for float"/> <menupopup statustext="meta-type of the column" id="Row${row}[meta]" no_lang="1" options=",,,,,,,0"/>
<checkbox align="center" id="Row${row}[notnull]" statustext="can not have special SQL-value NULL"/> </menulist>
<checkbox align="center" id="Row${row}[pk]" statustext="Primary key for the table, gets automaticaly indexed"/> <textbox type="integer" align="center" statustext="length for char+varchar, precisions int: 2, 4, 8 and float: 4, 8" id="Row${row}[precision]"/>
<checkbox align="center" id="Row${row}[uc]" statustext="DB ensures that every row has a unique value in that column"/> <textbox type="integer" statustext="scale for float" id="Row${row}[scale]"/>
<checkbox align="center" id="Row${row}[ix]" statustext="an indexed column speeds up querys using that column (cost space on the disk !!!)"/> <checkbox align="center" statustext="can not have special SQL-value NULL" id="Row${row}[notnull]"/>
<textbox size="8" id="Row${row}[default]" statustext="enter '' for an empty default, nothing mean no default"/> <checkbox align="center" statustext="Primary key for the table, gets automaticaly indexed" id="Row${row}[pk]"/>
<textbox size="20" id="Row${row}[comment]"/> <checkbox align="center" statustext="DB ensures that every row has a unique value in that column" id="Row${row}[uc]"/>
<textbox size="8" id="Row${row}[options]" statustext="DB-specific index options (comma-sep.), eg. mysql(FULLTEXT) or mysql(100) for the indexed length of a col"/> <checkbox align="center" statustext="an indexed column speeds up querys using that column (cost space on the disk !!!)" id="Row${row}[ix]"/>
<textbox size="8" align="center" id="Row${row}[fk]" statustext="name of other table where column is a key from"/> <textbox statustext="enter '' for an empty default, nothing mean no default" id="Row${row}[default]" size="8"/>
<button label="Delete Column" align="center" id="delete[$row]" statustext="Deletes this column"/> <textbox id="Row${row}[comment]" size="20"/>
<textbox statustext="DB-specific index options (comma-sep.), eg. mysql(FULLTEXT) or mysql(100) for the indexed length of a col" id="Row${row}[options]" size="8"/>
<textbox align="center" statustext="name of other table where column is a key from" id="Row${row}[fk]" size="8"/>
<button align="center" statustext="Deletes this column" label="Delete Column" id="delete[$row]"/>
</row> </row>
</rows> </rows>
</grid> </grid>
@ -73,10 +78,10 @@
</columns> </columns>
<rows> <rows>
<row class="th"> <row class="th">
<description span="all" value="Multicolumn Indices"/> <description value="Multicolumn Indices" span="all"/>
</row> </row>
<row class="th"> <row class="th">
<description value="#" no_lang="1" align="center"/> <description align="center" value="#" no_lang="1"/>
<description value="ColumnName"/> <description value="ColumnName"/>
<description value="ColumnName"/> <description value="ColumnName"/>
<description value="ColumnName"/> <description value="ColumnName"/>
@ -85,33 +90,33 @@
<description value="ColumnName"/> <description value="ColumnName"/>
<description value="ColumnName"/> <description value="ColumnName"/>
<description value="Unique"/> <description value="Unique"/>
<button label="Add Index" align="center" id="add_index" statustext="Add a new multi-column index"/> <button align="center" statustext="Add a new multi-column index" label="Add Index" id="add_index"/>
</row> </row>
<row class="row"> <row class="row">
<description no_lang="1" align="center" id="Index[$row][n]"/> <description align="center" id="Index[$row][n]" no_lang="1"/>
<menulist> <menulist>
<menupopup options="none" no_lang="1" id="Index[$row][0]" statustext="Select the indexed columns in their desired order"/> <menupopup statustext="Select the indexed columns in their desired order" id="Index[$row][0]" no_lang="1" options="none"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup options="none" no_lang="1" align="center" id="Index[$row][1]" statustext="Select the indexed columns in their desired order"/> <menupopup align="center" statustext="Select the indexed columns in their desired order" id="Index[$row][1]" no_lang="1" options="none"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup options="none" no_lang="1" id="Index[$row][2]" statustext="Select the indexed columns in their desired order"/> <menupopup statustext="Select the indexed columns in their desired order" id="Index[$row][2]" no_lang="1" options="none"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup options="none" no_lang="1" align="center" id="Index[$row][3]" statustext="Select the indexed columns in their desired order"/> <menupopup align="center" statustext="Select the indexed columns in their desired order" id="Index[$row][3]" no_lang="1" options="none"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup options="none" no_lang="1" id="Index[$row][4]" statustext="Select the indexed columns in their desired order"/> <menupopup statustext="Select the indexed columns in their desired order" id="Index[$row][4]" no_lang="1" options="none"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup options="none" no_lang="1" id="Index[$row][5]" statustext="Select the indexed columns in their desired order"/> <menupopup statustext="Select the indexed columns in their desired order" id="Index[$row][5]" no_lang="1" options="none"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup options="none" no_lang="1" id="Index[$row][6]" statustext="Select the indexed columns in their desired order"/> <menupopup statustext="Select the indexed columns in their desired order" id="Index[$row][6]" no_lang="1" options="none"/>
</menulist> </menulist>
<checkbox align="center" id="Index[$row][unique]" statustext="DB ensures that every row has a unique value in that column"/> <checkbox align="center" statustext="DB ensures that every row has a unique value in that column" id="Index[$row][unique]"/>
<button label="Delete Index" align="center" id="delete_index[$row]" statustext="Deletes this index"/> <button align="center" statustext="Deletes this index" label="Delete Index" id="delete_index[$row]"/>
</row> </row>
</rows> </rows>
</grid> </grid>
@ -129,7 +134,7 @@
</columns> </columns>
<rows> <rows>
<row disabled="!@msg"> <row disabled="!@msg">
<description span="all" class="redItalic" id="msg"/> <description id="msg" span="all" class="redItalic"/>
<description/> <description/>
<description/> <description/>
<description/> <description/>
@ -139,22 +144,22 @@
</row> </row>
<row> <row>
<menulist> <menulist>
<menupopup type="select-app" options="Select one ...,,all" label="Application" no_lang="1" id="app" onchange="1" statustext="Select an application, (*) = uninstalled"/> <menupopup type="select-app" statustext="Select an application, (*) = uninstalled" label="Application" id="app" no_lang="1" onchange="1" options="Select one ...,,all"/>
</menulist> </menulist>
<menulist> <menulist>
<menupopup label="TableName" no_lang="1" id="table_name" onchange="1" statustext="Select an table of the application"/> <menupopup statustext="Select an table of the application" label="TableName" id="table_name" no_lang="1" onchange="1"/>
</menulist> </menulist>
<textbox size="20" align="right" id="new_table_name" statustext="Name of table to add"/> <textbox align="right" statustext="Name of table to add" id="new_table_name" size="20"/>
<button label="Add Table" id="add_table" statustext="Create a new table for the application"/> <button statustext="Create a new table for the application" label="Add Table" id="add_table"/>
<button label="Import" id="import" statustext="Import table-definitions from existing db-table"/> <button statustext="Import table-definitions from existing db-table" label="Import" id="import"/>
<button label="Drop Table" id="drop_table" disabled="true" statustext="Drop a table - this can NOT be undone"/> <button disabled="true" statustext="Drop a table - this can NOT be undone" label="Drop Table" id="drop_table"/>
<button label="Write Tables" id="write_tables" statustext="Write &lt;app&gt;/setup/tables_current.inc.php"/> <button statustext="Write &lt;app&gt;/setup/tables_current.inc.php" label="Write Tables" id="write_tables"/>
</row> </row>
<row> <row>
<template span="all" id="etemplate.db-tools.cols"/> <template id="etemplate.db-tools.cols" span="all"/>
</row> </row>
<row> <row>
<template span="all" id="etemplate.db-tools.indices"/> <template id="etemplate.db-tools.indices" span="all"/>
</row> </row>
</rows> </rows>
</grid> </grid>