diff options
29 files changed, 125 insertions, 127 deletions
diff --git a/core/Updater.php b/core/Updater.php index 6d46bbf147..8b272cde66 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -313,12 +313,29 @@ class Updater public static function handleQueryError($e, $updateSql, $errorToIgnore, $file) { if (($errorToIgnore === false) - || !Db::get()->isErrNo($e, $errorToIgnore) + || !self::isDbErrorOneOf($e, $errorToIgnore) ) { $message = $file . ":\nError trying to execute the query '" . $updateSql . "'.\nThe error was: " . $e->getMessage(); throw new UpdaterErrorException($message); } } + + /** + * Returns whether an exception is a DB error with a code in the $errorCodesToIgnore list. + * + * @param int $error + * @param int|int[] $errorCodesToIgnore + */ + public static function isDbErrorOneOf($error, $errorCodesToIgnore) + { + $errorCodesToIgnore = is_array($errorCodesToIgnore) ? $errorCodesToIgnore : array($errorCodesToIgnore); + foreach ($errorCodesToIgnore as $code) { + if (Db::get()->isErrNo($error, $code)) { + return true; + } + } + return false; + } } /** @@ -327,4 +344,4 @@ class Updater */ class UpdaterErrorException extends \Exception { -} +}
\ No newline at end of file diff --git a/core/Updates/0.2.10.php b/core/Updates/0.2.10.php index b42449aacc..1ab471e32d 100644 --- a/core/Updates/0.2.10.php +++ b/core/Updates/0.2.10.php @@ -26,27 +26,27 @@ class Updates_0_2_10 extends Updates option_name VARCHAR( 64 ) NOT NULL , option_value LONGTEXT NOT NULL , PRIMARY KEY ( idoption , option_name ) - )' => false, + )' => 1050, // 0.1.7 [463] 'ALTER IGNORE TABLE `' . Common::prefixTable('log_visit') . '` - CHANGE `location_provider` `location_provider` VARCHAR( 100 ) DEFAULT NULL' => '1054', + CHANGE `location_provider` `location_provider` VARCHAR( 100 ) DEFAULT NULL' => 1054, // 0.1.7 [470] 'ALTER TABLE `' . Common::prefixTable('logger_api_call') . '` CHANGE `parameter_names_default_values` `parameter_names_default_values` TEXT, CHANGE `parameter_values` `parameter_values` TEXT, - CHANGE `returned_value` `returned_value` TEXT' => false, + CHANGE `returned_value` `returned_value` TEXT' => array(1054, 1146), 'ALTER TABLE `' . Common::prefixTable('logger_error') . '` - CHANGE `message` `message` TEXT' => false, + CHANGE `message` `message` TEXT' => array(1054, 1146), 'ALTER TABLE `' . Common::prefixTable('logger_exception') . '` - CHANGE `message` `message` TEXT' => false, + CHANGE `message` `message` TEXT' => array(1054, 1146), 'ALTER TABLE `' . Common::prefixTable('logger_message') . '` - CHANGE `message` `message` TEXT' => false, + CHANGE `message` `message` TEXT' => 1054, // 0.2.2 [489] 'ALTER IGNORE TABLE `' . Common::prefixTable('site') . '` - CHANGE `feedburnerName` `feedburnerName` VARCHAR( 100 ) DEFAULT NULL' => '1054', + CHANGE `feedburnerName` `feedburnerName` VARCHAR( 100 ) DEFAULT NULL' => 1054, ); } diff --git a/core/Updates/0.2.12.php b/core/Updates/0.2.12.php index 975ba373cd..0cf0fed8ea 100644 --- a/core/Updates/0.2.12.php +++ b/core/Updates/0.2.12.php @@ -23,11 +23,11 @@ class Updates_0_2_12 extends Updates 'ALTER TABLE `' . Common::prefixTable('site') . '` CHANGE `ts_created` `ts_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL' => false, 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - DROP `config_color_depth`' => false, + DROP `config_color_depth`' => 1091, // 0.2.12 [673] // Note: requires INDEX privilege - 'DROP INDEX index_idaction ON `' . Common::prefixTable('log_action') . '`' => '1091', + 'DROP INDEX index_idaction ON `' . Common::prefixTable('log_action') . '`' => 1091, ); } diff --git a/core/Updates/0.2.13.php b/core/Updates/0.2.13.php index eb65347c45..e73acf0b77 100644 --- a/core/Updates/0.2.13.php +++ b/core/Updates/0.2.13.php @@ -27,7 +27,7 @@ class Updates_0_2_13 extends Updates option_value LONGTEXT NOT NULL , autoload TINYINT NOT NULL DEFAULT '1', PRIMARY KEY ( option_name ) - )" => false, + )" => 1050, ); } diff --git a/core/Updates/0.2.24.php b/core/Updates/0.2.24.php index b4762ad15d..23bf21274e 100644 --- a/core/Updates/0.2.24.php +++ b/core/Updates/0.2.24.php @@ -21,11 +21,11 @@ class Updates_0_2_24 extends Updates { return array( 'CREATE INDEX index_type_name - ON ' . Common::prefixTable('log_action') . ' (type, name(15))' => false, + ON ' . Common::prefixTable('log_action') . ' (type, name(15))' => 1072, 'CREATE INDEX index_idsite_date - ON ' . Common::prefixTable('log_visit') . ' (idsite, visit_server_date)' => false, - 'DROP INDEX index_idsite ON ' . Common::prefixTable('log_visit') => false, - 'DROP INDEX index_visit_server_date ON ' . Common::prefixTable('log_visit') => false, + ON ' . Common::prefixTable('log_visit') . ' (idsite, visit_server_date)' => 1072, + 'DROP INDEX index_idsite ON ' . Common::prefixTable('log_visit') => 1091, + 'DROP INDEX index_visit_server_date ON ' . Common::prefixTable('log_visit') => 1091, ); } diff --git a/core/Updates/0.2.27.php b/core/Updates/0.2.27.php index 483d915a0f..615709e599 100644 --- a/core/Updates/0.2.27.php +++ b/core/Updates/0.2.27.php @@ -22,10 +22,10 @@ class Updates_0_2_27 extends Updates { $sqlarray = array( 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - ADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time`' => false, + ADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time`' => 1060, // 0.2.27 [826] 'ALTER IGNORE TABLE `' . Common::prefixTable('log_visit') . '` - CHANGE `visit_goal_converted` `visit_goal_converted` TINYINT(1) NOT NULL' => false, + CHANGE `visit_goal_converted` `visit_goal_converted` TINYINT(1) NOT NULL' => 1060, 'CREATE TABLE `' . Common::prefixTable('goal') . "` ( `idsite` int(11) NOT NULL, @@ -38,7 +38,7 @@ class Updates_0_2_27 extends Updates `revenue` float NOT NULL, `deleted` tinyint(4) NOT NULL default '0', PRIMARY KEY (`idsite`,`idgoal`) - )" => false, + )" => 1050, 'CREATE TABLE `' . Common::prefixTable('log_conversion') . '` ( `idvisit` int(10) unsigned NOT NULL, @@ -61,13 +61,13 @@ class Updates_0_2_27 extends Updates `revenue` float default NULL, PRIMARY KEY (`idvisit`,`idgoal`), KEY `index_idsite_date` (`idsite`,`visit_server_date`) - )' => false, + )' => 1050, ); $tables = DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (preg_match('/archive_/', $tableName) == 1) { - $sqlarray['CREATE INDEX index_all ON ' . $tableName . ' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)'] = false; + $sqlarray['CREATE INDEX index_all ON ' . $tableName . ' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)'] = 1072; } } diff --git a/core/Updates/0.4.2.php b/core/Updates/0.4.2.php index b4b44053bd..d3cac21d21 100644 --- a/core/Updates/0.4.2.php +++ b/core/Updates/0.4.2.php @@ -21,12 +21,12 @@ class Updates_0_4_2 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - ADD `config_java` TINYINT(1) NOT NULL AFTER `config_flash`' => '1060', + ADD `config_java` TINYINT(1) NOT NULL AFTER `config_flash`' => 1060, 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - ADD `config_quicktime` TINYINT(1) NOT NULL AFTER `config_director`' => '1060', + ADD `config_quicktime` TINYINT(1) NOT NULL AFTER `config_director`' => 1060, 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` ADD `config_gears` TINYINT(1) NOT NULL AFTER `config_windowsmedia`, - ADD `config_silverlight` TINYINT(1) NOT NULL AFTER `config_gears`' => false, + ADD `config_silverlight` TINYINT(1) NOT NULL AFTER `config_gears`' => 1060, ); } diff --git a/core/Updates/0.4.php b/core/Updates/0.4.php index fe3f1426d2..ce86db2cee 100644 --- a/core/Updates/0.4.php +++ b/core/Updates/0.4.php @@ -22,13 +22,13 @@ class Updates_0_4 extends Updates return array( // 0.4 [1140] 'UPDATE `' . Common::prefixTable('log_visit') . '` - SET location_ip=location_ip+CAST(POW(2,32) AS UNSIGNED) WHERE location_ip < 0' => false, + SET location_ip=location_ip+CAST(POW(2,32) AS UNSIGNED) WHERE location_ip < 0' => false, 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - CHANGE `location_ip` `location_ip` BIGINT UNSIGNED NOT NULL' => false, + CHANGE `location_ip` `location_ip` BIGINT UNSIGNED NOT NULL' => 1054, 'UPDATE `' . Common::prefixTable('logger_api_call') . '` - SET caller_ip=caller_ip+CAST(POW(2,32) AS UNSIGNED) WHERE caller_ip < 0' => false, + SET caller_ip=caller_ip+CAST(POW(2,32) AS UNSIGNED) WHERE caller_ip < 0' => 1146, 'ALTER TABLE `' . Common::prefixTable('logger_api_call') . '` - CHANGE `caller_ip` `caller_ip` BIGINT UNSIGNED' => false, + CHANGE `caller_ip` `caller_ip` BIGINT UNSIGNED' => 1146, ); } diff --git a/core/Updates/0.5.5.php b/core/Updates/0.5.5.php index 28822ddbea..50f6236caa 100644 --- a/core/Updates/0.5.5.php +++ b/core/Updates/0.5.5.php @@ -21,17 +21,17 @@ class Updates_0_5_5 extends Updates static function getSql() { $sqlarray = array( - 'DROP INDEX index_idsite_date ON ' . Common::prefixTable('log_visit') => '1091', - 'CREATE INDEX index_idsite_date_config ON ' . Common::prefixTable('log_visit') . ' (idsite, visit_server_date, config_md5config(8))' => '1061', + 'DROP INDEX index_idsite_date ON ' . Common::prefixTable('log_visit') => 1091, + 'CREATE INDEX index_idsite_date_config ON ' . Common::prefixTable('log_visit') . ' (idsite, visit_server_date, config_md5config(8))' => array(1061,1072), ); $tables = DbHelper::getTablesInstalled(); foreach ($tables as $tableName) { if (preg_match('/archive_/', $tableName) == 1) { - $sqlarray['DROP INDEX index_all ON ' . $tableName] = '1091'; + $sqlarray['DROP INDEX index_all ON ' . $tableName] = 1091; } if (preg_match('/archive_numeric_/', $tableName) == 1) { - $sqlarray['CREATE INDEX index_idsite_dates_period ON ' . $tableName . ' (idsite, date1, date2, period)'] = '1061'; + $sqlarray['CREATE INDEX index_idsite_dates_period ON ' . $tableName . ' (idsite, date1, date2, period)'] = 1061; } } diff --git a/core/Updates/0.5.php b/core/Updates/0.5.php index 81d73db841..6c7a51af4e 100644 --- a/core/Updates/0.5.php +++ b/core/Updates/0.5.php @@ -20,16 +20,16 @@ class Updates_0_5 extends Updates static function getSql() { return array( - 'ALTER TABLE ' . Common::prefixTable('log_action') . ' ADD COLUMN `hash` INTEGER(10) UNSIGNED NOT NULL AFTER `name`;' => '1060', - 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' CHANGE visit_exit_idaction visit_exit_idaction_url INTEGER(11) NOT NULL;' => '1054', - 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' CHANGE visit_entry_idaction visit_entry_idaction_url INTEGER(11) NOT NULL;' => '1054', - 'ALTER TABLE ' . Common::prefixTable('log_link_visit_action') . ' CHANGE `idaction_ref` `idaction_url_ref` INTEGER(10) UNSIGNED NOT NULL;' => '1054', - 'ALTER TABLE ' . Common::prefixTable('log_link_visit_action') . ' CHANGE `idaction` `idaction_url` INTEGER(10) UNSIGNED NOT NULL;' => '1054', - 'ALTER TABLE ' . Common::prefixTable('log_link_visit_action') . ' ADD COLUMN `idaction_name` INTEGER(10) UNSIGNED AFTER `idaction_url_ref`;' => '1060', - 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' CHANGE `idaction` `idaction_url` INTEGER(11) UNSIGNED NOT NULL;' => '1054', + 'ALTER TABLE ' . Common::prefixTable('log_action') . ' ADD COLUMN `hash` INTEGER(10) UNSIGNED NOT NULL AFTER `name`;' => 1060, + 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' CHANGE visit_exit_idaction visit_exit_idaction_url INTEGER(11) NOT NULL;' => 1054, + 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' CHANGE visit_entry_idaction visit_entry_idaction_url INTEGER(11) NOT NULL;' => 1054, + 'ALTER TABLE ' . Common::prefixTable('log_link_visit_action') . ' CHANGE `idaction_ref` `idaction_url_ref` INTEGER(10) UNSIGNED NOT NULL;' => 1054, + 'ALTER TABLE ' . Common::prefixTable('log_link_visit_action') . ' CHANGE `idaction` `idaction_url` INTEGER(10) UNSIGNED NOT NULL;' => 1054, + 'ALTER TABLE ' . Common::prefixTable('log_link_visit_action') . ' ADD COLUMN `idaction_name` INTEGER(10) UNSIGNED AFTER `idaction_url_ref`;' => 1060, + 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' CHANGE `idaction` `idaction_url` INTEGER(11) UNSIGNED NOT NULL;' => 1054, 'UPDATE ' . Common::prefixTable('log_action') . ' SET `hash` = CRC32(name);' => false, - 'CREATE INDEX index_type_hash ON ' . Common::prefixTable('log_action') . ' (type, hash);' => '1061', - 'DROP INDEX index_type_name ON ' . Common::prefixTable('log_action') . ';' => '1091', + 'CREATE INDEX index_type_hash ON ' . Common::prefixTable('log_action') . ' (type, hash);' => 1061, + 'DROP INDEX index_type_name ON ' . Common::prefixTable('log_action') . ';' => 1091, ); } diff --git a/core/Updates/0.6-rc1.php b/core/Updates/0.6-rc1.php index 5286e7371a..9f293dda97 100644 --- a/core/Updates/0.6-rc1.php +++ b/core/Updates/0.6-rc1.php @@ -22,19 +22,19 @@ class Updates_0_6_rc1 extends Updates $defaultTimezone = 'UTC'; $defaultCurrency = 'USD'; return array( - 'ALTER TABLE ' . Common::prefixTable('user') . ' CHANGE date_registered date_registered TIMESTAMP NULL' => false, - 'ALTER TABLE ' . Common::prefixTable('site') . ' CHANGE ts_created ts_created TIMESTAMP NULL' => false, - 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD `timezone` VARCHAR( 50 ) NOT NULL AFTER `ts_created` ;' => false, - 'UPDATE ' . Common::prefixTable('site') . ' SET `timezone` = "' . $defaultTimezone . '";' => false, - 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD currency CHAR( 3 ) NOT NULL AFTER `timezone` ;' => false, - 'UPDATE ' . Common::prefixTable('site') . ' SET `currency` = "' . $defaultCurrency . '";' => false, - 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD `excluded_ips` TEXT NOT NULL AFTER `currency` ;' => false, - 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD excluded_parameters VARCHAR( 255 ) NOT NULL AFTER `excluded_ips` ;' => false, - 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' ADD INDEX `index_idsite_datetime_config` ( `idsite` , `visit_last_action_time` , `config_md5config` ( 8 ) ) ;' => false, - 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' ADD INDEX index_idsite_idvisit (idsite, idvisit) ;' => false, - 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' DROP INDEX index_idsite_date' => false, - 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' DROP visit_server_date;' => false, - 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' ADD INDEX index_idsite_datetime ( `idsite` , `server_time` )' => false, + 'ALTER TABLE ' . Common::prefixTable('user') . ' CHANGE date_registered date_registered TIMESTAMP NULL' => 1054, + 'ALTER TABLE ' . Common::prefixTable('site') . ' CHANGE ts_created ts_created TIMESTAMP NULL' => 1054, + 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD `timezone` VARCHAR( 50 ) NOT NULL AFTER `ts_created` ;' => 1060, + 'UPDATE ' . Common::prefixTable('site') . ' SET `timezone` = "' . $defaultTimezone . '";' => 1060, + 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD currency CHAR( 3 ) NOT NULL AFTER `timezone` ;' => 1060, + 'UPDATE ' . Common::prefixTable('site') . ' SET `currency` = "' . $defaultCurrency . '";' => 1060, + 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD `excluded_ips` TEXT NOT NULL AFTER `currency` ;' => 1060, + 'ALTER TABLE ' . Common::prefixTable('site') . ' ADD excluded_parameters VARCHAR( 255 ) NOT NULL AFTER `excluded_ips` ;' => 1060, + 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' ADD INDEX `index_idsite_datetime_config` ( `idsite` , `visit_last_action_time` , `config_md5config` ( 8 ) ) ;' => array(1061, 1072), + 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' ADD INDEX index_idsite_idvisit (idsite, idvisit) ;' => array(1061, 1072), + 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' DROP INDEX index_idsite_date' => 1091, + 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' DROP visit_server_date;' => 1091, + 'ALTER TABLE ' . Common::prefixTable('log_conversion') . ' ADD INDEX index_idsite_datetime ( `idsite` , `server_time` )' => array(1072, 1061), ); } @@ -64,4 +64,4 @@ class Updates_0_6_rc1 extends Updates "</li></ul>"); } } -} +}
\ No newline at end of file diff --git a/core/Updates/0.6.3.php b/core/Updates/0.6.3.php index b91b67fd3b..56488304ff 100644 --- a/core/Updates/0.6.3.php +++ b/core/Updates/0.6.3.php @@ -22,9 +22,9 @@ class Updates_0_6_3 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - CHANGE `location_ip` `location_ip` INT UNSIGNED NOT NULL' => false, + CHANGE `location_ip` `location_ip` INT UNSIGNED NOT NULL' => 1054, 'ALTER TABLE `' . Common::prefixTable('logger_api_call') . '` - CHANGE `caller_ip` `caller_ip` INT UNSIGNED' => false, + CHANGE `caller_ip` `caller_ip` INT UNSIGNED' => array(1054, 1146), ); } diff --git a/core/Updates/1.2-rc1.php b/core/Updates/1.2-rc1.php index 1e1862a432..c037e17fcd 100644 --- a/core/Updates/1.2-rc1.php +++ b/core/Updates/1.2-rc1.php @@ -35,7 +35,7 @@ class Updates_1_2_rc1 extends Updates ADD visitor_days_since_last SMALLINT(5) UNSIGNED NOT NULL, ADD visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL, ADD `config_id` BINARY(8) NOT NULL AFTER `config_md5config` - ' => false, + ' => array(1054, 1091), 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` ADD custom_var_k1 VARCHAR(100) DEFAULT NULL, ADD custom_var_v1 VARCHAR(100) DEFAULT NULL, @@ -54,14 +54,14 @@ class Updates_1_2_rc1 extends Updates ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`, ADD `idaction_name_ref` INT UNSIGNED NOT NULL AFTER `idaction_name`, ADD INDEX `index_idsite_servertime` ( `idsite` , `server_time` ) - ' => false, + ' => 1060, 'ALTER TABLE `' . Common::prefixTable('log_conversion') . '` DROP `referer_idvisit`, ADD `idvisitor` BINARY(8) NOT NULL AFTER `idsite`, ADD visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL, ADD visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL - ' => false, + ' => array(1060, 1091), 'ALTER TABLE `' . Common::prefixTable('log_conversion') . '` ADD custom_var_k1 VARCHAR(100) DEFAULT NULL, ADD custom_var_v1 VARCHAR(100) DEFAULT NULL, @@ -73,30 +73,30 @@ class Updates_1_2_rc1 extends Updates ADD custom_var_v4 VARCHAR(100) DEFAULT NULL, ADD custom_var_k5 VARCHAR(100) DEFAULT NULL, ADD custom_var_v5 VARCHAR(100) DEFAULT NULL - ' => 1060, + ' => array(1060, 1061), // Migrate 128bits IDs inefficiently stored as 8bytes (256 bits) into 64bits 'UPDATE ' . Common::prefixTable('log_visit') . ' SET idvisitor = binary(unhex(substring(visitor_idcookie,1,16))), config_id = binary(unhex(substring(config_md5config,1,16))) - ' => false, + ' => 1054, 'UPDATE ' . Common::prefixTable('log_conversion') . ' SET idvisitor = binary(unhex(substring(visitor_idcookie,1,16))) - ' => false, + ' => 1054, // Drop migrated fields 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` DROP visitor_idcookie, DROP config_md5config - ' => false, + ' => 1091, 'ALTER TABLE `' . Common::prefixTable('log_conversion') . '` DROP visitor_idcookie - ' => false, + ' => 1091, // Recreate INDEX on new field 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` ADD INDEX `index_idsite_datetime_config` (idsite, visit_last_action_time, config_id) - ' => false, + ' => 1061, // Backfill action logs as best as we can 'UPDATE ' . Common::prefixTable('log_link_visit_action') . ' as action, @@ -112,10 +112,10 @@ class Updates_1_2_rc1 extends Updates ' => false, // New index used max once per request, in case this table grows significantly in the future - 'ALTER TABLE `' . Common::prefixTable('option') . '` ADD INDEX ( `autoload` ) ' => false, + 'ALTER TABLE `' . Common::prefixTable('option') . '` ADD INDEX ( `autoload` ) ' => 1061, // new field for websites - 'ALTER TABLE `' . Common::prefixTable('site') . '` ADD `group` VARCHAR( 250 ) NOT NULL' => false, + 'ALTER TABLE `' . Common::prefixTable('site') . '` ADD `group` VARCHAR( 250 ) NOT NULL' => 1060, ); } diff --git a/core/Updates/1.2.3.php b/core/Updates/1.2.3.php index ae28ee7e9e..d240462468 100644 --- a/core/Updates/1.2.3.php +++ b/core/Updates/1.2.3.php @@ -22,14 +22,14 @@ class Updates_1_2_3 extends Updates { return array( // LOAD DATA INFILE uses the database's charset - 'ALTER DATABASE `' . Config::getInstance()->database['dbname'] . '` DEFAULT CHARACTER SET utf8' => false, + 'ALTER DATABASE `' . Config::getInstance()->database['dbname'] . '` DEFAULT CHARACTER SET utf8' => false, // Various performance improvements schema updates 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` DROP INDEX index_idsite_datetime_config, DROP INDEX index_idsite_idvisit, ADD INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time), - ADD INDEX index_idsite_datetime (idsite, visit_last_action_time)' => false, + ADD INDEX index_idsite_datetime (idsite, visit_last_action_time)' => array(1061, 1091), ); } diff --git a/core/Updates/1.2.5-rc1.php b/core/Updates/1.2.5-rc1.php index a4f6ee02bb..af6308ad8a 100644 --- a/core/Updates/1.2.5-rc1.php +++ b/core/Updates/1.2.5-rc1.php @@ -21,11 +21,11 @@ class Updates_1_2_5_rc1 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('goal') . '` - ADD `allow_multiple` tinyint(4) NOT NULL AFTER case_sensitive' => false, + ADD `allow_multiple` tinyint(4) NOT NULL AFTER case_sensitive' => 1060, 'ALTER TABLE `' . Common::prefixTable('log_conversion') . '` ADD buster int unsigned NOT NULL AFTER revenue, DROP PRIMARY KEY, - ADD PRIMARY KEY (idvisit, idgoal, buster)' => false, + ADD PRIMARY KEY (idvisit, idgoal, buster)' => 1060, ); } diff --git a/core/Updates/1.2.5-rc7.php b/core/Updates/1.2.5-rc7.php index 08284dd07f..94671da038 100644 --- a/core/Updates/1.2.5-rc7.php +++ b/core/Updates/1.2.5-rc7.php @@ -21,7 +21,7 @@ class Updates_1_2_5_rc7 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` - ADD INDEX index_idsite_idvisitor (idsite, idvisitor)' => false, + ADD INDEX index_idsite_idvisitor (idsite, idvisitor)' => 1061, ); } diff --git a/core/Updates/1.4-rc1.php b/core/Updates/1.4-rc1.php index 3697864ce1..5290e8d24b 100644 --- a/core/Updates/1.4-rc1.php +++ b/core/Updates/1.4-rc1.php @@ -21,7 +21,7 @@ class Updates_1_4_rc1 extends Updates { return array( 'UPDATE `' . Common::prefixTable('pdf') . '` - SET format = "pdf"' => '42S22', + SET format = "pdf"' => '42S22', 'ALTER TABLE `' . Common::prefixTable('pdf') . '` ADD COLUMN `format` VARCHAR(10)' => '42S22', ); diff --git a/core/Updates/1.4-rc2.php b/core/Updates/1.4-rc2.php index b2a3b3176c..a54ab231c0 100644 --- a/core/Updates/1.4-rc2.php +++ b/core/Updates/1.4-rc2.php @@ -20,20 +20,20 @@ class Updates_1_4_rc2 extends Updates static function getSql() { return array( - "SET sql_mode=''" => false, + "SET sql_mode=''" => false, // this converts the 32-bit UNSIGNED INT column to a 16 byte VARBINARY; // _but_ MySQL does string conversion! (e.g., integer 1 is converted to 49 -- the ASCII code for "1") 'ALTER TABLE ' . Common::prefixTable('log_visit') . ' MODIFY location_ip VARBINARY(16) NOT NULL' => false, 'ALTER TABLE ' . Common::prefixTable('logger_api_call') . ' - MODIFY caller_ip VARBINARY(16) NOT NULL' => false, + MODIFY caller_ip VARBINARY(16) NOT NULL' => 1146, // fortunately, 2^32 is 10 digits long and fits in the VARBINARY(16) without truncation; // to fix this, we cast to an integer, convert to hex, pad out leading zeros, and unhex it 'UPDATE ' . Common::prefixTable('log_visit') . " SET location_ip = UNHEX(LPAD(HEX(CONVERT(location_ip, UNSIGNED)), 8, '0'))" => false, 'UPDATE ' . Common::prefixTable('logger_api_call') . " - SET caller_ip = UNHEX(LPAD(HEX(CONVERT(caller_ip, UNSIGNED)), 8, '0'))" => false, + SET caller_ip = UNHEX(LPAD(HEX(CONVERT(caller_ip, UNSIGNED)), 8, '0'))" => 1146, ); } diff --git a/core/Updates/1.5-b1.php b/core/Updates/1.5-b1.php index 36b0b27724..176d2f6059 100644 --- a/core/Updates/1.5-b1.php +++ b/core/Updates/1.5-b1.php @@ -37,11 +37,11 @@ class Updates_1_5_b1 extends Updates PRIMARY KEY(idvisit, idorder, idaction_sku), INDEX index_idsite_servertime ( idsite, server_time ) - ) DEFAULT CHARSET=utf8 ' => false, + ) DEFAULT CHARSET=utf8 ' => 1050, 'ALTER IGNORE TABLE `' . Common::prefixTable('log_visit') . '` ADD visitor_days_since_order SMALLINT(5) UNSIGNED NOT NULL AFTER visitor_days_since_last, - ADD visit_goal_buyer TINYINT(1) NOT NULL AFTER visit_goal_converted' => false, + ADD visit_goal_buyer TINYINT(1) NOT NULL AFTER visit_goal_converted' => 1060, 'ALTER IGNORE TABLE `' . Common::prefixTable('log_conversion') . '` ADD visitor_days_since_order SMALLINT(5) UNSIGNED NOT NULL AFTER visitor_days_since_first, @@ -52,7 +52,7 @@ class Updates_1_5_b1 extends Updates ADD revenue_shipping float default NULL, ADD revenue_discount float default NULL, ADD UNIQUE KEY unique_idsite_idorder (idsite, idorder), - MODIFY idgoal int(10) NOT NULL' => false, + MODIFY idgoal int(10) NOT NULL' => 1060, ); } diff --git a/core/Updates/1.5-b4.php b/core/Updates/1.5-b4.php index 318552e3b7..802992f6ae 100644 --- a/core/Updates/1.5-b4.php +++ b/core/Updates/1.5-b4.php @@ -21,7 +21,7 @@ class Updates_1_5_b4 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('site') . '` - ADD ecommerce TINYINT DEFAULT 0' => false, + ADD ecommerce TINYINT DEFAULT 0' => 1060, ); } diff --git a/core/Updates/1.5-b5.php b/core/Updates/1.5-b5.php index 8f3ef447f2..5b13385fd8 100644 --- a/core/Updates/1.5-b5.php +++ b/core/Updates/1.5-b5.php @@ -26,7 +26,7 @@ class Updates_1_5_b5 extends Updates lifetime INTEGER, data TEXT, PRIMARY KEY ( id ) - ) DEFAULT CHARSET=utf8' => false, + ) DEFAULT CHARSET=utf8' => 1050, ); } diff --git a/core/Updates/1.6-b1.php b/core/Updates/1.6-b1.php index c200e5bf12..f28fc487cc 100644 --- a/core/Updates/1.6-b1.php +++ b/core/Updates/1.6-b1.php @@ -24,7 +24,7 @@ class Updates_1_6_b1 extends Updates ADD idaction_category2 INTEGER(10) UNSIGNED NOT NULL AFTER idaction_category, ADD idaction_category3 INTEGER(10) UNSIGNED NOT NULL, ADD idaction_category4 INTEGER(10) UNSIGNED NOT NULL, - ADD idaction_category5 INTEGER(10) UNSIGNED NOT NULL' => false, + ADD idaction_category5 INTEGER(10) UNSIGNED NOT NULL' => 1060, 'ALTER TABLE `' . Common::prefixTable('log_visit') . '` CHANGE custom_var_k1 custom_var_k1 VARCHAR(200) DEFAULT NULL, CHANGE custom_var_v1 custom_var_v1 VARCHAR(200) DEFAULT NULL, diff --git a/core/Updates/1.7-b1.php b/core/Updates/1.7-b1.php index 91f63e0309..676065d3bd 100644 --- a/core/Updates/1.7-b1.php +++ b/core/Updates/1.7-b1.php @@ -21,7 +21,7 @@ class Updates_1_7_b1 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('pdf') . '` - ADD COLUMN `aggregate_reports_format` TINYINT(1) NOT NULL AFTER `reports`' => false, + ADD COLUMN `aggregate_reports_format` TINYINT(1) NOT NULL AFTER `reports`' => 1060, 'UPDATE `' . Common::prefixTable('pdf') . '` SET `aggregate_reports_format` = 1' => false, ); diff --git a/core/Updates/1.7.2-rc7.php b/core/Updates/1.7.2-rc7.php index 2f479c0522..87ae2fc035 100755 --- a/core/Updates/1.7.2-rc7.php +++ b/core/Updates/1.7.2-rc7.php @@ -22,7 +22,7 @@ class Updates_1_7_2_rc7 extends Updates { return array( 'ALTER TABLE `' . Common::prefixTable('user_dashboard') . '` - ADD `name` VARCHAR( 100 ) NULL DEFAULT NULL AFTER `iddashboard`' => false, + ADD `name` VARCHAR( 100 ) NULL DEFAULT NULL AFTER `iddashboard`' => 1060, ); } diff --git a/core/Updates/1.9-b9.php b/core/Updates/1.9-b9.php index 39176d7f96..76a87da8af 100755 --- a/core/Updates/1.9-b9.php +++ b/core/Updates/1.9-b9.php @@ -35,10 +35,10 @@ class Updates_1_9_b9 extends Updates return array( // add geoip columns to log_visit - "ALTER TABLE `$logVisit` $addColumns" => 1091, + "ALTER TABLE `$logVisit` $addColumns" => array(1091, 1060), // add geoip columns to log_conversion - "ALTER TABLE `$logConversion` $addColumns" => 1091, + "ALTER TABLE `$logConversion` $addColumns" => array(1091, 1060), ); } diff --git a/core/Updates/2.0.4-b5.php b/core/Updates/2.0.4-b5.php index 24c0e0d589..94e6a6529d 100644 --- a/core/Updates/2.0.4-b5.php +++ b/core/Updates/2.0.4-b5.php @@ -56,7 +56,10 @@ class Updates_2_0_4_b5 extends Updates $superUser = null; } - if (!empty($superUser['bridge']) || empty($superUser)) { + if (!empty($superUser['bridge']) + || empty($superUser) + || empty($superUser['login']) + ) { // there is a super user which is not from the config but from the bridge, that means we already have // a super user in the database return; diff --git a/plugins/ExamplePlugin/API.php b/plugins/ExamplePlugin/API.php deleted file mode 100644 index ffa887761f..0000000000 --- a/plugins/ExamplePlugin/API.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\ExamplePlugin; - -/** - * API for plugin ExamplePlugin - * - * @method static \Piwik\Plugins\ExamplePlugin\API getInstance() - */ -class API extends \Piwik\Plugin\API -{ - /** - * Example method. Please remove if you do not need this API method. - * You can call this API method like this: - * /index.php?module=API&method=ExamplePlugin.getAnswerToLife - * /index.php?module=API&method=ExamplePlugin.getAnswerToLife&truth=0 - * - * @param bool $truth - * - * @return int - */ - public function getAnswerToLife($truth = true) - { - if ($truth) { - return 42; - } - - return 24; - } -} diff --git a/tests/PHPUnit/Fixture.php b/tests/PHPUnit/Fixture.php index 41bd85ddf1..b94ffcc4e2 100644 --- a/tests/PHPUnit/Fixture.php +++ b/tests/PHPUnit/Fixture.php @@ -791,8 +791,14 @@ class Fixture extends PHPUnit_Framework_Assert return $result; } - public static function updateDatabase() + public static function updateDatabase($force = false) { + if ($force) { + // remove version options to force update + Option::deleteLike('version%'); + Option::set('version_core', '0.0'); + } + $updater = new Updater(); $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); if (empty($componentsWithUpdateFile)) { @@ -801,8 +807,8 @@ class Fixture extends PHPUnit_Framework_Assert $result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile); if (!empty($result['coreError']) - && !empty($result['warnings']) - && !empty($result['errors']) + || !empty($result['warnings']) + || !empty($result['errors']) ) { throw new \Exception("Failed to update database (errors or warnings found): " . print_r($result, true)); } diff --git a/tests/PHPUnit/Integration/BackwardsCompatibility1XTest.php b/tests/PHPUnit/Integration/BackwardsCompatibility1XTest.php index 1331786c69..5cfdd4e1a4 100644 --- a/tests/PHPUnit/Integration/BackwardsCompatibility1XTest.php +++ b/tests/PHPUnit/Integration/BackwardsCompatibility1XTest.php @@ -76,6 +76,14 @@ class BackwardsCompatibility1XTest extends IntegrationTestCase $this->runApiTests($api, $params); } + public function testUpdateWorksAfterPiwikIsAlreadyUpToDate() + { + $result = Fixture::updateDatabase($force = true); + if ($result === false) { + throw new \Exception("Failed to force update (nothing to update)."); + } + } + public function getApiForTesting() { $idSite = 1; |