"- fixed sometimes not working delete of a column (seems to be php5 related, as it was working before)

- removed one idention from tables_{current|update}.inc.php
- removed closing ?> tag"
This commit is contained in:
Ralf Becker 2008-05-24 06:39:05 +00:00
parent 17b8868698
commit c45e0ee9fe

View File

@ -122,10 +122,8 @@ class db_tools
elseif ($content['delete']) elseif ($content['delete'])
{ {
list($col) = each($content['delete']); list($col) = each($content['delete']);
@reset($this->data[$posted_table]['fd']); @reset($this->data[$posted_table]['fd']);
while ($col-- > 0 && list($key,$data) = @each($this->data[$posted_table]['fd'])) ; while ($col-- > 0 && list($key) = @each($this->data[$posted_table]['fd'])) ;
unset($this->data[$posted_table]['fd'][$key]); unset($this->data[$posted_table]['fd'][$key]);
$this->changes[$posted_table][$key] = '**deleted**'; $this->changes[$posted_table][$key] = '**deleted**';
} }
@ -205,7 +203,7 @@ class db_tools
$no_button = array( ); $no_button = array( );
if (!$this->app || !$this->table) if (!$this->app || !$this->table)
{ {
$no_button += array('write_tables' => True); $no_button['write_tables'] = True;
} }
if ($this->debug) if ($this->debug)
{ {
@ -352,8 +350,13 @@ class db_tools
*/ */
function table2content($table,&$columns,$extra_index=False) function table2content($table,&$columns,$extra_index=False)
{ {
if ($this->debug >= 3)
{
echo __METHOD__."(\$table,,$extra_index) \$table ="; _debug_array($table);
}
$content = $columns = array(); $content = $columns = array();
for ($n = 1; list($col_name,$col_defs) = each($table['fd']); ++$n) $n = 1;
foreach($table['fd'] as $col_name => $col_defs)
{ {
$col_defs['name'] = $col_name; $col_defs['name'] = $col_name;
$col_defs['pk'] = in_array($col_name,$table['pk']); $col_defs['pk'] = in_array($col_name,$table['pk']);
@ -370,7 +373,7 @@ class db_tools
$content["Row$n"] = $col_defs; $content["Row$n"] = $col_defs;
$columns[$n] = $col_name; $columns[$n++] = $col_name;
} }
$n = 2; $n = 2;
foreach(array('uc','ix') as $type) foreach(array('uc','ix') as $type)
@ -395,8 +398,8 @@ class db_tools
} }
if ($this->debug >= 3) if ($this->debug >= 3)
{ {
echo "<p>table2content(,,'$extra_index'): content ="; _debug_array($content); echo "content ="; _debug_array($content);
echo "<p>columns ="; _debug_array($columns); echo "columns ="; _debug_array($columns);
} }
return $content; return $content;
} }
@ -461,8 +464,7 @@ class db_tools
case 'type': // selectbox ensures type is not empty case 'type': // selectbox ensures type is not empty
case 'precision': case 'precision':
case 'scale': case 'scale':
// case 'nullable': if ($val != '')
if ($val != '' || $prop == 'nullable')
{ {
$table['fd'][$name][$prop] = $prop=='default'&& $val=="''" ? '' : $val; $table['fd'][$name][$prop] = $prop=='default'&& $val=="''" ? '' : $val;
} }
@ -582,14 +584,10 @@ class db_tools
} }
if ($depth) if ($depth)
{ {
$tabs = "\n"; $tabs = "\n".str_repeat("\t",$depth-1);
for ($n = 0; $n < $depth; ++$n)
{
$tabs .= "\t";
}
++$depth; ++$depth;
} }
$def = "array($tabs".($tabs ? "\t" : ''); $def = 'array('.$tabs.($tabs ? "\t" : '');
$n = 0; $n = 0;
foreach($arr as $key => $val) foreach($arr as $key => $val)
@ -615,11 +613,11 @@ class db_tools
} }
if ($n < count($arr)-1) if ($n < count($arr)-1)
{ {
$def .= ",$tabs".($tabs ? "\t" : ''); $def .= ','.$tabs.($tabs ? "\t" : '');
} }
++$n; ++$n;
} }
$def .= "$tabs)"; $def .= $tabs.')';
return $def; return $def;
} }
@ -667,7 +665,7 @@ class db_tools
{ {
return False; return False;
} }
$def .= "\t\$phpgw_baseline = "; $def .= "\$phpgw_baseline = ";
$def .= $this->write_array($phpgw_baseline,1); $def .= $this->write_array($phpgw_baseline,1);
$def .= ";\n"; $def .= ";\n";
@ -803,15 +801,9 @@ class db_tools
{ {
return False; return False;
} }
$file_baseline = EGW_SERVER_ROOT."/$app/setup/tables_baseline.inc.php";
$file_current = EGW_SERVER_ROOT."/$app/setup/tables_current.inc.php"; $file_current = EGW_SERVER_ROOT."/$app/setup/tables_current.inc.php";
$file_update = EGW_SERVER_ROOT."/$app/setup/tables_update.inc.php"; $file_update = EGW_SERVER_ROOT."/$app/setup/tables_update.inc.php";
if (!file_exists($file_baseline) && !copy($file_current,$file_baseline))
{
//echo "<p>Can't copy $file_current to $file_baseline !!!</p>\n";
return False;
}
$old_version = $this->setup_version($app); $old_version = $this->setup_version($app);
$old_version_ = str_replace('.','_',$old_version); $old_version_ = str_replace('.','_',$old_version);
@ -833,7 +825,6 @@ class db_tools
$update = $this->setup_header($this->app); $update = $this->setup_header($this->app);
} }
$update .= " $update .= "
\$test[] = '$old_version';
function $app"."_upgrade$old_version_() function $app"."_upgrade$old_version_()
{\n"; {\n";
@ -842,7 +833,7 @@ class db_tools
$update .= " $update .= "
return \$GLOBALS['setup_info']['$app']['currentver'] = '$version'; return \$GLOBALS['setup_info']['$app']['currentver'] = '$version';
} }
?".">\n"; \n";
if (!($f = fopen($file_update,'w'))) if (!($f = fopen($file_update,'w')))
{ {
//echo "<p>Cant open '$update' for writing !!!</p>\n"; //echo "<p>Cant open '$update' for writing !!!</p>\n";
@ -890,7 +881,7 @@ class db_tools
{ {
if (!isset($current[$name])) // table $name droped if (!isset($current[$name])) // table $name droped
{ {
$update .= "\t\t\$GLOBALS['egw_setup']->oProc->DropTable('$name');\n"; $update .= "\t\$GLOBALS['egw_setup']->oProc->DropTable('$name');\n";
} }
else else
{ {
@ -908,13 +899,13 @@ class db_tools
$this->remove_from_array($new_table_def['fk'],$col); $this->remove_from_array($new_table_def['fk'],$col);
$this->remove_from_array($new_table_def['ix'],$col); $this->remove_from_array($new_table_def['ix'],$col);
$this->remove_from_array($new_table_def['uc'],$col); $this->remove_from_array($new_table_def['uc'],$col);
$update .= "\t\t\$GLOBALS['egw_setup']->oProc->DropColumn('$name',"; $update .= "\t\$GLOBALS['egw_setup']->oProc->DropColumn('$name',";
$update .= $this->write_array($new_table_def,2).",'$col');\n"; $update .= $this->write_array($new_table_def,2).",'$col');\n";
} }
else // column $col renamed else // column $col renamed
{ {
$new_col = $this->changes[$name][$col]; $new_col = $this->changes[$name][$col];
$update .= "\t\t\$GLOBALS['egw_setup']->oProc->RenameColumn('$name','$col','$new_col');\n"; $update .= "\t\$GLOBALS['egw_setup']->oProc->RenameColumn('$name','$col','$new_col');\n";
} }
} }
} }
@ -937,7 +928,7 @@ class db_tools
{ {
$tables .= ($tables ? ',' : '') . "'$name'"; $tables .= ($tables ? ',' : '') . "'$name'";
$update .= "\t\t\$GLOBALS['egw_setup']->oProc->CreateTable('$name',"; $update .= "\t\$GLOBALS['egw_setup']->oProc->CreateTable('$name',";
$update .= $this->write_array($table_def,2).");\n"; $update .= $this->write_array($table_def,2).");\n";
} }
else else
@ -955,14 +946,14 @@ class db_tools
if (($add = !isset($old[$name]['fd'][$col])) || // column $col added if (($add = !isset($old[$name]['fd'][$col])) || // column $col added
serialize($old_norm_fd[$col]) != serialize($new_norm_fd[$col])) // column definition altered serialize($old_norm_fd[$col]) != serialize($new_norm_fd[$col])) // column definition altered
{ {
$update .= "\t\t".($do_refresh ? "/* done by RefreshTable() anyway\n\t\t" : ''). $update .= "\t".($do_refresh ? "/* done by RefreshTable() anyway\n\t" : '').
"\$GLOBALS['egw_setup']->oProc->".($add ? 'Add' : 'Alter')."Column('$name','$col',"; "\$GLOBALS['egw_setup']->oProc->".($add ? 'Add' : 'Alter')."Column('$name','$col',";
$update .= $this->write_array($col_def,2) . ');' . ($do_refresh ? '*/' : '') . "\n"; $update .= $this->write_array($col_def,2) . ');' . ($do_refresh ? '*/' : '') . "\n";
} }
} }
if ($do_refresh) if ($do_refresh)
{ {
$update .= "\t\t\$GLOBALS['egw_setup']->oProc->RefreshTable('$name',"; $update .= "\t\$GLOBALS['egw_setup']->oProc->RefreshTable('$name',";
$update .= $this->write_array($table_def,2).");\n"; $update .= $this->write_array($table_def,2).");\n";
} }
} }
@ -1060,7 +1051,6 @@ class db_tools
function setup_header($app) function setup_header($app)
{ {
return '<?php return '<?php
/** /**
* eGroupWare - Setup * eGroupWare - Setup
* http://www.egroupware.org * http://www.egroupware.org