From dd595999dc5d4d438f423b888c58c6fe80f090d2 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sat, 23 Jan 2010 14:53:54 +0000 Subject: [PATCH] UTF-8 - konverter now working --- .../updates/froxlor/0.9/update_0.9.inc.php | 66 +++++++++++++++++++ install/updates/froxlor/upgrade_syscp.inc.php | 61 +++-------------- .../1.0/update_1.0.10_1.2-beta1.inc.php | 0 .../{ => syscp}/1.0/update_1.0_1.0.10.inc.php | 0 .../1.2/update_1.2-beta1_1.2.19.inc.php | 0 .../{ => syscp}/1.2/update_1.2.19_1.4.inc.php | 0 .../{ => syscp}/1.4/update_1.4.inc.php | 0 install/updatesql.php | 22 +++++-- lib/tables.inc.php | 2 +- 9 files changed, 91 insertions(+), 60 deletions(-) create mode 100644 install/updates/froxlor/0.9/update_0.9.inc.php rename install/updates/{ => syscp}/1.0/update_1.0.10_1.2-beta1.inc.php (100%) rename install/updates/{ => syscp}/1.0/update_1.0_1.0.10.inc.php (100%) rename install/updates/{ => syscp}/1.2/update_1.2-beta1_1.2.19.inc.php (100%) rename install/updates/{ => syscp}/1.2/update_1.2.19_1.4.inc.php (100%) rename install/updates/{ => syscp}/1.4/update_1.4.inc.php (100%) diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php new file mode 100644 index 00000000..56db3640 --- /dev/null +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -0,0 +1,66 @@ +logAction(ADM_ACTION, LOG_WARNING, "Updating from 0.9-r1 to 0.9-r2"); + + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (119, 'spf', 'use_spf', '0');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (120, 'spf', 'spf_entry', '@ IN TXT \"v=spf1 a mx -all\"');"); + + // Convert all data to UTF-8 to have a sane standard across all data + $result = $db->query("SHOW TABLES"); + while($table = $db->fetch_array($result, 'num')) + { + $db->query("ALTER TABLE " . $table[0] . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"); + $db->query("ALTER TABLE " . $table[0] . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); + + $affected_columns = array(); + + $primarykey = ""; + $columns = $db->query("SHOW COLUMNS FROM ".$table[0]); + while ($column = $db->fetch_array($columns)) + { + if (!(strpos($column['Type'], "char") === false) || !(strpos($column['Type'], "text") === false)) + { + $affected_columns[] = $column['Field']; + } + + if ($column['Key'] == 'PRI') { + $primarykey = $column['Field']; + } + } + + $count_cols = count($affected_columns); + if ($count_cols > 0) + { + $load = ""; + foreach($affected_columns as $col) + { + $load .= ", `" . $col . "`"; + } + + $rows = $db->query("SELECT $primarykey" . $load . " FROM `" . $table[0] . "`"); + while ($row = $db->fetch_array($rows)) + { + $changes = ""; + for ($i = 0; $i < $count_cols; $i++) + { + $base = "`" . $affected_columns[$i] . "` = '" . convertUtf8($row[$affected_columns[$i]]) . "'"; + $changes .= ($i == ($count_cols-1)) ? $base : $base . ", "; + } + + $db->query("UPDATE `" . $table[0] . "` SET " . $changes . " WHERE `$primarykey` = " . $db->escape($row[$primarykey]) . ";"); + } + } + } + + $db->query("UPDATE `panel_settings` SET `varname` = 'froxlor_graphic' WHERE `varname` = 'syscp_graphic'"); + + // set new version + + $query = 'UPDATE `%s` SET `value` = \'0.9-r2\' WHERE `settinggroup` = \'panel\' AND `varname` = \'version\''; + $query = sprintf($query, TABLE_PANEL_SETTINGS); + $db->query($query); + $settings['panel']['version'] = '0.9-r2'; +} diff --git a/install/updates/froxlor/upgrade_syscp.inc.php b/install/updates/froxlor/upgrade_syscp.inc.php index e9066a7d..c47957f2 100644 --- a/install/updates/froxlor/upgrade_syscp.inc.php +++ b/install/updates/froxlor/upgrade_syscp.inc.php @@ -37,6 +37,8 @@ if($settings['panel']['frontend'] == 'froxlor' && $settings['panel']['version'] == '0.9') { + $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 0.9 to 0.9-r1"); + /* * add missing database-updates if necessary (old: update/update_database.php */ @@ -197,60 +199,13 @@ if($settings['panel']['frontend'] == 'froxlor' $db->query("ALTER TABLE `" . TABLE_PANEL_ADMINS . "` MODIFY `traffic` BIGINT(30), MODIFY `traffic_used` BIGINT(30)"); + // set new version + + $query = 'UPDATE `%s` SET `value` = \'0.9-r1\' WHERE `settinggroup` = \'panel\' AND `varname` = \'version\''; + $query = sprintf($query, TABLE_PANEL_SETTINGS); + $db->query($query); + $settings['panel']['version'] = '0.9-r1'; - $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (119, 'spf', 'use_spf', '0');"); - $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (120, 'spf', 'spf_entry', '@ IN TXT \"v=spf1 a mx -all\"');"); - - // Convert all data to UTF-8 to have a sane standard across all data - $tables = $db->fetch_array("SHOW TABLES"); - foreach ($tables as $table) - { - $db->query("ALTER TABLE " . $table[0] . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"); - $db->query("ALTER TABLE " . $table[0] . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); - - $columns = $db->fetch_array("SHOW COLUMNS FROM ".$table[0]); - - $affected_columns = array(); - - $primarykey = ""; - foreach ($columns as $column) - { - if (!(strpos($column['Type'], "char") === false) || !(strpos($column['Type'], "text") === false)) - { - $affected_columns[] = $column['Field']; - } - - if ($column['Key'] == 'PRI') { - $primarykey = $column['Field']; - } - } - - $count_cols = count($affected_columns); - if ($count_cols > 0) - { - $load = ""; - foreach($affected_columns as $col) - { - $load .= ", " . $col; - } - - $rows = $db->fetch_array("SELECT $primarykey" . $load . " FROM " . $table[0]); - - foreach($rows as $row) - { - $changes = ""; - for ($i = 0; $i < $count_cols; $i++) - { - $base = $affected_columns[$i] . " = " . $db->escape(convertUtf8($row[$affected_columns[$i]])) ; - $changes .= ($i == ($count_cols-1)) ? $base : $base . ", "; - } - - $db->query("UPDATE " . $table[0] . " SET " . $changes . " WHERE $primarykey = " . $db->escape($row['id']) . ";"); - } - } - } - - $db->query("UPDATE `panel_settings` SET `varname` = 'froxlor_graphic' WHERE `varname` = 'syscp_graphic'"); } ?> diff --git a/install/updates/1.0/update_1.0.10_1.2-beta1.inc.php b/install/updates/syscp/1.0/update_1.0.10_1.2-beta1.inc.php similarity index 100% rename from install/updates/1.0/update_1.0.10_1.2-beta1.inc.php rename to install/updates/syscp/1.0/update_1.0.10_1.2-beta1.inc.php diff --git a/install/updates/1.0/update_1.0_1.0.10.inc.php b/install/updates/syscp/1.0/update_1.0_1.0.10.inc.php similarity index 100% rename from install/updates/1.0/update_1.0_1.0.10.inc.php rename to install/updates/syscp/1.0/update_1.0_1.0.10.inc.php diff --git a/install/updates/1.2/update_1.2-beta1_1.2.19.inc.php b/install/updates/syscp/1.2/update_1.2-beta1_1.2.19.inc.php similarity index 100% rename from install/updates/1.2/update_1.2-beta1_1.2.19.inc.php rename to install/updates/syscp/1.2/update_1.2-beta1_1.2.19.inc.php diff --git a/install/updates/1.2/update_1.2.19_1.4.inc.php b/install/updates/syscp/1.2/update_1.2.19_1.4.inc.php similarity index 100% rename from install/updates/1.2/update_1.2.19_1.4.inc.php rename to install/updates/syscp/1.2/update_1.2.19_1.4.inc.php diff --git a/install/updates/1.4/update_1.4.inc.php b/install/updates/syscp/1.4/update_1.4.inc.php similarity index 100% rename from install/updates/1.4/update_1.4.inc.php rename to install/updates/syscp/1.4/update_1.4.inc.php diff --git a/install/updatesql.php b/install/updatesql.php index 1283a86c..069d1bff 100644 --- a/install/updatesql.php +++ b/install/updatesql.php @@ -51,7 +51,7 @@ unset($result); require ('../lib/functions.php'); -$updatelog = SysCPLogger::getInstanceOf(array('loginname' => 'updater'), $db, $settings); +$updatelog = FroxlorLogger::getInstanceOf(array('loginname' => 'updater'), $db, $settings); /* * since froxlor, we have to check if there's still someone @@ -68,7 +68,7 @@ if(!isset($settings['panel']['frontend']) || (substr($settings['panel']['version'], 0, 3) == '1.0' && $settings['panel']['version'] != '1.0.10')) { $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.0 to 1.0.10"); - include_once ('./updates/1.0/update_1.0_1.0.10.inc.php'); + include_once ('./updates/syscp/1.0/update_1.0_1.0.10.inc.php'); } /** @@ -78,7 +78,7 @@ if(!isset($settings['panel']['frontend']) if($settings['panel']['version'] == '1.0.10') { $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.0.10 to 1.2-beta1"); - include_once ('./updates/1.0/update_1.0.10_1.2-beta1.inc.php'); + include_once ('./updates/syscp/1.0/update_1.0.10_1.2-beta1.inc.php'); } /** @@ -88,7 +88,7 @@ if(!isset($settings['panel']['frontend']) if(substr($settings['panel']['version'], 0, 3) == '1.2') { $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.2-beta1 to 1.2.19"); - include_once ('./updates/1.2/update_1.2-beta1_1.2.19.inc.php'); + include_once ('./updates/syscp/1.2/update_1.2-beta1_1.2.19.inc.php'); } /** @@ -98,7 +98,7 @@ if(!isset($settings['panel']['frontend']) if(substr($settings['panel']['version'], 0, 6) == '1.2.19') { $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.2.19 to 1.4"); - include_once ('./updates/1.2/update_1.2.19_1.4.inc.php'); + include_once ('./updates/syscp/1.2/update_1.2.19_1.4.inc.php'); } /** @@ -108,7 +108,7 @@ if(!isset($settings['panel']['frontend']) if(substr($settings['panel']['version'], 0, 3) == '1.4') { $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 1.4"); - include_once ('./updates/1.4/update_1.4.inc.php'); + include_once ('./updates/syscp/1.4/update_1.4.inc.php'); } /** @@ -120,6 +120,16 @@ if(!isset($settings['panel']['frontend']) */ include_once ('./updates/froxlor/upgrade_syscp.inc.php'); +} +if(!isset($settings['panel']['frontend']) + || $settings['panel']['frontend'] == 'froxlor') +{ + if($settings['panel']['version'] == '0.9-r1') + { + $updatelog->logAction(ADM_ACTION, LOG_WARNING, "Updating from 0.9"); + include_once ('./updates/froxlor/0.9/update_0.9.inc.php'); + } + } updateCounters(); diff --git a/lib/tables.inc.php b/lib/tables.inc.php index 450b6f50..89488c75 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -65,7 +65,7 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9'; +$version = '0.9-r2'; $dbversion = '2'; ?>