From 3d909d4776dbc56660e779e678eb51ca09b09d3c Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 1 Apr 2008 10:33:54 +0000 Subject: [PATCH] fixed fatal error "Exception thrown without a stack frame in Unknown on line 0", if DB does not exist when calling the regular eGW url --- phpgwapi/inc/class.egw.inc.php | 31 +++++++++++++++------------ phpgwapi/inc/common_functions.inc.php | 16 ++++++++++---- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/phpgwapi/inc/class.egw.inc.php b/phpgwapi/inc/class.egw.inc.php index 87c3dbc28f..0f463e87e0 100644 --- a/phpgwapi/inc/class.egw.inc.php +++ b/phpgwapi/inc/class.egw.inc.php @@ -81,24 +81,29 @@ class egw extends egw_minimal } $this->db->set_app('phpgwapi'); - $this->db->Halt_On_Error = 'no'; - $this->db->connect( - $GLOBALS['egw_info']['server']['db_name'], - $GLOBALS['egw_info']['server']['db_host'], - $GLOBALS['egw_info']['server']['db_port'], - $GLOBALS['egw_info']['server']['db_user'], - $GLOBALS['egw_info']['server']['db_pass'], - $GLOBALS['egw_info']['server']['db_type'] - ); // check if eGW is already setup, if not redirect to setup/ - if (!$this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchSingle()) + try { + $this->db->connect( + $GLOBALS['egw_info']['server']['db_name'], + $GLOBALS['egw_info']['server']['db_host'], + $GLOBALS['egw_info']['server']['db_port'], + $GLOBALS['egw_info']['server']['db_user'], + $GLOBALS['egw_info']['server']['db_pass'], + $GLOBALS['egw_info']['server']['db_type'] + ); + } + catch(Exception $e) { + //echo "
Connection to DB failed (".$e->getMessage().")!\n".$e->getTraceAsString();
+		}
+		if ($e || !$this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchSingle())
 		{
 			$setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/');
 
 			// we check for the old table too, to not scare updating users ;-)
-			if ($this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchSingle())
+			if (!$e && $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchSingle())
 			{
-				throw new Exception('
Fatal Error: You need to update eGroupWare before you can continue using it.
',999); + throw new Exception('
Fatal Error: You need to update eGroupWare before you can continue using it.
',999); } else { @@ -107,8 +112,6 @@ class egw extends egw_minimal } exit; } - $this->db->Halt_On_Error = 'yes'; - // Set the DB's client charset if a system-charset is set $system_charset = $this->db->select(config::TABLE,'config_value',array( 'config_app' => 'phpgwapi', diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index 927332164d..a1264f401a 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -1279,12 +1279,16 @@ */ function lang($key,$vars=null) { + static $varnames = array('%1','%2','%3','%4'); + if(!is_array($vars)) { $vars = func_get_args(); array_shift($vars); // remove $key } - return $GLOBALS['egw']->translation->translate($key,$vars); + return is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->translations) ? + $GLOBALS['egw']->translation->translate($key,$vars) : + str_replace($varnames,$vars,$key); } } @@ -1359,11 +1363,11 @@ function egw_exception_handler(Exception $e) '
'.$e->getMessage()."\n\n".
 		$e->getTraceAsString()."
\n"; - if (is_object($GLOBALS['egw']) && is_object($GLOBALS['egw']->session)) + if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->session)) { '

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

'; } - if (is_object($GLOBALS['egw']) && is_object($GLOBALS['egw']->framework)) + if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->framework)) { $GLOBALS['egw']->framework->render($message,$headline); } @@ -1371,7 +1375,11 @@ function egw_exception_handler(Exception $e) { echo "\n\n$headline\n\n\n$message\n\n\n"; } - $GLOBALS['egw']->common->egw_exit(); + if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->common)) + { + $GLOBALS['egw']->common->egw_exit(); + } + exit; } set_exception_handler('egw_exception_handler');