Commit 9f505333652edfea7e0b3fb8a738db121f3a3257

Authored by Megan Watson
1 parent 769762b2

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/trunk@9083 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-5.sql renamed to sql/mysql/upgrade/3.5.3/add_autoinc.sql