* Setup/API: improved diagnostics about db connection problem and not installed EGroupware

- removed deprecated egw_db->Halt_On_Error handling in favor of just exceptions
- added a couple of exceptions extending egw_exception_db to be able to detect different problem areas
- fixed setup to use / catch exceptions
- new egw_exception_db_setup displays link to setup below exception message, to cope with no longer allowed html in exception messages
This commit is contained in:
Ralf Becker 2013-03-05 10:50:43 +00:00
parent 8703b9a8e8
commit 93710e09e1
7 changed files with 249 additions and 286 deletions

View File

@ -90,30 +90,32 @@ class egw extends egw_minimal
// check if eGW is already setup, if not redirect to setup/ // check if eGW is already setup, if not redirect to setup/
try { try {
$this->db->connect(); $this->db->connect();
if (!($num_config = $this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn())) $num_config = $this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
{ }
catch(egw_exception_db_connection $e) {
// ignore exception, get handled below
}
catch(egw_exception_db_invalid_sql $e1) {
try {
$phpgw_config = $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn(); $phpgw_config = $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
} }
catch (egw_exception_db_invalid_sql $e2) {
// ignor error, get handled below
}
} }
catch(Exception $e) { if (!$num_config)
//echo "<pre>Connection to DB failed (".$e->getMessage().")!\n".$e->getTraceAsString();
}
if ($e || !$num_config)
{ {
$setup_dir = str_replace(array('home/index.php','index.php'),'setup/',$_SERVER['PHP_SELF']);
// we check for the old table too, to not scare updating users ;-) // we check for the old table too, to not scare updating users ;-)
if ($phpgw_config) if ($phpgw_config)
{ {
throw new Exception('<center><b>Fatal Error:</b> You need to <a href="' . $setup_dir . throw new Exception('You need to update EGroupware before you can continue using it.',999);
'">update eGroupWare</a> before you can continue using it.</center>',999);
} }
else if ($e)
{ {
throw new Exception('<center><b>Fatal Error:</b> It appears that you have not created the database tables for ' throw new egw_exception_db_setup('Connection with '.$e->getMessage()."\n\n".
.'eGroupWare. Click <a href="' . $setup_dir . '">here</a> to run setup.</center>',999); 'Maybe you not created a database for EGroupware yet.',999);
} }
exit; throw new egw_exception_db_setup('It appears that you have not created the database tables for EGroupware.',999);
} }
// Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in config::read) // Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in config::read)
foreach($GLOBALS['egw_info']['server']['system_charset'] = $this->db->select(config::TABLE,'config_name,config_value',array( foreach($GLOBALS['egw_info']['server']['system_charset'] = $this->db->select(config::TABLE,'config_name,config_value',array(
@ -213,7 +215,7 @@ class egw extends egw_minimal
} }
/** /**
* wakeup2 funcontion needs to be called after unserializing the egw-object * wakeup2 function needs to be called after unserializing the egw-object
* *
* It adapts the restored object/enviroment to the changed (current) application / page-request * It adapts the restored object/enviroment to the changed (current) application / page-request
* *

View File

@ -107,12 +107,6 @@ class egw_db
*/ */
var $Debug = 0; var $Debug = 0;
/**
* @deprecated use exceptions (try/catch block) to handle failed connections or sql errors
* @var string $Halt_On_Error "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore errror, but spit a warning)
*/
var $Halt_On_Error = 'yes';
/** /**
* @var array $Record current record * @var array $Record current record
*/ */
@ -400,8 +394,7 @@ class egw_db
{ {
if (!check_load_extension($php_extension)) if (!check_load_extension($php_extension))
{ {
$this->halt("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!"); throw new egw_exception_db_connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!");
return null; // in case error-reporting = 'no'
} }
if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection
{ {
@ -414,8 +407,7 @@ class egw_db
$this->Link_ID = ADONewConnection($type); $this->Link_ID = ADONewConnection($type);
if (!$this->Link_ID) if (!$this->Link_ID)
{ {
$this->halt("No ADOdb support for '$type' ($this->Type) !!!"); throw new egw_exception_db_connection("No ADOdb support for '$type' ($this->Type) !!!");
return null; // in case error-reporting = 'no'
} }
$connect = $GLOBALS['egw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect'; $connect = $GLOBALS['egw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect';
if (($Ok = $this->Link_ID->$connect($Host, $User, $Password))) if (($Ok = $this->Link_ID->$connect($Host, $User, $Password)))
@ -430,8 +422,7 @@ class egw_db
if (!$Ok) if (!$Ok)
{ {
$Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password
$this->halt("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); throw new egw_exception_db_connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed.");
return null; // in case error-reporting = 'no'
} }
if ($this->Debug) if ($this->Debug)
{ {
@ -671,9 +662,8 @@ class egw_db
} }
if (!$this->Query_ID) if (!$this->Query_ID)
{ {
$this->halt("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). throw new egw_exception_db_invalid_sql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String).
($inputarr ? "<br>Parameters: '".implode("','",$inputarr)."'":''), ($inputarr ? "<br>Parameters: '".implode("','",$inputarr)."'":''));
$line, $file);
} }
return $this->Query_ID; return $this->Query_ID;
} }
@ -707,8 +697,7 @@ class egw_db
{ {
if (!$this->Query_ID) if (!$this->Query_ID)
{ {
$this->halt('next_record called with no query pending.'); throw new egw_exception_db('next_record called with no query pending.');
return 0;
} }
if ($this->Row) // first row is already fetched if ($this->Row) // first row is already fetched
{ {
@ -763,10 +752,7 @@ class egw_db
{ {
if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos)) if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos))
{ {
$this->halt("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); throw new egw_exception_db("seek($pos) failed: resultset has " . $this->num_rows() . " rows");
$this->Query_ID->Move( $this->num_rows() );
$this->Row = $this->num_rows();
return False;
} }
return True; return True;
} }
@ -973,65 +959,6 @@ class egw_db
return $result; return $result;
} }
/**
* Error handler
*
* @param string $msg error message
* @param int $line line of calling method/function (optional)
* @param string $file file of calling method/function (optional)
*/
function halt($msg, $line = '', $file = '')
{
if ($this->Link_ID) // only if we have a link, else infinite loop
{
$this->Error = $this->Link_ID->ErrorMsg(); // need to be BEFORE unlock,
$this->Errno = $this->Link_ID->ErrorNo(); // else we get its error or none
$this->unlock(); /* Just in case there is a table currently locked */
}
if ($this->Halt_On_Error == "no")
{
return;
}
if ($this->Halt_On_Error == 'yes')
{
throw new egw_exception_db($msg.($this->Error?":\n".$this->Error:''),$this->Errno);
}
$this->haltmsg($msg);
if ($file)
{
printf("<br /><b>File:</b> %s",$file);
}
if ($line)
{
printf("<br /><b>Line:</b> %s",$line);
}
printf("<br /><b>Function:</b> %s</p>\n",function_backtrace(2));
if ($this->Halt_On_Error != "report")
{
echo "<p><b>Session halted.</b></p>";
if (is_object($GLOBALS['egw']->common))
{
$GLOBALS['egw']->common->egw_exit(True);
}
else // happens eg. in setup
{
exit();
}
}
}
function haltmsg($msg)
{
printf("<p><b>Database error:</b> %s<br>\n", $msg);
if (($this->Errno || $this->Error) && $this->Error != "()")
{
printf("<b>$this->Type Error</b>: %s (%s)<br>\n",$this->Errno,$this->Error);
}
}
/** /**
* Get description of a table * Get description of a table
* *
@ -1061,7 +988,6 @@ class egw_db
if($column->primary_key) $flags .= "primary_key "; if($column->primary_key) $flags .= "primary_key ";
if($column->binary) $flags .= "binary "; if($column->binary) $flags .= "binary ";
// _debug_array($column);
$metadata[$i] = array( $metadata[$i] = array(
'table' => $table, 'table' => $table,
'name' => $column->name, 'name' => $column->name,
@ -1523,8 +1449,7 @@ class egw_db
if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key]))
{ {
// give a warning that we have no column-type throw new egw_exception_db_invalid_sql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>");
$this->halt("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>");
} }
$column_type = is_array($column_definitions) ? @$column_definitions[$key]['type'] : False; $column_type = is_array($column_definitions) ? @$column_definitions[$key]['type'] : False;
$not_null = is_array($column_definitions) && isset($column_definitions[$key]['nullable']) ? !$column_definitions[$key]['nullable'] : false; $not_null = is_array($column_definitions) && isset($column_definitions[$key]['nullable']) ? !$column_definitions[$key]['nullable'] : false;
@ -1912,7 +1837,7 @@ class egw_db
{ {
$ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB');
if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where') = '$ret'</p>\n"; if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where') = '$ret'</p>\n";
if (!$ret) $this->halt("Error in UpdateBlob($table,$col,\$val,$where)",$line,$file); if (!$ret) throw new egw_exception_db_invalid_sql("Error in UpdateBlob($table,$col,\$val,$where)",$line,$file);
} }
} }
return $ret; return $ret;

View File

@ -138,8 +138,7 @@ class egw_exception_wrong_parameter extends egw_exception_assertion_failed { }
class egw_exception_wrong_userinput extends egw_exception_assertion_failed { } class egw_exception_wrong_userinput extends egw_exception_assertion_failed { }
/** /**
* Exceptions thrown by the egw_db class * Exception thrown by the egw_db class for everything not covered by extended classed below
*
*/ */
class egw_exception_db extends egw_exception class egw_exception_db extends egw_exception
{ {
@ -159,6 +158,25 @@ class egw_exception_db extends egw_exception
/** /**
* Storing the row violates a unique key constrain * Storing the row violates a unique key constrain
*
*/ */
class egw_exception_db_not_unique extends egw_exception_db { } class egw_exception_db_not_unique extends egw_exception_db { }
/**
* Can not connect to database: eg. database down, wrong host, name or credentials
*/
class egw_exception_db_connection extends egw_exception_db { }
/**
* PHP lackst support for configured database type
*/
class egw_exception_db_support extends egw_exception_db { }
/**
* Classic invalid SQL error
*/
class egw_exception_db_invalid_sql extends egw_exception_db { }
/**
* EGroupware not (fully) installed, visit setup
*/
class egw_exception_db_setup extends egw_exception_db { }

View File

@ -1589,7 +1589,12 @@ function egw_exception_handler(Exception $e)
$message .= html::htmlspecialchars($e->getTraceAsString()); $message .= html::htmlspecialchars($e->getTraceAsString());
} }
$message .= "</pre>\n"; $message .= "</pre>\n";
if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->session) && method_exists($GLOBALS['egw'],'link')) if (is_a($e, 'egw_exception_db_setup'))
{
$setup_dir = str_replace(array('home/index.php','index.php'),'setup/',$_SERVER['PHP_SELF']);
$message .= '<a href="'.$setup_dir.'">Run setup to install or configure EGroupware.</a>';
}
elseif (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->session) && method_exists($GLOBALS['egw'],'link'))
{ {
$message .= '<p><a href="'.$GLOBALS['egw']->link('/index.php').'">'.try_lang('Click here to resume your eGroupWare Session.').'</a></p>'; $message .= '<p><a href="'.$GLOBALS['egw']->link('/index.php').'">'.try_lang('Click here to resume your eGroupWare Session.').'</a></p>';
} }

View File

@ -122,34 +122,36 @@ class setup
if ($connect_and_setcharset) if ($connect_and_setcharset)
{ {
$this->db->Halt_On_Error = 'no'; // table might not be created at that stage try {
$this->set_table_names(); // sets/checks config- and applications-table-name
$this->set_table_names(); // sets/checks config- and applications-table-name // Set the DB's client charset if a system-charset is set
$this->db->select($this->config_table,'config_value',array(
// Set the DB's client charset if a system-charset is set 'config_app' => 'phpgwapi',
$this->db->select($this->config_table,'config_value',array( 'config_name' => 'system_charset',
'config_app' => 'phpgwapi', ),__LINE__,__FILE__);
'config_name' => 'system_charset', if ($this->db->next_record() && $this->db->f(0))
),__LINE__,__FILE__);
if ($this->db->next_record() && $this->db->f(0))
{
$this->system_charset = $this->db->f(0);
$this->db_charset_was = $this->db->Link_ID->GetCharSet(); // needed for the update
// we can NOT set the DB charset for mysql, if the api version < 1.0.1.019, as it would mess up the DB content!!!
if (substr($this->db->Type,0,5) == 'mysql') // we need to check the api version
{ {
$this->db->select($this->applications_table,'app_version',array( $this->system_charset = $this->db->f(0);
'app_name' => 'phpgwapi', $this->db_charset_was = $this->db->Link_ID->GetCharSet(); // needed for the update
),__LINE__,__FILE__);
$api_version = $this->db->next_record() ? $this->db->f(0) : false; // we can NOT set the DB charset for mysql, if the api version < 1.0.1.019, as it would mess up the DB content!!!
} if (substr($this->db->Type,0,5) == 'mysql') // we need to check the api version
if (!$api_version || !$this->alessthanb($api_version,'1.0.1.019')) {
{ $this->db->select($this->applications_table,'app_version',array(
$this->db->Link_ID->SetCharSet($this->system_charset); 'app_name' => 'phpgwapi',
),__LINE__,__FILE__);
$api_version = $this->db->next_record() ? $this->db->f(0) : false;
}
if (!$api_version || !$this->alessthanb($api_version,'1.0.1.019'))
{
$this->db->Link_ID->SetCharSet($this->system_charset);
}
} }
} }
$this->db->Halt_On_Error = 'yes'; // setting the default again catch (egw_exception_db $e) {
// table might not be created at that stage
}
} }
} }

View File

@ -52,62 +52,65 @@ class setup_detection
function get_db_versions($setup_info=null) function get_db_versions($setup_info=null)
{ {
$tname = Array(); $tname = Array();
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; try { // catch DB errors
$GLOBALS['egw_setup']->set_table_names();
$GLOBALS['egw_setup']->set_table_names(); if($GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->applications_table),true))
if($GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->applications_table),true))
{
/* one of these tables exists. checking for post/pre beta version */
if($GLOBALS['egw_setup']->applications_table != 'applications')
{ {
$GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__); /* one of these tables exists. checking for post/pre beta version */
while(@$GLOBALS['egw_setup']->db->next_record()) if($GLOBALS['egw_setup']->applications_table != 'applications')
{ {
$app = $GLOBALS['egw_setup']->db->f('app_name'); $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__);
if (!isset($setup_info[$app])) // app source no longer there while(@$GLOBALS['egw_setup']->db->next_record())
{ {
$setup_info[$app] = array( $app = $GLOBALS['egw_setup']->db->f('app_name');
'name' => $app, if (!isset($setup_info[$app])) // app source no longer there
'tables' => $GLOBALS['egw_setup']->db->f('app_tables'), {
'version' => 'deleted', $setup_info[$app] = array(
); 'name' => $app,
'tables' => $GLOBALS['egw_setup']->db->f('app_tables'),
'version' => 'deleted',
);
}
$setup_info[$app]['currentver'] = $GLOBALS['egw_setup']->db->f('app_version');
$setup_info[$app]['enabled'] = $GLOBALS['egw_setup']->db->f('app_enabled');
} }
$setup_info[$app]['currentver'] = $GLOBALS['egw_setup']->db->f('app_version'); /* This is to catch old setup installs that did not have phpgwapi listed as an app */
$setup_info[$app]['enabled'] = $GLOBALS['egw_setup']->db->f('app_enabled'); $tmp = @$setup_info['phpgwapi']['version']; /* save the file version */
} if(!@$setup_info['phpgwapi']['currentver'])
/* This is to catch old setup installs that did not have phpgwapi listed as an app */ {
$tmp = @$setup_info['phpgwapi']['version']; /* save the file version */ $setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver'];
if(!@$setup_info['phpgwapi']['currentver']) $setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver'];
{ $setup_info['phpgwapi']['enabled'] = $setup_info['admin']['enabled'];
$setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver']; // _debug_array($setup_info['phpgwapi']);exit;
$setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver']; // There seems to be a problem here. If ['phpgwapi']['currentver'] is set,
$setup_info['phpgwapi']['enabled'] = $setup_info['admin']['enabled']; // The GLOBALS never gets set.
// _debug_array($setup_info['phpgwapi']);exit; $GLOBALS['setup_info'] = $setup_info;
// There seems to be a problem here. If ['phpgwapi']['currentver'] is set, $GLOBALS['egw_setup']->register_app('phpgwapi');
// The GLOBALS never gets set. }
$GLOBALS['setup_info'] = $setup_info; else
$GLOBALS['egw_setup']->register_app('phpgwapi'); {
$GLOBALS['setup_info'] = $setup_info;
}
$setup_info['phpgwapi']['version'] = $tmp; /* restore the file version */
} }
else else
{ {
$GLOBALS['setup_info'] = $setup_info; $GLOBALS['egw_setup']->db->query('select * from applications');
} while(@$GLOBALS['egw_setup']->db->next_record())
$setup_info['phpgwapi']['version'] = $tmp; /* restore the file version */
}
else
{
$GLOBALS['egw_setup']->db->query('select * from applications');
while(@$GLOBALS['egw_setup']->db->next_record())
{
if($GLOBALS['egw_setup']->db->f('app_name') == 'admin')
{ {
$setup_info['phpgwapi']['currentver'] = $GLOBALS['egw_setup']->db->f('app_version'); if($GLOBALS['egw_setup']->db->f('app_name') == 'admin')
{
$setup_info['phpgwapi']['currentver'] = $GLOBALS['egw_setup']->db->f('app_version');
}
$setup_info[$GLOBALS['egw_setup']->db->f('app_name')]['currentver'] = $GLOBALS['egw_setup']->db->f('app_version');
} }
$setup_info[$GLOBALS['egw_setup']->db->f('app_name')]['currentver'] = $GLOBALS['egw_setup']->db->f('app_version');
} }
} }
} }
catch (egw_exception_db $e) {
// ignore db errors
}
// _debug_array($setup_info); // _debug_array($setup_info);
return $setup_info; return $setup_info;
} }
@ -286,15 +289,17 @@ class setup_detection
{ {
$setup_info = $setup_info ? $setup_info : $GLOBALS['setup_info']; $setup_info = $setup_info ? $setup_info : $GLOBALS['setup_info'];
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; try { // catch DB errors
// _debug_array($setup_info); if (!$GLOBALS['egw_setup']->db->Link_ID)
{
if (!$GLOBALS['egw_setup']->db->Link_ID) $old = error_reporting();
{ error_reporting($old & ~E_WARNING); // no warnings
$old = error_reporting(); $GLOBALS['egw_setup']->db->connect();
error_reporting($old & ~E_WARNING); // no warnings error_reporting($old);
$GLOBALS['egw_setup']->db->connect(); }
error_reporting($old); }
catch(egw_exception_db $e) {
// ignore error
} }
$GLOBALS['egw_setup']->set_table_names(); $GLOBALS['egw_setup']->set_table_names();
@ -324,15 +329,13 @@ class setup_detection
else else
{ {
/* no tables, so checking if we can create them */ /* no tables, so checking if we can create them */
$GLOBALS['egw_setup']->db->query('CREATE TABLE egw_testrights ( testfield varchar(5) NOT NULL )'); try {
if(!$GLOBALS['egw_setup']->db->Errno) $GLOBALS['egw_setup']->db->query('CREATE TABLE egw_testrights ( testfield varchar(5) NOT NULL )');
{
$GLOBALS['egw_setup']->db->query('DROP TABLE egw_testrights'); $GLOBALS['egw_setup']->db->query('DROP TABLE egw_testrights');
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Install Applications)'; $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Install Applications)';
return 3; return 3;
} }
else catch (egw_exception_db $e) {
{
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)';
return 1; return 1;
} }
@ -346,18 +349,21 @@ class setup_detection
*/ */
function check_config() function check_config()
{ {
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no';
if(@$GLOBALS['egw_info']['setup']['stage']['db'] != 10) if(@$GLOBALS['egw_info']['setup']['stage']['db'] != 10)
{ {
return ''; return '';
} }
$GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_name,config_value',array('config_app' => 'phpgwapi'),__LINE__,__FILE__); try { // catch db errors
while($GLOBALS['egw_setup']->db->next_record()) $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_name,config_value',array('config_app' => 'phpgwapi'),__LINE__,__FILE__);
{ while($GLOBALS['egw_setup']->db->next_record())
$config[$GLOBALS['egw_setup']->db->f(0)] = $GLOBALS['egw_setup']->db->f(1); {
$config[$GLOBALS['egw_setup']->db->f(0)] = $GLOBALS['egw_setup']->db->f(1);
}
}
catch (egw_exception_db $e) {
// ignore db errors
} }
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 2 (Needs Configuration)'; $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 2 (Needs Configuration)';
if(!count($config)) if(!count($config))
{ {
@ -426,7 +432,6 @@ class setup_detection
function check_lang($check = True) function check_lang($check = True)
{ {
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no';
if($check && $GLOBALS['egw_info']['setup']['stage']['db'] != 10) if($check && $GLOBALS['egw_info']['setup']['stage']['db'] != 10)
{ {
return ''; return '';
@ -435,30 +440,32 @@ class setup_detection
{ {
$GLOBALS['setup_info'] = $GLOBALS['egw_setup']->detection->get_db_versions($GLOBALS['setup_info']); $GLOBALS['setup_info'] = $GLOBALS['egw_setup']->detection->get_db_versions($GLOBALS['setup_info']);
} }
$GLOBALS['egw_setup']->db->query($q = "SELECT DISTINCT lang FROM {$GLOBALS['egw_setup']->lang_table}",__LINE__,__FILE__); try {
if($GLOBALS['egw_setup']->db->num_rows() == 0) $GLOBALS['egw_setup']->db->query($q = "SELECT DISTINCT lang FROM {$GLOBALS['egw_setup']->lang_table}",__LINE__,__FILE__);
}
catch (egw_exception_db $e) {
// ignore db error
}
if($e || $GLOBALS['egw_setup']->db->num_rows() == 0)
{ {
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (No languages installed)'; $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (No languages installed)';
return 1; return 1;
} }
else while(@$GLOBALS['egw_setup']->db->next_record())
{ {
while(@$GLOBALS['egw_setup']->db->next_record()) $GLOBALS['egw_info']['setup']['installed_langs'][$GLOBALS['egw_setup']->db->f('lang')] = $GLOBALS['egw_setup']->db->f('lang');
{
$GLOBALS['egw_info']['setup']['installed_langs'][$GLOBALS['egw_setup']->db->f('lang')] = $GLOBALS['egw_setup']->db->f('lang');
}
foreach($GLOBALS['egw_info']['setup']['installed_langs'] as $key => $value)
{
$sql = "SELECT lang_name FROM {$GLOBALS['egw_setup']->languages_table} WHERE lang_id = '".$value."'";
$GLOBALS['egw_setup']->db->query($sql);
if ($GLOBALS['egw_setup']->db->next_record())
{
$GLOBALS['egw_info']['setup']['installed_langs'][$value] = $GLOBALS['egw_setup']->db->f('lang_name');
}
}
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Completed)';
return 10;
} }
foreach($GLOBALS['egw_info']['setup']['installed_langs'] as $key => $value)
{
$sql = "SELECT lang_name FROM {$GLOBALS['egw_setup']->languages_table} WHERE lang_id = '".$value."'";
$GLOBALS['egw_setup']->db->query($sql);
if ($GLOBALS['egw_setup']->db->next_record())
{
$GLOBALS['egw_info']['setup']['installed_langs'][$value] = $GLOBALS['egw_setup']->db->f('lang_name');
}
}
$GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Completed)';
return 10;
} }
/** /**
@ -475,12 +482,16 @@ class setup_detection
{ {
/* Make a copy, else we send some callers into an infinite loop */ /* Make a copy, else we send some callers into an infinite loop */
$copy = $setup_info; $copy = $setup_info;
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no';
$table_names = $GLOBALS['egw_setup']->db->table_names();
$tables = Array(); $tables = Array();
foreach($table_names as $key => $val) try {
{ $table_names = $GLOBALS['egw_setup']->db->table_names();
$tables[] = $val['table_name']; foreach($table_names as $key => $val)
{
$tables[] = $val['table_name'];
}
}
catch (egw_exception_db $e) {
// ignore db error
} }
foreach($copy[$appname]['tables'] as $key => $val) foreach($copy[$appname]['tables'] as $key => $val)
{ {

View File

@ -284,91 +284,91 @@ switch($GLOBALS['egw_info']['setup']['stage']['db'])
$db_filled_block = $setup_tpl->get_var('V_db_stage_6_pre'); $db_filled_block = $setup_tpl->get_var('V_db_stage_6_pre');
$setup_tpl->set_var('tableshave',lang('If you did not receive any errors, your applications have been')); $setup_tpl->set_var('tableshave',lang('If you did not receive any errors, your applications have been'));
// FIXME : CAPTURE THIS OUTPUT try { // catch DB errors to report them
$GLOBALS['egw_setup']->db->Halt_On_Error = 'report'; switch ($GLOBALS['egw_info']['setup']['currentver']['phpgwapi'])
{
switch ($GLOBALS['egw_info']['setup']['currentver']['phpgwapi']) case 'dbcreate':
{ $GLOBALS['egw_setup']->db->create_database($_POST['db_root'], $_POST['db_pass'], 'utf8', // create all new db's with utf8
case 'dbcreate': !preg_match('/^[0-9.a-z_]+$/i', $_POST['db_grant_host']) ? 'localhost' : $_POST['db_grant_host']);
$GLOBALS['egw_setup']->db->create_database($_POST['db_root'], $_POST['db_pass'], 'utf8', // create all new db's with utf8 break;
!preg_match('/^[0-9.a-z_]+$/i', $_POST['db_grant_host']) ? 'localhost' : $_POST['db_grant_host']); case 'drop':
break; $setup_info = $GLOBALS['egw_setup']->detection->get_versions($setup_info);
case 'drop': $setup_info = $GLOBALS['egw_setup']->process->droptables($setup_info);
$setup_info = $GLOBALS['egw_setup']->detection->get_versions($setup_info); break;
$setup_info = $GLOBALS['egw_setup']->process->droptables($setup_info); case 'new':
break; // use uploaded backup, instead installing from scratch
case 'new': if ($_POST['upload'])
// use uploaded backup, instead installing from scratch
if ($_POST['upload'])
{
$db_backup = new db_backup();
if (is_array($_FILES['uploaded']) && !$_FILES['uploaded']['error'] &&
is_uploaded_file($_FILES['uploaded']['tmp_name']))
{ {
if (preg_match('/\.(bz2|gz)$/i',$_FILES['uploaded']['name'],$matches)) $db_backup = new db_backup();
if (is_array($_FILES['uploaded']) && !$_FILES['uploaded']['error'] &&
is_uploaded_file($_FILES['uploaded']['tmp_name']))
{ {
$ext = '.'.$matches[1]; if (preg_match('/\.(bz2|gz)$/i',$_FILES['uploaded']['name'],$matches))
move_uploaded_file($_FILES['uploaded']['tmp_name'],$_FILES['uploaded']['tmp_name'].$ext); {
$_FILES['uploaded']['tmp_name'] .= $ext; $ext = '.'.$matches[1];
move_uploaded_file($_FILES['uploaded']['tmp_name'],$_FILES['uploaded']['tmp_name'].$ext);
$_FILES['uploaded']['tmp_name'] .= $ext;
}
if (is_resource($f = $db_backup->fopen_backup($_FILES['uploaded']['tmp_name'],true)))
{
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
$db_backup->restore($f,$_POST['convert_charset'],$_FILES['uploaded']['tmp_name'],false);
fclose($f);
echo '<p align="center">'.lang('restore finished')."</p>\n";
unlink($_FILES['uploaded']['tmp_name']);
}
else // backup failed ==> dont start the upgrade
{
$setup_tpl->set_var('submsg',lang('Restore failed'));
$setup_tpl->set_var('tableshave','<b>'.$f.'</b>');
$setup_tpl->set_var('subaction','');
}
} }
if (is_resource($f = $db_backup->fopen_backup($_FILES['uploaded']['tmp_name'],true))) }
else
{
$setup_info = $GLOBALS['egw_setup']->detection->upgrade_exclude($setup_info);
// Set the DB's client charset if a system-charset is set
if ($_REQUEST['system_charset'])
{ {
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096); $GLOBALS['egw_setup']->system_charset = $_REQUEST['system_charset'];
$db_backup->restore($f,$_POST['convert_charset'],$_FILES['uploaded']['tmp_name'],false); $GLOBALS['egw_setup']->db->Link_ID->SetCharSet($_REQUEST['system_charset']);
}
$setup_info = $GLOBALS['egw_setup']->process->pass($setup_info,'new',$_REQUEST['debug'],True);
$GLOBALS['egw_info']['setup']['currentver']['phpgwapi'] = 'oldversion';
}
break;
case 'oldversion':
// create a backup, before upgrading the tables
if ($_POST['backup'])
{
$db_backup =& CreateObject('phpgwapi.db_backup');
if (is_resource($f = $db_backup->fopen_backup()))
{
echo '<p align="center">'.lang('backup started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
$db_backup->backup($f);
fclose($f); fclose($f);
echo '<p align="center">'.lang('restore finished')."</p>\n"; echo '<p align="center">'.lang('backup finished')."</p>\n";
unlink($_FILES['uploaded']['tmp_name']);
} }
else // backup failed ==> dont start the upgrade else // backup failed ==> dont start the upgrade
{ {
$setup_tpl->set_var('submsg',lang('Restore failed')); $setup_tpl->set_var('submsg',lang('Backup failed'));
$setup_tpl->set_var('tableshave','<b>'.$f.'</b>'); $setup_tpl->set_var('tableshave','<b>'.$f.'</b>');
$setup_tpl->set_var('subaction',''); $setup_tpl->set_var('subaction','');
} }
} }
} if (!@$_POST['backup'] || !is_string($f))
else
{
$setup_info = $GLOBALS['egw_setup']->detection->upgrade_exclude($setup_info);
// Set the DB's client charset if a system-charset is set
if ($_REQUEST['system_charset'])
{ {
$GLOBALS['egw_setup']->system_charset = $_REQUEST['system_charset']; $setup_info = $GLOBALS['egw_setup']->process->pass($setup_info,'upgrade',$_REQUEST['debug']);
$GLOBALS['egw_setup']->db->Link_ID->SetCharSet($_REQUEST['system_charset']); $GLOBALS['egw_info']['setup']['currentver']['phpgwapi'] = 'oldversion';
} }
$setup_info = $GLOBALS['egw_setup']->process->pass($setup_info,'new',$_REQUEST['debug'],True); break;
$GLOBALS['egw_info']['setup']['currentver']['phpgwapi'] = 'oldversion'; }
} }
break; catch (egw_exception_db $e)
case 'oldversion': {
// create a backup, before upgrading the tables echo "<pre>".$e->getMessage()."</pre>\n";
if ($_POST['backup'])
{
$db_backup =& CreateObject('phpgwapi.db_backup');
if (is_resource($f = $db_backup->fopen_backup()))
{
echo '<p align="center">'.lang('backup started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
$db_backup->backup($f);
fclose($f);
echo '<p align="center">'.lang('backup finished')."</p>\n";
}
else // backup failed ==> dont start the upgrade
{
$setup_tpl->set_var('submsg',lang('Backup failed'));
$setup_tpl->set_var('tableshave','<b>'.$f.'</b>');
$setup_tpl->set_var('subaction','');
}
}
if (!@$_POST['backup'] || !is_string($f))
{
$setup_info = $GLOBALS['egw_setup']->process->pass($setup_info,'upgrade',$_REQUEST['debug']);
$GLOBALS['egw_info']['setup']['currentver']['phpgwapi'] = 'oldversion';
}
break;
} }
$GLOBALS['egw_setup']->db->Halt_On_Error = 'no';
$setup_tpl->set_var('re-check_my_installation',lang('Re-Check My Installation')); $setup_tpl->set_var('re-check_my_installation',lang('Re-Check My Installation'));
$setup_tpl->set_var('system_charset',$GLOBALS['egw']->system_charset); $setup_tpl->set_var('system_charset',$GLOBALS['egw']->system_charset);
$setup_tpl->parse('V_db_stage_6_post','B_db_stage_6_post'); $setup_tpl->parse('V_db_stage_6_post','B_db_stage_6_post');