diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php index 1a1f8fb..1f3476b 100644 --- a/lib/upgrades/UpgradeFunctions.inc.php +++ b/lib/upgrades/UpgradeFunctions.inc.php @@ -61,7 +61,7 @@ class UpgradeFunctions { '3.1.6.3' => array('cleanupGroupMembership'), '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'), '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'), - '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier') + '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier','addAutoIncrementToTables') ); var $descriptions = array( @@ -93,7 +93,8 @@ class UpgradeFunctions { 'createIndexes'=>'Recreate db integrity:Create indexes on the database', 'removeSlashesFromObjects'=>'Remove slashes from documents and folders', 'moveConfigSettingsToDB' => 'Move the configuration settings from the config.ini file into the new database table.', - 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.' + 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.', + 'addAutoIncrementToTables' => 'Update all db tables to use auto_increment.' ); var $phases = array( "setPermissionFolder" => 1, @@ -109,9 +110,47 @@ class UpgradeFunctions { 'dropIndexes'=>4, 'createPrimaryKeys'=>5, 'createForeignKeys'=>6, - 'createIndexes'=>7, + 'createIndexes'=>7 ); + var $priority = array( + 'addAutoIncrementToTables'=>1 + ); + + /** + * Set all tables in the DB to auto increment, thereby removing the use of the zseq tables + */ + function addAutoIncrementToTables() + { + global $default; + DBUtil::setupAdminDatabase(); + $db = $default->_admindb; + + // Get all tables in the database + $query = 'SHOW TABLES'; + $tableList = DBUtil::getResultArray($query, $db); + + // Ensure that if there is a zero id on plugins and upgrades it is updated + $query = "UPDATE plugins SET id = (SELECT max(id)+1 FROM plugins) WHERE id = 0"; + DBUtil::runQuery($query, $db); + + $query = "UPDATE upgrades SET id = (SELECT max(id)+1 FROM plugins) WHERE id = 0"; + DBUtil::runQuery($query, $db); + + // Loop through tables and add auto increment + foreach ($tableList as $tableArr){ + $key = key($tableArr); + $tableName = $tableArr[$key]; + + // Some tables don't have an id column, we ignore those errors and continue + $query = "ALTER TABLE {$tableName} CHANGE `id` `id` int (11) NOT NULL AUTO_INCREMENT"; + DBUtil::runQuery($query, $db); + } + } + + /** + * Copy the modified config values from the config.ini to the appropriate setting in the database + */ function moveConfigSettingsToDB() { require_once('Config.php'); @@ -1259,7 +1298,7 @@ class UpgradeFunctions { $oScheduler->registerTask(); } // }}} - + // {{{ removeAdminVersionNotifier function removeAdminVersionNotifier() { global $default; diff --git a/lib/upgrades/UpgradeItems.inc.php b/lib/upgrades/UpgradeItems.inc.php index 4ecccf9..4a3f673 100644 --- a/lib/upgrades/UpgradeItems.inc.php +++ b/lib/upgrades/UpgradeItems.inc.php @@ -72,7 +72,7 @@ class UpgradeItem { var $date; var $result; - function UpgradeItem($name, $version, $description = null, $phase = 0) { + function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) { $this->name = $name; $this->version = $version; if (is_null($description)) { @@ -80,6 +80,7 @@ class UpgradeItem { } $this->description = $description; $this->phase = $phase; + $this->priority = $priority; } function setParent($parent) { @@ -208,9 +209,9 @@ class SQLUpgradeItem extends UpgradeItem { $phase = $details[3]; } if (is_null($priority)) { - $this->priority = isset($details[4]) ? $details[4] : 0; + $priority = isset($details[4]) ? $details[4] : 0; } - $this->UpgradeItem($path, $version, $description, $phase); + $this->UpgradeItem($path, $version, $description, $phase, $priority); } /** @@ -338,7 +339,7 @@ class SQLUpgradeItem extends UpgradeItem { } class FunctionUpgradeItem extends UpgradeItem { - function FunctionUpgradeItem ($func, $version, $description = null, $phase = null) { + function FunctionUpgradeItem ($func, $version, $description = null, $phase = null, $priority = null) { $this->type = "func"; if (is_null($description)) { $aUpgradeFunctions = new UpgradeFunctions; @@ -347,7 +348,10 @@ class FunctionUpgradeItem extends UpgradeItem { if (is_null($phase)) { $phase = 0; } - $this->UpgradeItem($func, $version, $description, $phase); + if(is_null($priority)){ + $priority = 0; + } + $this->UpgradeItem($func, $version, $description, $phase, $priority); } function getUpgrades($origVersion, $currVersion) { @@ -364,7 +368,8 @@ class FunctionUpgradeItem extends UpgradeItem { } foreach ($funcs as $func) { $iPhase = KTUtil::arrayGet($aUpgradeFunctions->phases, $func, 0); - $ret[] = new FunctionUpgradeItem($func, $version, $aUpgradeFunctions->descriptions[$func], $iPhase); + $iPriority = KTUtil::arrayGet($aUpgradeFunctions->priority, $func, 0); + $ret[] = new FunctionUpgradeItem($func, $version, $aUpgradeFunctions->descriptions[$func], $iPhase, $iPriority); } } return $ret; diff --git a/sql/mysql/upgrade/3.5.3/add_autoinc.sql b/sql/mysql/upgrade/3.5.3/add_autoinc.sql new file mode 100644 index 0000000..7f5a472 --- /dev/null +++ b/sql/mysql/upgrade/3.5.3/add_autoinc.sql @@ -0,0 +1,83 @@ +select @id :=max(id)+1 from plugins; +update plugins set id = @id where id = 0; +select @id :=max(id)+1 from upgrades; +update upgrades set id = @id where id = 0; +alter table active_sessions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table archive_restoration_request change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table archiving_settings change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table archiving_type_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table authentication_sources change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table column_entries change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table dashlet_disables change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table data_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table discussion_comments change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table discussion_threads change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_archiving_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_content_version change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_fields change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_fields_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_incomplete change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_link_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_metadata_version change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_role_allocations change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_subscriptions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_transaction_types_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_transactions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_type_fields_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_type_fieldsets_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table document_types_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table documents change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table field_behaviours change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table field_value_instances change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table fieldsets change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table folder_doctypes_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table folder_subscriptions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table folder_transactions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table folders change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table folders_users_roles_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table groups_groups_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table groups_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table help change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table help_replacement change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table interceptor_instances change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table links change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table metadata_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table metadata_lookup_tree change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table mime_extractors change `id` `id` mediumint(9) NOT NULL AUTO_INCREMENT; +alter table mime_documents change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table mime_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table news change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table notifications change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table organisations_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permission_assignments change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permission_descriptors change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permission_dynamic_conditions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permission_lookup_assignments change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permission_lookups change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permission_objects change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table permissions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table plugin_helper change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table plugin_rss change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table plugins change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table role_allocations change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table roles change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table saved_searches change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table scheduler_tasks change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table search_saved change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table status_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table system_settings change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table tag_words change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table time_period change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table time_unit_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table units_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table units_organisations_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table upgrades change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table user_history change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table users change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table users_groups_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table workflow_state_permission_assignments change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table workflow_states change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table workflow_transitions change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table workflow_trigger_instances change `id` `id` int (11) NOT NULL AUTO_INCREMENT; +alter table workflows change `id` `id` int (11) NOT NULL AUTO_INCREMENT;