From c57ae62d1c987082050c87cc7b52d3b990372c2e Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 20 May 2022 18:00:41 +0200 Subject: [PATCH] fix not working installation under PHP 8.1 due to mysqli throwing errors now by default --- api/src/Categories.php | 2 +- api/src/Db.php | 2 +- api/src/Exception.php | 4 ++-- api/src/Translation.php | 21 +++++++++++++-------- setup/inc/class.setup.inc.php | 6 ++---- setup/inc/class.setup_detection.inc.php | 11 +++++++---- setup/index.php | 8 +------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/api/src/Categories.php b/api/src/Categories.php index 47ae5a7838..1ecd6bb653 100644 --- a/api/src/Categories.php +++ b/api/src/Categories.php @@ -125,7 +125,7 @@ class Categories if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; if ($accountid === self::GLOBAL_ACCOUNT || - $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) + (int)$accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) { $this->account_id = (int) $accountid; } diff --git a/api/src/Db.php b/api/src/Db.php index 368356189d..f4ab80c667 100644 --- a/api/src/Db.php +++ b/api/src/Db.php @@ -358,7 +358,7 @@ class Db //error_log(__METHOD__."() this->Host(s)=$this->Host, n=$n --> host=$host"); $new_connection = !$this->Link_ID || !$this->Link_ID->IsConnected(); $this->_connect($host); - // check if connected node is healty + // check if connected node is healthy if ($new_connection && self::$health_check) { call_user_func(self::$health_check, $this); diff --git a/api/src/Exception.php b/api/src/Exception.php index 70e550db66..e142245af9 100644 --- a/api/src/Exception.php +++ b/api/src/Exception.php @@ -31,6 +31,6 @@ class Exception extends \Exception // nothing fancy yet function __construct($msg=null,$code=100,\Exception $previous=null) { - return parent::__construct($msg, $code, $previous); + parent::__construct($msg, $code, $previous); } -} +} \ No newline at end of file diff --git a/api/src/Translation.php b/api/src/Translation.php index 961177f7aa..3d620f5b0e 100644 --- a/api/src/Translation.php +++ b/api/src/Translation.php @@ -354,7 +354,7 @@ class Translation $loaded =& self::load_app_files($app, $l, null, $updated_load_via); } //error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded))); - if ($loaded || $instance_specific) + if ($loaded) { Cache::setCache($instance_specific ? Cache::INSTANCE : Cache::TREE, __CLASS__, $app.':'.$l, $loaded); @@ -401,12 +401,17 @@ class Translation if (!isset(self::$db)) return; } $loaded = array(); - foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array( - 'lang' => $lang, - 'app_name' => $app, - ),__LINE__,__FILE__) as $row) - { - $loaded[strtolower($row['message_id'])] = $row['content']; + try { + foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array( + 'lang' => $lang, + 'app_name' => $app, + ), __LINE__, __FILE__) as $row) + { + $loaded[strtolower($row['message_id'])] = $row['content']; + } + } + catch (Db\Exception $e) { + // ignore error } //error_log(__METHOD__."($app,$lang) took ".(1000*(microtime(true)-$start))." ms to load ".count($loaded)." phrases"); return $loaded; @@ -1174,4 +1179,4 @@ class Translation } return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default } -} +} \ No newline at end of file diff --git a/setup/inc/class.setup.inc.php b/setup/inc/class.setup.inc.php index ed05fc3ecf..26c4a24c52 100644 --- a/setup/inc/class.setup.inc.php +++ b/setup/inc/class.setup.inc.php @@ -55,7 +55,7 @@ class setup */ var $html; - var $system_charset; + var $system_charset = 'utf-8'; var $lang; var $ConfigDomain; @@ -90,8 +90,6 @@ class setup $this->detection = new setup_detection(); $this->process = new setup_process(); - if (preg_match('/^[a-z0-9-]+$/i', $_REQUEST['system_charset'])) $this->system_charset = $_REQUEST['system_charset']; - /* The setup application needs these */ if ($html) $this->html = new setup_html(); if ($translation) $this->translation = new setup_translation(); @@ -137,7 +135,7 @@ class setup $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 + if (substr($this->db->Type,0,5) === 'mysql') // we need to check the api version { $api_version = $this->db->select($this->applications_table,'app_version',array( 'app_name' => 'phpgwapi', diff --git a/setup/inc/class.setup_detection.inc.php b/setup/inc/class.setup_detection.inc.php index fc144ffd5f..c47dfee701 100755 --- a/setup/inc/class.setup_detection.inc.php +++ b/setup/inc/class.setup_detection.inc.php @@ -300,7 +300,8 @@ class setup_detection if (!$setup_info) $setup_info = $GLOBALS['setup_info']; try { // catch DB errors - if (!$GLOBALS['egw_setup']->db->Link_ID) + if (empty($GLOBALS['egw_setup']->db->Link_ID) || + empty($GLOBALS['egw_setup']->db->Link_ID->_connectionID)) { $old = error_reporting(); error_reporting($old & ~E_WARNING); // no warnings @@ -310,11 +311,13 @@ class setup_detection $GLOBALS['egw_setup']->set_table_names(); } } - catch(Api\Db\Exception $e) { + catch(\Exception $e) { // ignore error } - if (!$GLOBALS['egw_setup']->db->Link_ID || !$GLOBALS['egw_setup']->db->Link_ID->_connectionID) + if (empty($GLOBALS['egw_setup']->db->Link_ID) || + empty($GLOBALS['egw_setup']->db->Link_ID->_connectionID) || + $GLOBALS['egw_setup']->db->Link_ID->_connectionID->connect_errno) { $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; return 1; @@ -574,4 +577,4 @@ class setup_detection } return true; } -} +} \ No newline at end of file diff --git a/setup/index.php b/setup/index.php index 3067ecf98a..9c2acd2206 100644 --- a/setup/index.php +++ b/setup/index.php @@ -342,12 +342,6 @@ switch($GLOBALS['egw_info']['setup']['stage']['db']) else { $s_info = $GLOBALS['egw_setup']->detection->upgrade_exclude($setup_info); - // Set the DB's client charset if a system-charset is set - if (preg_match('/^[a-z0-9-]+$/i', $_REQUEST['system_charset'])) - { - $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($s_info,'new',$_REQUEST['debug'],True); $GLOBALS['egw_info']['setup']['currentver']['phpgwapi'] = 'oldversion'; } @@ -539,4 +533,4 @@ else } $setup_tpl->pparse('out','T_setup_main'); -$GLOBALS['egw_setup']->html->show_footer(); +$GLOBALS['egw_setup']->html->show_footer(); \ No newline at end of file