From 187718ccd8f4e7521e0fa45f57de35566152aacc Mon Sep 17 00:00:00 2001
From: ralf
Date: Thu, 25 Jan 2024 21:21:46 +0200
Subject: [PATCH] fix PHP Deprecated dynamic property db_charset_was used in
EGroupware 1.0 update and remove old MySQL charset fixing script
---
setup/fix_mysql_charset.php | 180 ----------------------------------
setup/inc/class.setup.inc.php | 1 -
2 files changed, 181 deletions(-)
delete mode 100644 setup/fix_mysql_charset.php
diff --git a/setup/fix_mysql_charset.php b/setup/fix_mysql_charset.php
deleted file mode 100644
index d10402ab43..0000000000
--- a/setup/fix_mysql_charset.php
+++ /dev/null
@@ -1,180 +0,0 @@
-
- * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
- * @version $Id$
- */
-
-// if we are NOT called as part of an update script, behave like a regular setup script
-if (!isset($GLOBALS['egw_setup']) || !is_object($GLOBALS['egw_setup']))
-{
- $diagnostics = 1; // can be set to 0=non, 1=some (default for now), 2=all
-
- include('./inc/functions.inc.php');
- // Authorize the user to use setup app and load the database
- // Does not return unless user is authorized
- if (!$GLOBALS['egw_setup']->auth('Config') || @$_POST['cancel'])
- {
- Header('Location: index.php');
- exit;
- }
- $GLOBALS['egw_setup']->loaddb();
-
- $tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
- $setup_tpl = CreateObject('phpgwapi.Template',$tpl_root);
- $setup_tpl->set_file(array(
- 'T_head' => 'head.tpl',
- 'T_footer' => 'footer.tpl',
- ));
- $GLOBALS['egw_setup']->html->show_header('',False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
- echo ''.'Fix mysql DB to match the EGroupware system_charset'."
\n";
- $running_standalone = true;
-}
-$db =& $GLOBALS['egw_setup']->db;
-$charset2mysql =& $GLOBALS['egw_setup']->db->Link_ID->charset2mysql;
-$mysql2charset = array_flip($charset2mysql);
-
-$ServerInfo = $db->Link_ID->ServerInfo();
-$db_version = (float) $ServerInfo['version'];
-
-if ($running_standalone || $_REQUEST['debug']) echo "DB-Type='{$GLOBALS['egw_setup']->db->Type}', DB-Version=$db_version ($ServerInfo[description]), EGroupware system_charset='{$GLOBALS['egw_setup']->system_charset}', DB-connection charset was '{$GLOBALS['egw_setup']->db_charset_was}'
\n";
-
-$mysql_system_charset = isset($charset2mysql[$GLOBALS['egw_setup']->system_charset]) ?
- $charset2mysql[$GLOBALS['egw_setup']->system_charset] : $GLOBALS['egw_setup']->system_charset;
-
-if (substr($db->Type,0,5) == 'mysql' && $db_version >= 4.1 && $GLOBALS['egw_setup']->system_charset && $GLOBALS['egw_setup']->db_charset_was &&
- $GLOBALS['egw_setup']->system_charset != $GLOBALS['egw_setup']->db_charset_was)
-{
- $tables_modified = 'no';
-
- $tables = array();
- $db->query("SHOW TABLE STATUS",__LINE__,__FILE__);
- while (($row = $db->row(true)))
- {
- $tables[$row['Name']] = $row['Collation'];
- }
- foreach($tables as $table => $collation)
- {
- $columns = array();
- $db->query("SHOW FULL FIELDS FROM `$table`",__LINE__,__FILE__);
- while(($row = $db->row(true)))
- {
- $columns[] = $row;
- }
- //echo $table; _debug_array($columns);
- $fulltext = $fulltext_back = array();
- $db->query("SHOW KEYS FROM `$table`",__LINE__,__FILE__);
- while(($row = $db->row(true)))
- {
- if ($row['Index_type'] == 'FULLTEXT')
- {
- $fulltext[$row['Column_name']] = $row['Key_name'];
- }
- }
-
- $alter_table = $alter_table_back = array();
- foreach($columns as $column)
- {
- if ($column['Collation'] && preg_match('/^(char|varchar|.*text)\(?([0-9]*)\)?$/i',$column['Type'],$matches))
- {
- list(,$type,$size) = $matches;
- list($charset) = explode('_',$column['Collation']);
-
- if (isset($mysql2charset[$charset])) $charset = $mysql2charset[$charset];
-
- if ($charset != $GLOBALS['egw_setup']->system_charset)
- {
- $col = $column['Field'];
-
- if ($type == 'varchar' || $type == 'char') // old schema_proc (pre 1.0.1) used also char
- {
- $type = 'varchar('.$size.')';
- $bintype = 'varbinary('.$size.')';
- }
- else
- {
- $bintype = str_replace('text','blob',$type);
- }
- //echo "$table.$col $type CHARACTER SET $charset $default $null
\n";
-
- $default = !is_null($column['Default']) ? "DEFAULT '".$column['Default']."'" : '';
- $null = $column['Null'] ? 'NULL' : 'NOT NULL';
-
- if (isset($fulltext[$col]))
- {
- $idx_name = $fulltext[$col];
- $idx_cols = array();
- foreach($fulltext as $c => $i)
- {
- if ($i == $idx_name)
- {
- $idx_cols[] = $c;
- unset($fulltext[$c]);
- }
- }
- $fulltext_back[$idx_name] = $idx_cols;
- $alter_table[] = " DROP INDEX `$idx_name`";
- }
- $alter_table[] = " CHANGE `$col` `$col` $bintype $default $null";
- $alter_table_back[] = " CHANGE `$col` `$col` $type CHARACTER SET $mysql_system_charset $default $null";
- }
- }
- }
- list($charset) = explode('_',$collation);
- if (isset($mysql2charset[$charset])) $charset = $mysql2charset[$charset];
- if ($charset != $GLOBALS['egw_setup']->system_charset)
- {
- $alter_table[] = " DEFAULT CHARACTER SET $mysql_system_charset";
- }
- if (count($alter_table))
- {
- $alter_table = "ALTER TABLE $table\n".implode(",\n",$alter_table);
-
- if ($running_standalone || $_REQUEST['debug']) echo ''.nl2br($alter_table)."
\n";
- if (!$db->query($alter_table,__LINE__,__FILE__))
- {
- echo "SQL Error: ".nl2br($alter_table)."
\n";
- echo "{$db->Type} Error: {$db->Errno} ({$db->Error})
\n";
- echo "continuing ...
\n";
- continue;
- }
- foreach($fulltext_back as $idx_name => $idx_cols)
- {
- $alter_table_back[] = " ADD FULLTEXT `$idx_name` (`".implode('`,`',$idx_cols)."`)";
- }
- if (count($alter_table_back))
- {
- $alter_table_back = "ALTER TABLE $table\n".implode(",\n",$alter_table_back);
-
- if ($running_standalone || $_REQUEST['debug']) echo ''.nl2br($alter_table_back)."
\n";
- if (!$db->query($alter_table_back,__LINE__,__FILE__))
- {
- echo "SQL Error: ".nl2br($alter_table_back)."
\n";
- echo "{$db->Type} Error: {$db->Errno} ({$db->Error})\n";
- echo "continuing ...
\n";
- continue;
- }
- }
- ++$tables_modified;
- }
- }
- // change the default charset of the DB
- $db->query("SHOW CREATE DATABASE `$db->Database`",__LINE__,__FILE__);
- $create_db = $db->next_record() ? $db->f(1) : '';
- if (preg_match('/CHARACTER SET ([a-z1-9_-]+) /i',$create_db,$matches) && $matches[1] != $mysql_system_charset)
- {
- $alter_db = "ALTER DATABASE `$db->Database` DEFAULT CHARACTER SET $mysql_system_charset";
- if ($running_standalone || $_REQUEST['debug']) echo ''.$alter_db."
\n";
- $db->query($alter_db,__LINE__,__FILE__);
- }
-}
-if ($running_standalone || $_REQUEST['debug'])
-{
- echo "$tables_modified tables changed to our system_charset {$GLOBALS['egw_setup']->system_charset}($mysql_system_charset)
\n";
-
- if ($running_standalone) $GLOBALS['egw_setup']->html->show_footer();
-}
diff --git a/setup/inc/class.setup.inc.php b/setup/inc/class.setup.inc.php
index a584d00fbc..596478c1fd 100644
--- a/setup/inc/class.setup.inc.php
+++ b/setup/inc/class.setup.inc.php
@@ -133,7 +133,6 @@ class setup
),__LINE__,__FILE__)->fetchColumn()))
{
$this->system_charset = $charset;
- $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