From aaa073d9fd70aa98217b8bad5e8de207d2c6e33e Mon Sep 17 00:00:00 2001 From: Davy Rolink Date: Thu, 2 Oct 2014 20:55:22 +0200 Subject: [PATCH] 3.1.1 upgrade --- src/includes/psmconfig.inc.php | 2 +- src/psm/Util/Install/Installer.class.php | 37 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/includes/psmconfig.inc.php b/src/includes/psmconfig.inc.php index 9876bc88..45d09266 100644 --- a/src/includes/psmconfig.inc.php +++ b/src/includes/psmconfig.inc.php @@ -29,7 +29,7 @@ /** * Current PSM version */ -define('PSM_VERSION', '3.1.0'); +define('PSM_VERSION', '3.1.1'); /** * URL to check for updates. Will not be checked if turned off on config page. diff --git a/src/psm/Util/Install/Installer.class.php b/src/psm/Util/Install/Installer.class.php index 7fb96507..da82f765 100644 --- a/src/psm/Util/Install/Installer.class.php +++ b/src/psm/Util/Install/Installer.class.php @@ -78,7 +78,7 @@ class Installer { // different DB version, check if the version requires any changes // @todo this is currently a manual check for each version, similar to upgrade().. not a clean way - if(version_compare($version_db, '3.1.0', '<')) { + if(version_compare($version_db, '3.1.1', '<')) { return true; } else { // change database version to current version so this check won't be required next time @@ -209,7 +209,7 @@ class Installer { PSM_DB_PREFIX . 'log_users' => "CREATE TABLE `" . PSM_DB_PREFIX . "log_users` ( `log_id` int(11) UNSIGNED NOT NULL , `user_id` int(11) UNSIGNED NOT NULL , - PRIMARY KEY (`log_id`, `user_id`), + PRIMARY KEY (`log_id`, `user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", PSM_DB_PREFIX . 'servers' => "CREATE TABLE `" . PSM_DB_PREFIX . "servers` ( `server_id` int(11) unsigned NOT NULL AUTO_INCREMENT, @@ -286,6 +286,10 @@ class Installer { // upgrade to 3.1.0 $this->upgrade310(); } + if(version_compare($version_from, '3.1.1', '<')) { + // upgrade to 3.1.1 + $this->upgrade311(); + } psm_update_conf('version', $version_to); } @@ -425,4 +429,33 @@ class Installer { $this->execSQL($queries); } + + /** + * Upgrade for v3.1.1 release (all log-users relations are in a separate table) + */ + protected function upgrade311() { + // Create log_users table + $this->execSQL("CREATE TABLE `" . PSM_DB_PREFIX . "log_users` ( + `log_id` int(11) UNSIGNED NOT NULL , + `user_id` int(11) UNSIGNED NOT NULL , + PRIMARY KEY (`log_id`, `user_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + + // Migrate the data + $logs = $this->db->select(PSM_DB_PREFIX . 'log', null, array('log_id', 'user_id')); + foreach ($logs as $log) { + // Validation + if (empty($log['user_id']) || trim($log['user_id']) == '') { + continue; + } + + // Insert into new table + foreach (explode(',', $log['user_id']) as $user_id) { + psm_add_log_user($log['log_id'], $user_id); + } + } + + // Drop old user_id('s) column + $this->execSQL("ALTER TABLE `" . PSM_DB_PREFIX . "log` DROP COLUMN `user_id`;"); + } }