Commit 0f6be16364c1e3c93502609ce906d8762f76e57d

Authored by kevin_fourie
1 parent b9b23d86

Merged in from STABLE trunk...

KTS-3604
"Upgrade failed from 3.5.2c to 3.5.3."
Fixed. Added auto increment for mediumint id's

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@9153 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/upgrades/UpgradeFunctions.inc.php
... ... @@ -150,7 +150,6 @@ class UpgradeFunctions {
150 150 continue;
151 151 }
152 152  
153   -
154 153 $doneTables[] = $tableName;
155 154  
156 155 if(strpos($tableName, 'zseq_', 0) !== false){
... ... @@ -161,22 +160,27 @@ class UpgradeFunctions {
161 160 $query = "SELECT max(id) FROM {$tableName}";
162 161 $aId = DBUtil::getOneResult($query);
163 162  
164   - if(PEAR::isError($aId)){
165   - // Means that the table doesn't have an id column
166   - continue;
167   - }
168   -
169 163 // If there's no result, then the table may be empty
170   - if(!empty($aId)){
  164 + if(!PEAR::isError($aId)){
171 165 $id = (int)$aId['max(id)'] + 1;
172 166  
173 167 $query = "UPDATE {$tableName} SET id = {$id} WHERE id = 0";
174 168 $res = DBUtil::runQuery($query, $db);
  169 + }else{
  170 + $default->log->error('Add auto_increment, fail on get max id: '.$aId->getMessage());
175 171 }
176 172  
177 173 // Update the table, set id to auto_increment
178 174 $query = "ALTER TABLE {$tableName} CHANGE `id` `id` int (11) NOT NULL AUTO_INCREMENT";
179 175 $res = DBUtil::runQuery($query, $db);
  176 +
  177 + if(PEAR::isError($res)){
  178 + $default->log->error('Add auto_increment, fail on change id to auto_increment: '.$res->getMessage());
  179 +
  180 + // try again with mediumint
  181 + $query = "ALTER TABLE {$tableName} CHANGE `id` `id` mediumint (9) NOT NULL AUTO_INCREMENT";
  182 + $res = DBUtil::runQuery($query, $db);
  183 + }
180 184 }
181 185 }
182 186  
... ...