Commit c4f760482ae0b266deb67bb4c6d3faffc3cd32b8

Authored by kevin_fourie
1 parent b68ab510

Merged in from STABLE trunk...

KTS-3592
"Upgrade failed from 346 to 353."
Fixed. A function now runs before the upgrades to add auto_increment to the existing tables.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.3-Release-Branch@9085 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/upgrades/UpgradeFunctions.inc.php
@@ -61,7 +61,7 @@ class UpgradeFunctions { @@ -61,7 +61,7 @@ class UpgradeFunctions {
61 '3.1.6.3' => array('cleanupGroupMembership'), 61 '3.1.6.3' => array('cleanupGroupMembership'),
62 '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'), 62 '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'),
63 '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'), 63 '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'),
64 - '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier') 64 + '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier','addAutoIncrementToTables')
65 ); 65 );
66 66
67 var $descriptions = array( 67 var $descriptions = array(
@@ -93,7 +93,8 @@ class UpgradeFunctions { @@ -93,7 +93,8 @@ class UpgradeFunctions {
93 'createIndexes'=>'Recreate db integrity:Create indexes on the database', 93 'createIndexes'=>'Recreate db integrity:Create indexes on the database',
94 'removeSlashesFromObjects'=>'Remove slashes from documents and folders', 94 'removeSlashesFromObjects'=>'Remove slashes from documents and folders',
95 'moveConfigSettingsToDB' => 'Move the configuration settings from the config.ini file into the new database table.', 95 'moveConfigSettingsToDB' => 'Move the configuration settings from the config.ini file into the new database table.',
96 - 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.' 96 + 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.',
  97 + 'addAutoIncrementToTables' => 'Update all db tables to use auto_increment.'
97 ); 98 );
98 var $phases = array( 99 var $phases = array(
99 "setPermissionFolder" => 1, 100 "setPermissionFolder" => 1,
@@ -109,9 +110,47 @@ class UpgradeFunctions { @@ -109,9 +110,47 @@ class UpgradeFunctions {
109 'dropIndexes'=>4, 110 'dropIndexes'=>4,
110 'createPrimaryKeys'=>5, 111 'createPrimaryKeys'=>5,
111 'createForeignKeys'=>6, 112 'createForeignKeys'=>6,
112 - 'createIndexes'=>7, 113 + 'createIndexes'=>7
113 ); 114 );
114 115
  116 + var $priority = array(
  117 + 'addAutoIncrementToTables'=>1
  118 + );
  119 +
  120 + /**
  121 + * Set all tables in the DB to auto increment, thereby removing the use of the zseq tables
  122 + */
  123 + function addAutoIncrementToTables()
  124 + {
  125 + global $default;
  126 + DBUtil::setupAdminDatabase();
  127 + $db = $default->_admindb;
  128 +
  129 + // Get all tables in the database
  130 + $query = 'SHOW TABLES';
  131 + $tableList = DBUtil::getResultArray($query, $db);
  132 +
  133 + // Ensure that if there is a zero id on plugins and upgrades it is updated
  134 + $query = "UPDATE plugins SET id = (SELECT max(id)+1 FROM plugins) WHERE id = 0";
  135 + DBUtil::runQuery($query, $db);
  136 +
  137 + $query = "UPDATE upgrades SET id = (SELECT max(id)+1 FROM plugins) WHERE id = 0";
  138 + DBUtil::runQuery($query, $db);
  139 +
  140 + // Loop through tables and add auto increment
  141 + foreach ($tableList as $tableArr){
  142 + $key = key($tableArr);
  143 + $tableName = $tableArr[$key];
  144 +
  145 + // Some tables don't have an id column, we ignore those errors and continue
  146 + $query = "ALTER TABLE {$tableName} CHANGE `id` `id` int (11) NOT NULL AUTO_INCREMENT";
  147 + DBUtil::runQuery($query, $db);
  148 + }
  149 + }
  150 +
  151 + /**
  152 + * Copy the modified config values from the config.ini to the appropriate setting in the database
  153 + */
115 function moveConfigSettingsToDB() 154 function moveConfigSettingsToDB()
116 { 155 {
117 require_once('Config.php'); 156 require_once('Config.php');
@@ -1259,7 +1298,7 @@ class UpgradeFunctions { @@ -1259,7 +1298,7 @@ class UpgradeFunctions {
1259 $oScheduler->registerTask(); 1298 $oScheduler->registerTask();
1260 } 1299 }
1261 // }}} 1300 // }}}
1262 - 1301 +
1263 // {{{ removeAdminVersionNotifier 1302 // {{{ removeAdminVersionNotifier
1264 function removeAdminVersionNotifier() { 1303 function removeAdminVersionNotifier() {
1265 global $default; 1304 global $default;
lib/upgrades/UpgradeItems.inc.php
@@ -72,7 +72,7 @@ class UpgradeItem { @@ -72,7 +72,7 @@ class UpgradeItem {
72 var $date; 72 var $date;
73 var $result; 73 var $result;
74 74
75 - function UpgradeItem($name, $version, $description = null, $phase = 0) { 75 + function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) {
76 $this->name = $name; 76 $this->name = $name;
77 $this->version = $version; 77 $this->version = $version;
78 if (is_null($description)) { 78 if (is_null($description)) {
@@ -80,6 +80,7 @@ class UpgradeItem { @@ -80,6 +80,7 @@ class UpgradeItem {
80 } 80 }
81 $this->description = $description; 81 $this->description = $description;
82 $this->phase = $phase; 82 $this->phase = $phase;
  83 + $this->priority = $priority;
83 } 84 }
84 85
85 function setParent($parent) { 86 function setParent($parent) {
@@ -208,9 +209,9 @@ class SQLUpgradeItem extends UpgradeItem { @@ -208,9 +209,9 @@ class SQLUpgradeItem extends UpgradeItem {
208 $phase = $details[3]; 209 $phase = $details[3];
209 } 210 }
210 if (is_null($priority)) { 211 if (is_null($priority)) {
211 - $this->priority = isset($details[4]) ? $details[4] : 0; 212 + $priority = isset($details[4]) ? $details[4] : 0;
212 } 213 }
213 - $this->UpgradeItem($path, $version, $description, $phase); 214 + $this->UpgradeItem($path, $version, $description, $phase, $priority);
214 } 215 }
215 216
216 /** 217 /**
@@ -338,7 +339,7 @@ class SQLUpgradeItem extends UpgradeItem { @@ -338,7 +339,7 @@ class SQLUpgradeItem extends UpgradeItem {
338 } 339 }
339 340
340 class FunctionUpgradeItem extends UpgradeItem { 341 class FunctionUpgradeItem extends UpgradeItem {
341 - function FunctionUpgradeItem ($func, $version, $description = null, $phase = null) { 342 + function FunctionUpgradeItem ($func, $version, $description = null, $phase = null, $priority = null) {
342 $this->type = "func"; 343 $this->type = "func";
343 if (is_null($description)) { 344 if (is_null($description)) {
344 $aUpgradeFunctions = new UpgradeFunctions; 345 $aUpgradeFunctions = new UpgradeFunctions;
@@ -347,7 +348,10 @@ class FunctionUpgradeItem extends UpgradeItem { @@ -347,7 +348,10 @@ class FunctionUpgradeItem extends UpgradeItem {
347 if (is_null($phase)) { 348 if (is_null($phase)) {
348 $phase = 0; 349 $phase = 0;
349 } 350 }
350 - $this->UpgradeItem($func, $version, $description, $phase); 351 + if(is_null($priority)){
  352 + $priority = 0;
  353 + }
  354 + $this->UpgradeItem($func, $version, $description, $phase, $priority);
351 } 355 }
352 356
353 function getUpgrades($origVersion, $currVersion) { 357 function getUpgrades($origVersion, $currVersion) {
@@ -364,7 +368,8 @@ class FunctionUpgradeItem extends UpgradeItem { @@ -364,7 +368,8 @@ class FunctionUpgradeItem extends UpgradeItem {
364 } 368 }
365 foreach ($funcs as $func) { 369 foreach ($funcs as $func) {
366 $iPhase = KTUtil::arrayGet($aUpgradeFunctions->phases, $func, 0); 370 $iPhase = KTUtil::arrayGet($aUpgradeFunctions->phases, $func, 0);
367 - $ret[] = new FunctionUpgradeItem($func, $version, $aUpgradeFunctions->descriptions[$func], $iPhase); 371 + $iPriority = KTUtil::arrayGet($aUpgradeFunctions->priority, $func, 0);
  372 + $ret[] = new FunctionUpgradeItem($func, $version, $aUpgradeFunctions->descriptions[$func], $iPhase, $iPriority);
368 } 373 }
369 } 374 }
370 return $ret; 375 return $ret;
sql/mysql/upgrade/3.5.3/add_autoinc.sql 0 โ†’ 100644
  1 +select @id :=max(id)+1 from plugins;
  2 +update plugins set id = @id where id = 0;
  3 +select @id :=max(id)+1 from upgrades;
  4 +update upgrades set id = @id where id = 0;
  5 +alter table active_sessions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  6 +alter table archive_restoration_request change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  7 +alter table archiving_settings change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  8 +alter table archiving_type_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  9 +alter table authentication_sources change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  10 +alter table column_entries change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  11 +alter table dashlet_disables change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  12 +alter table data_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  13 +alter table discussion_comments change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  14 +alter table discussion_threads change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  15 +alter table document_archiving_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  16 +alter table document_content_version change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  17 +alter table document_fields change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  18 +alter table document_fields_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  19 +alter table document_incomplete change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  20 +alter table document_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  21 +alter table document_link_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  22 +alter table document_metadata_version change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  23 +alter table document_role_allocations change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  24 +alter table document_subscriptions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  25 +alter table document_transaction_types_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  26 +alter table document_transactions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  27 +alter table document_type_fields_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  28 +alter table document_type_fieldsets_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  29 +alter table document_types_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  30 +alter table documents change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  31 +alter table field_behaviours change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  32 +alter table field_value_instances change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  33 +alter table fieldsets change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  34 +alter table folder_doctypes_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  35 +alter table folder_subscriptions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  36 +alter table folder_transactions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  37 +alter table folders change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  38 +alter table folders_users_roles_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  39 +alter table groups_groups_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  40 +alter table groups_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  41 +alter table help change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  42 +alter table help_replacement change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  43 +alter table interceptor_instances change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  44 +alter table links change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  45 +alter table metadata_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  46 +alter table metadata_lookup_tree change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  47 +alter table mime_extractors change `id` `id` mediumint(9) NOT NULL AUTO_INCREMENT;
  48 +alter table mime_documents change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  49 +alter table mime_types change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  50 +alter table news change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  51 +alter table notifications change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  52 +alter table organisations_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  53 +alter table permission_assignments change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  54 +alter table permission_descriptors change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  55 +alter table permission_dynamic_conditions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  56 +alter table permission_lookup_assignments change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  57 +alter table permission_lookups change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  58 +alter table permission_objects change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  59 +alter table permissions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  60 +alter table plugin_helper change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  61 +alter table plugin_rss change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  62 +alter table plugins change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  63 +alter table role_allocations change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  64 +alter table roles change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  65 +alter table saved_searches change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  66 +alter table scheduler_tasks change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  67 +alter table search_saved change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  68 +alter table status_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  69 +alter table system_settings change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  70 +alter table tag_words change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  71 +alter table time_period change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  72 +alter table time_unit_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  73 +alter table units_lookup change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  74 +alter table units_organisations_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  75 +alter table upgrades change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  76 +alter table user_history change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  77 +alter table users change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  78 +alter table users_groups_link change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  79 +alter table workflow_state_permission_assignments change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  80 +alter table workflow_states change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  81 +alter table workflow_transitions change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  82 +alter table workflow_trigger_instances change `id` `id` int (11) NOT NULL AUTO_INCREMENT;
  83 +alter table workflows change `id` `id` int (11) NOT NULL AUTO_INCREMENT;