From 93710e09e112a5eb0c381e36566b1e5bb97b39ba Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 5 Mar 2013 10:50:43 +0000 Subject: [PATCH] * 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 --- phpgwapi/inc/class.egw.inc.php | 32 ++-- phpgwapi/inc/class.egw_db.inc.php | 93 ++---------- phpgwapi/inc/class.egw_exception.inc.php | 26 +++- phpgwapi/inc/common_functions.inc.php | 7 +- setup/inc/class.setup.inc.php | 52 ++++--- setup/inc/class.setup_detection.inc.php | 185 ++++++++++++----------- setup/index.php | 140 ++++++++--------- 7 files changed, 249 insertions(+), 286 deletions(-) diff --git a/phpgwapi/inc/class.egw.inc.php b/phpgwapi/inc/class.egw.inc.php index d9d1f71217..f8fc1d63b1 100644 --- a/phpgwapi/inc/class.egw.inc.php +++ b/phpgwapi/inc/class.egw.inc.php @@ -90,30 +90,32 @@ class egw extends egw_minimal // check if eGW is already setup, if not redirect to setup/ try { $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(); } + catch (egw_exception_db_invalid_sql $e2) { + // ignor error, get handled below + } } - catch(Exception $e) { - //echo "
Connection to DB failed (".$e->getMessage().")!\n".$e->getTraceAsString();
-		}
-		if ($e || !$num_config)
+		if (!$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 ;-)
 			if ($phpgw_config)
 			{
-				throw new Exception('
Fatal Error: You need to update eGroupWare before you can continue using it.
',999); + throw new Exception('You need to update EGroupware before you can continue using it.',999); } - else + if ($e) { - throw new Exception('
Fatal Error: It appears that you have not created the database tables for ' - .'eGroupWare. Click here to run setup.
',999); + throw new egw_exception_db_setup('Connection with '.$e->getMessage()."\n\n". + '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) 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 * diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index 1c770371be..b8b3723acd 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -107,12 +107,6 @@ class egw_db */ 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 */ @@ -400,8 +394,7 @@ class egw_db { 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 !!!"); - return null; // in case error-reporting = 'no' + 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 !!!"); } 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); if (!$this->Link_ID) { - $this->halt("No ADOdb support for '$type' ($this->Type) !!!"); - return null; // in case error-reporting = 'no' + throw new egw_exception_db_connection("No ADOdb support for '$type' ($this->Type) !!!"); } $connect = $GLOBALS['egw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect'; if (($Ok = $this->Link_ID->$connect($Host, $User, $Password))) @@ -430,8 +422,7 @@ class egw_db if (!$Ok) { $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password - $this->halt("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); - return null; // in case error-reporting = 'no' + throw new egw_exception_db_connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); } if ($this->Debug) { @@ -671,9 +662,8 @@ class egw_db } if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). - ($inputarr ? "
Parameters: '".implode("','",$inputarr)."'":''), - $line, $file); + throw new egw_exception_db_invalid_sql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). + ($inputarr ? "
Parameters: '".implode("','",$inputarr)."'":'')); } return $this->Query_ID; } @@ -707,8 +697,7 @@ class egw_db { if (!$this->Query_ID) { - $this->halt('next_record called with no query pending.'); - return 0; + throw new egw_exception_db('next_record called with no query pending.'); } 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)) { - $this->halt("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); - $this->Query_ID->Move( $this->num_rows() ); - $this->Row = $this->num_rows(); - return False; + throw new egw_exception_db("seek($pos) failed: resultset has " . $this->num_rows() . " rows"); } return True; } @@ -973,65 +959,6 @@ class egw_db 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("
File: %s",$file); - } - if ($line) - { - printf("
Line: %s",$line); - } - printf("
Function: %s

\n",function_backtrace(2)); - - if ($this->Halt_On_Error != "report") - { - echo "

Session halted.

"; - if (is_object($GLOBALS['egw']->common)) - { - $GLOBALS['egw']->common->egw_exit(True); - } - else // happens eg. in setup - { - exit(); - } - } - } - - function haltmsg($msg) - { - printf("

Database error: %s
\n", $msg); - if (($this->Errno || $this->Error) && $this->Error != "()") - { - printf("$this->Type Error: %s (%s)
\n",$this->Errno,$this->Error); - } - } - /** * Get description of a table * @@ -1061,7 +988,6 @@ class egw_db if($column->primary_key) $flags .= "primary_key "; if($column->binary) $flags .= "binary "; -// _debug_array($column); $metadata[$i] = array( 'table' => $table, 'name' => $column->name, @@ -1523,8 +1449,7 @@ class egw_db if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) { - // give a warning that we have no column-type - $this->halt("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",

".print_r($column_definitions,True)."
nothing known about column '$key'!"); + throw new egw_exception_db_invalid_sql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",
".print_r($column_definitions,True)."
nothing known about column '$key'!"); } $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; @@ -1912,7 +1837,7 @@ class egw_db { $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); if ($this->Debug) echo "

adodb::UpdateBlob('$table','$col','$val','$where') = '$ret'

\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; diff --git a/phpgwapi/inc/class.egw_exception.inc.php b/phpgwapi/inc/class.egw_exception.inc.php index 18ccf8d0d4..8f156b9add 100644 --- a/phpgwapi/inc/class.egw_exception.inc.php +++ b/phpgwapi/inc/class.egw_exception.inc.php @@ -138,8 +138,7 @@ class egw_exception_wrong_parameter 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 { @@ -159,6 +158,25 @@ class egw_exception_db extends egw_exception /** * Storing the row violates a unique key constrain - * */ -class egw_exception_db_not_unique extends egw_exception_db { } \ No newline at end of file +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 { } \ No newline at end of file diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index 6cbe1657b0..efc8926bc9 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -1589,7 +1589,12 @@ function egw_exception_handler(Exception $e) $message .= html::htmlspecialchars($e->getTraceAsString()); } $message .= "
\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 .= 'Run setup to install or configure EGroupware.'; + } + elseif (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->session) && method_exists($GLOBALS['egw'],'link')) { $message .= '

'.try_lang('Click here to resume your eGroupWare Session.').'

'; } diff --git a/setup/inc/class.setup.inc.php b/setup/inc/class.setup.inc.php index f0a5d39216..1274837179 100644 --- a/setup/inc/class.setup.inc.php +++ b/setup/inc/class.setup.inc.php @@ -122,34 +122,36 @@ class setup 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( - 'config_app' => 'phpgwapi', - 'config_name' => 'system_charset', - ),__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 + // Set the DB's client charset if a system-charset is set + $this->db->select($this->config_table,'config_value',array( + 'config_app' => 'phpgwapi', + 'config_name' => 'system_charset', + ),__LINE__,__FILE__); + if ($this->db->next_record() && $this->db->f(0)) { - $this->db->select($this->applications_table,'app_version',array( - '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->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( + '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 + } } } @@ -651,7 +653,7 @@ class setup // Remove categories $this->db->delete(categories::TABLE, array('cat_appname'=>$appname),__LINE__,__FILE__); categories::invalidate_cache($appname); - + // Remove config $this->db->delete(config::TABLE, array('config_app'=>$appname),__LINE__,__FILE__); //echo 'DELETING application: ' . $appname; diff --git a/setup/inc/class.setup_detection.inc.php b/setup/inc/class.setup_detection.inc.php index 0fa61a3e19..2dc8a805c7 100755 --- a/setup/inc/class.setup_detection.inc.php +++ b/setup/inc/class.setup_detection.inc.php @@ -52,62 +52,65 @@ class setup_detection function get_db_versions($setup_info=null) { $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)) - { - /* one of these tables exists. checking for post/pre beta version */ - if($GLOBALS['egw_setup']->applications_table != 'applications') + if($GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->applications_table),true)) { - $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__); - while(@$GLOBALS['egw_setup']->db->next_record()) + /* one of these tables exists. checking for post/pre beta version */ + if($GLOBALS['egw_setup']->applications_table != 'applications') { - $app = $GLOBALS['egw_setup']->db->f('app_name'); - if (!isset($setup_info[$app])) // app source no longer there + $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__); + while(@$GLOBALS['egw_setup']->db->next_record()) { - $setup_info[$app] = array( - 'name' => $app, - 'tables' => $GLOBALS['egw_setup']->db->f('app_tables'), - 'version' => 'deleted', - ); + $app = $GLOBALS['egw_setup']->db->f('app_name'); + if (!isset($setup_info[$app])) // app source no longer there + { + $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'); - $setup_info[$app]['enabled'] = $GLOBALS['egw_setup']->db->f('app_enabled'); - } - /* 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 */ - if(!@$setup_info['phpgwapi']['currentver']) - { - $setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver']; - $setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver']; - $setup_info['phpgwapi']['enabled'] = $setup_info['admin']['enabled']; - // _debug_array($setup_info['phpgwapi']);exit; - // There seems to be a problem here. If ['phpgwapi']['currentver'] is set, - // The GLOBALS never gets set. - $GLOBALS['setup_info'] = $setup_info; - $GLOBALS['egw_setup']->register_app('phpgwapi'); + /* 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 */ + if(!@$setup_info['phpgwapi']['currentver']) + { + $setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver']; + $setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver']; + $setup_info['phpgwapi']['enabled'] = $setup_info['admin']['enabled']; + // _debug_array($setup_info['phpgwapi']);exit; + // There seems to be a problem here. If ['phpgwapi']['currentver'] is set, + // The GLOBALS never gets set. + $GLOBALS['setup_info'] = $setup_info; + $GLOBALS['egw_setup']->register_app('phpgwapi'); + } + else + { + $GLOBALS['setup_info'] = $setup_info; + } + $setup_info['phpgwapi']['version'] = $tmp; /* restore the file version */ } else { - $GLOBALS['setup_info'] = $setup_info; - } - $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') + $GLOBALS['egw_setup']->db->query('select * from applications'); + while(@$GLOBALS['egw_setup']->db->next_record()) { - $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); return $setup_info; } @@ -286,15 +289,17 @@ class setup_detection { $setup_info = $setup_info ? $setup_info : $GLOBALS['setup_info']; - $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; - // _debug_array($setup_info); - - if (!$GLOBALS['egw_setup']->db->Link_ID) - { - $old = error_reporting(); - error_reporting($old & ~E_WARNING); // no warnings - $GLOBALS['egw_setup']->db->connect(); - error_reporting($old); + try { // catch DB errors + if (!$GLOBALS['egw_setup']->db->Link_ID) + { + $old = error_reporting(); + error_reporting($old & ~E_WARNING); // no warnings + $GLOBALS['egw_setup']->db->connect(); + error_reporting($old); + } + } + catch(egw_exception_db $e) { + // ignore error } $GLOBALS['egw_setup']->set_table_names(); @@ -324,15 +329,13 @@ class setup_detection else { /* no tables, so checking if we can create them */ - $GLOBALS['egw_setup']->db->query('CREATE TABLE egw_testrights ( testfield varchar(5) NOT NULL )'); - if(!$GLOBALS['egw_setup']->db->Errno) - { + try { + $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_info']['setup']['header_msg'] = 'Stage 3 (Install Applications)'; return 3; } - else - { + catch (egw_exception_db $e) { $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; return 1; } @@ -346,18 +349,21 @@ class setup_detection */ function check_config() { - $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; if(@$GLOBALS['egw_info']['setup']['stage']['db'] != 10) { return ''; } - $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); + try { // catch db errors + $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); + } + } + catch (egw_exception_db $e) { + // ignore db errors } - $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 2 (Needs Configuration)'; if(!count($config)) { @@ -426,7 +432,6 @@ class setup_detection function check_lang($check = True) { - $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; if($check && $GLOBALS['egw_info']['setup']['stage']['db'] != 10) { return ''; @@ -435,30 +440,32 @@ class setup_detection { $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__); - if($GLOBALS['egw_setup']->db->num_rows() == 0) + try { + $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)'; 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'); - } - 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; + $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; } /** @@ -475,12 +482,16 @@ class setup_detection { /* Make a copy, else we send some callers into an infinite loop */ $copy = $setup_info; - $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; - $table_names = $GLOBALS['egw_setup']->db->table_names(); $tables = Array(); - foreach($table_names as $key => $val) - { - $tables[] = $val['table_name']; + try { + $table_names = $GLOBALS['egw_setup']->db->table_names(); + 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) { diff --git a/setup/index.php b/setup/index.php index 34ee9f0bc7..ab348775f9 100644 --- a/setup/index.php +++ b/setup/index.php @@ -284,91 +284,91 @@ switch($GLOBALS['egw_info']['setup']['stage']['db']) $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')); - // FIXME : CAPTURE THIS OUTPUT - $GLOBALS['egw_setup']->db->Halt_On_Error = 'report'; - - 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 - !preg_match('/^[0-9.a-z_]+$/i', $_POST['db_grant_host']) ? 'localhost' : $_POST['db_grant_host']); - break; - case 'drop': - $setup_info = $GLOBALS['egw_setup']->detection->get_versions($setup_info); - $setup_info = $GLOBALS['egw_setup']->process->droptables($setup_info); - break; - case 'new': - // 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'])) + try { // catch DB errors to report them + 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 + !preg_match('/^[0-9.a-z_]+$/i', $_POST['db_grant_host']) ? 'localhost' : $_POST['db_grant_host']); + break; + case 'drop': + $setup_info = $GLOBALS['egw_setup']->detection->get_versions($setup_info); + $setup_info = $GLOBALS['egw_setup']->process->droptables($setup_info); + break; + case 'new': + // use uploaded backup, instead installing from scratch + if ($_POST['upload']) { - 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]; - move_uploaded_file($_FILES['uploaded']['tmp_name'],$_FILES['uploaded']['tmp_name'].$ext); - $_FILES['uploaded']['tmp_name'] .= $ext; + if (preg_match('/\.(bz2|gz)$/i',$_FILES['uploaded']['name'],$matches)) + { + $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 '

'.lang('restore started, this might take a few minutes ...')."

\n".str_repeat(' ',4096); + $db_backup->restore($f,$_POST['convert_charset'],$_FILES['uploaded']['tmp_name'],false); + fclose($f); + echo '

'.lang('restore finished')."

\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',''.$f.''); + $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 '

'.lang('restore started, this might take a few minutes ...')."

\n".str_repeat(' ',4096); - $db_backup->restore($f,$_POST['convert_charset'],$_FILES['uploaded']['tmp_name'],false); + $GLOBALS['egw_setup']->system_charset = $_REQUEST['system_charset']; + $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 '

'.lang('backup started, this might take a few minutes ...')."

\n".str_repeat(' ',4096); + $db_backup->backup($f); fclose($f); - echo '

'.lang('restore finished')."

\n"; - unlink($_FILES['uploaded']['tmp_name']); + echo '

'.lang('backup finished')."

\n"; } 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',''.$f.''); $setup_tpl->set_var('subaction',''); } } - } - 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']) + if (!@$_POST['backup'] || !is_string($f)) { - $GLOBALS['egw_setup']->system_charset = $_REQUEST['system_charset']; - $GLOBALS['egw_setup']->db->Link_ID->SetCharSet($_REQUEST['system_charset']); + $setup_info = $GLOBALS['egw_setup']->process->pass($setup_info,'upgrade',$_REQUEST['debug']); + $GLOBALS['egw_info']['setup']['currentver']['phpgwapi'] = 'oldversion'; } - $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 '

'.lang('backup started, this might take a few minutes ...')."

\n".str_repeat(' ',4096); - $db_backup->backup($f); - fclose($f); - echo '

'.lang('backup finished')."

\n"; - } - else // backup failed ==> dont start the upgrade - { - $setup_tpl->set_var('submsg',lang('Backup failed')); - $setup_tpl->set_var('tableshave',''.$f.''); - $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; + break; + } + } + catch (egw_exception_db $e) + { + echo "
".$e->getMessage()."
\n"; } - - $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('system_charset',$GLOBALS['egw']->system_charset); $setup_tpl->parse('V_db_stage_6_post','B_db_stage_6_post');