diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php index 1204b10..6233e82 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','removeOldSearchPlugins','addAutoIncrementToTables') + '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier','removeOldSearchPlugins','addAutoIncrementToTables', 'addAutoIncrementToTables2') ); var $descriptions = array( @@ -95,7 +95,8 @@ class UpgradeFunctions { 'moveConfigSettingsToDB' => 'Move the configuration settings from the config.ini file into the new database table.', 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.', 'removeOldSearchPlugins' => 'Remove the old Search Plugins.', - 'addAutoIncrementToTables' => 'Update all db tables to use auto_increment.' + 'addAutoIncrementToTables' => 'Update all current db tables to use auto_increment.', + 'addAutoIncrementToTables2' => 'Update all new db tables to use auto_increment.' ); var $phases = array( "setPermissionFolder" => 1, @@ -115,37 +116,67 @@ class UpgradeFunctions { ); var $priority = array( - 'addAutoIncrementToTables'=>1 + 'addAutoIncrementToTables'=>1, + 'addAutoIncrementToTables2'=>-1 ); + function addAutoIncrementToTables2() + { + return self::addAutoIncrementToTables(); + } + /** * Set all tables in the DB to auto increment, thereby removing the use of the zseq tables */ function addAutoIncrementToTables() { + static $doneTables = array(); + global $default; DBUtil::setupAdminDatabase(); $db = $default->_admindb; // Get all tables in the database - $query = 'SHOW TABLES'; + $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 + if(in_array($tableName, $doneTables)){ + // already been set - skip + continue; + } + + + $doneTables[] = $tableName; + + if(strpos($tableName, 'zseq_', 0) !== false){ + // ignore zseq tables + continue; + } + + $query = "SELECT max(id) FROM {$tableName}"; + $aId = DBUtil::getOneResult($query); + + if(PEAR::isError($aId)){ + // Means that the table doesn't have an id column + continue; + } + + // If there's no result, then the table may be empty + if(!empty($aId)){ + $id = (int)$aId['max(id)'] + 1; + + $query = "UPDATE {$tableName} SET id = {$id} WHERE id = 0"; + $res = DBUtil::runQuery($query, $db); + } + + // Update the table, set id to auto_increment $query = "ALTER TABLE {$tableName} CHANGE `id` `id` int (11) NOT NULL AUTO_INCREMENT"; - DBUtil::runQuery($query, $db); + $res = DBUtil::runQuery($query, $db); } } @@ -1308,7 +1339,7 @@ class UpgradeFunctions { if(file_exists($oldPath)) return rmdir($oldPath); } // }}} - + // {{{ removeOldSearchPlugins function removeOldSearchPlugins() { global $default; @@ -1322,7 +1353,7 @@ class UpgradeFunctions { UpgradeFunctions::rm_recursive($oldPath1); $oldPath2 = KT_DIR . "/plugins/generalmetadata/"; UpgradeFunctions::rm_recursive($oldPath2); - + // FIXME: We should check that they all worked return true; } diff --git a/sql/mysql/upgrade/3.5.3/add_autoinc.sql b/sql/mysql/upgrade/3.5.3/add_autoinc.sql deleted file mode 100644 index 7f5a472..0000000 --- a/sql/mysql/upgrade/3.5.3/add_autoinc.sql +++ /dev/null @@ -1,83 +0,0 @@ -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;