Commit af421b4714e7e61a37d232aca82e33fa09b97e8d
1 parent
17eacfeb
Added errors to the display. Changed the DB user to use the admin user. Recreate…
…d the cache directory after upgrade. PT: 1782058 Committed by: Megan Watson
Showing
2 changed files
with
83 additions
and
62 deletions
setup/upgrade/lib/UpgradeItems.inc.php
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| ... | ... | @@ -57,16 +57,16 @@ require_once("../wizard/dbUtilities.php"); |
| 57 | 57 | |
| 58 | 58 | // {{{ Upgrade_Already_Applied |
| 59 | 59 | class Upgrade_Already_Applied { |
| 60 | - | |
| 60 | + | |
| 61 | 61 | function Upgrade_Already_Applied($oUpgradeItem) { |
| 62 | 62 | $this->oUpgradeItem = $oUpgradeItem; |
| 63 | 63 | } |
| 64 | - | |
| 64 | + | |
| 65 | 65 | } |
| 66 | 66 | // }}} |
| 67 | 67 | |
| 68 | 68 | class UpgradeItem { |
| 69 | - | |
| 69 | + | |
| 70 | 70 | public $type = ""; |
| 71 | 71 | public $name; |
| 72 | 72 | public $version; |
| ... | ... | @@ -76,7 +76,8 @@ class UpgradeItem { |
| 76 | 76 | public $parent; |
| 77 | 77 | public $date; |
| 78 | 78 | public $result; |
| 79 | - | |
| 79 | + protected $error; | |
| 80 | + | |
| 80 | 81 | function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) { |
| 81 | 82 | $this->name = $name; |
| 82 | 83 | $this->version = $version; |
| ... | ... | @@ -86,7 +87,7 @@ class UpgradeItem { |
| 86 | 87 | $this->description = $description; |
| 87 | 88 | $this->phase = $phase; |
| 88 | 89 | $this->priority = $priority; |
| 89 | - | |
| 90 | + | |
| 90 | 91 | $this->dbUtilities = new dbUtilities(); |
| 91 | 92 | $this->iniUtilities = new iniUtilities(); |
| 92 | 93 | } |
| ... | ... | @@ -122,6 +123,14 @@ class UpgradeItem { |
| 122 | 123 | return $this->type; |
| 123 | 124 | } |
| 124 | 125 | |
| 126 | + public function getErrors() | |
| 127 | + { | |
| 128 | + if(isset($this->error[0])){ | |
| 129 | + return $this->error[0]; | |
| 130 | + } | |
| 131 | + return $this->error; | |
| 132 | + } | |
| 133 | + | |
| 125 | 134 | /** |
| 126 | 135 | * Runs a DB query and returns a result based on arguments which specify what to look for |
| 127 | 136 | * |
| ... | ... | @@ -135,13 +144,13 @@ class UpgradeItem { |
| 135 | 144 | $this->dbUtilities = new dbUtilities(); |
| 136 | 145 | $this->iniUtilities = new iniUtilities(); |
| 137 | 146 | } |
| 138 | - | |
| 147 | + | |
| 139 | 148 | $wizConfigHandler = new configuration(); |
| 140 | 149 | $configPath = $wizConfigHandler->readConfigPathIni(); |
| 141 | - | |
| 150 | + | |
| 142 | 151 | $this->iniUtilities->load($configPath); |
| 143 | 152 | $dconf = $this->iniUtilities->getSection('db'); |
| 144 | - $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); | |
| 153 | + $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbAdminUser'], $dconf['dbAdminPass'], $dconf['dbName']); | |
| 145 | 154 | $result = $this->dbUtilities->query($query); |
| 146 | 155 | if($checkResult) { |
| 147 | 156 | $assArr = $this->dbUtilities->fetchAssoc($result); |
| ... | ... | @@ -153,7 +162,7 @@ class UpgradeItem { |
| 153 | 162 | } |
| 154 | 163 | return !is_null($result); |
| 155 | 164 | } |
| 156 | - | |
| 165 | + | |
| 157 | 166 | function _upgradeTableInstalled() { |
| 158 | 167 | $query = "SELECT COUNT(id) FROM upgrades"; |
| 159 | 168 | $res = $this->runDBQuery($query, true, true); |
| ... | ... | @@ -169,7 +178,7 @@ class UpgradeItem { |
| 169 | 178 | } |
| 170 | 179 | $query = "SELECT id FROM upgrades WHERE descriptor = '".$this->getDescriptor()."' AND result = 1"; |
| 171 | 180 | $res = $this->runDBQuery($query, true, false); |
| 172 | - | |
| 181 | + | |
| 173 | 182 | if(!$res) { |
| 174 | 183 | return true; |
| 175 | 184 | } |
| ... | ... | @@ -214,7 +223,7 @@ class UpgradeItem { |
| 214 | 223 | } |
| 215 | 224 | $sql = "INSERT INTO upgrades (`id`, `descriptor`, `description`, `date_performed`, `result`, `parent`) VALUES (NULL, '". $this->getDescriptor()."', '".$this->description."', '".$this->date."', '".$result."', '".$parentid."')"; |
| 216 | 225 | $this->dbUtilities->query($sql); |
| 217 | - | |
| 226 | + | |
| 218 | 227 | return true; |
| 219 | 228 | } |
| 220 | 229 | |
| ... | ... | @@ -225,7 +234,7 @@ class UpgradeItem { |
| 225 | 234 | } // end class UpgradeItem |
| 226 | 235 | |
| 227 | 236 | class SQLUpgradeItem extends UpgradeItem { |
| 228 | - | |
| 237 | + | |
| 229 | 238 | function SQLUpgradeItem($path, $version = null, $description = null, $phase = null, $priority = null) { |
| 230 | 239 | $this->type = "sql"; |
| 231 | 240 | $this->priority = 0; |
| ... | ... | @@ -366,11 +375,11 @@ class SQLUpgradeItem extends UpgradeItem { |
| 366 | 375 | $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); |
| 367 | 376 | return $this->dbUtilities->runQueries($queries); |
| 368 | 377 | } |
| 369 | - | |
| 378 | + | |
| 370 | 379 | } // end class SQLUpgradeItem |
| 371 | 380 | |
| 372 | 381 | class KTRebuildPermissionObserver { |
| 373 | - | |
| 382 | + | |
| 374 | 383 | function start() { |
| 375 | 384 | $this->lastBeat = time(); |
| 376 | 385 | } |
| ... | ... | @@ -384,11 +393,11 @@ class KTRebuildPermissionObserver { |
| 384 | 393 | } |
| 385 | 394 | function end() { |
| 386 | 395 | } |
| 387 | - | |
| 396 | + | |
| 388 | 397 | } |
| 389 | 398 | |
| 390 | 399 | class RecordUpgradeItem extends UpgradeItem { |
| 391 | - | |
| 400 | + | |
| 392 | 401 | function RecordUpgradeItem ($version, $oldversion = null) { |
| 393 | 402 | $this->type = "upgrade"; |
| 394 | 403 | if (is_null($oldversion)) { |
| ... | ... | @@ -426,7 +435,7 @@ class RecordUpgradeItem extends UpgradeItem { |
| 426 | 435 | KTPermissionUtil::rebuildPermissionLookups(true); |
| 427 | 436 | $po->end(); |
| 428 | 437 | */ |
| 429 | - | |
| 438 | + | |
| 430 | 439 | $versionFile=KT_DIR . '/docs/VERSION-NAME.txt'; |
| 431 | 440 | $fp = fopen($versionFile,'rt'); |
| 432 | 441 | $systemVersion = fread($fp, filesize($versionFile)); |
| ... | ... | @@ -495,7 +504,7 @@ class RecordUpgradeItem extends UpgradeItem { |
| 495 | 504 | @unlink($sFile); |
| 496 | 505 | } |
| 497 | 506 | } |
| 498 | - | |
| 507 | + | |
| 499 | 508 | } // end class RecordUpgradeItem |
| 500 | 509 | |
| 501 | 510 | ?> | ... | ... |
setup/upgrade/steps/upgradeDatabase.php
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | -* Upgrade Step Controller. | |
| 3 | +* Upgrade Step Controller. | |
| 4 | 4 | * |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| ... | ... | @@ -44,7 +44,7 @@ define('KT_DIR', SYSTEM_DIR); |
| 44 | 44 | define('KT_LIB_DIR', SYSTEM_DIR.'lib'); |
| 45 | 45 | require_once(WIZARD_LIB . 'upgrade.inc.php'); |
| 46 | 46 | |
| 47 | -class upgradeDatabase extends Step | |
| 47 | +class upgradeDatabase extends Step | |
| 48 | 48 | { |
| 49 | 49 | /** |
| 50 | 50 | * Location of database binaries. |
| ... | ... | @@ -54,7 +54,7 @@ class upgradeDatabase extends Step |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | 56 | private $mysqlDir; // TODO:multiple databases |
| 57 | - | |
| 57 | + | |
| 58 | 58 | /** |
| 59 | 59 | * Name of database binary. |
| 60 | 60 | * |
| ... | ... | @@ -63,7 +63,7 @@ class upgradeDatabase extends Step |
| 63 | 63 | * @var string |
| 64 | 64 | */ |
| 65 | 65 | private $dbBinary = ''; // TODO:multiple databases |
| 66 | - | |
| 66 | + | |
| 67 | 67 | /** |
| 68 | 68 | * List of errors used in template |
| 69 | 69 | * |
| ... | ... | @@ -72,7 +72,7 @@ class upgradeDatabase extends Step |
| 72 | 72 | * @var array |
| 73 | 73 | */ |
| 74 | 74 | public $templateErrors = array('dmspassword', 'dmsuserpassword', 'con', 'dname', 'dtype', 'duname', 'dpassword'); |
| 75 | - | |
| 75 | + | |
| 76 | 76 | /** |
| 77 | 77 | * Flag to store class information in session |
| 78 | 78 | * |
| ... | ... | @@ -81,7 +81,7 @@ class upgradeDatabase extends Step |
| 81 | 81 | * @var array |
| 82 | 82 | */ |
| 83 | 83 | public $storeInSession = true; |
| 84 | - | |
| 84 | + | |
| 85 | 85 | public $sysVersion = ''; |
| 86 | 86 | protected $silent = false; |
| 87 | 87 | protected $temp_variables = array(); |
| ... | ... | @@ -96,7 +96,7 @@ class upgradeDatabase extends Step |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | 98 | public function doStep() { |
| 99 | - $this->temp_variables = array("step_name"=>"database", "silent"=>$this->silent, | |
| 99 | + $this->temp_variables = array("step_name"=>"database", "silent"=>$this->silent, | |
| 100 | 100 | "loadingText"=>"The database upgrade is under way. Please wait until it completes"); |
| 101 | 101 | $this->initErrors(); |
| 102 | 102 | if(!$this->inStep("database")) { |
| ... | ... | @@ -119,25 +119,25 @@ class upgradeDatabase extends Step |
| 119 | 119 | } |
| 120 | 120 | return 'error'; |
| 121 | 121 | } |
| 122 | - | |
| 122 | + | |
| 123 | 123 | $this->doRun(); |
| 124 | 124 | return 'landing'; |
| 125 | 125 | } |
| 126 | - | |
| 126 | + | |
| 127 | 127 | private function confirmUpgrade() { |
| 128 | 128 | return isset($_POST['ConfirmUpgrade']); |
| 129 | 129 | } |
| 130 | - | |
| 130 | + | |
| 131 | 131 | private function upgrading() { |
| 132 | 132 | return isset($_POST['RunUpgrade']); |
| 133 | - } | |
| 134 | - | |
| 133 | + } | |
| 134 | + | |
| 135 | 135 | private function doRun($action = null) { |
| 136 | 136 | $this->readConfig(); |
| 137 | - | |
| 137 | + | |
| 138 | 138 | $this->util->dbUtilities->load($this->dbSettings['dbHost'], $this->dbSettings['dbPort'], $this->dbSettings['dbUser'],$this->dbSettings['dbPass'], $this->dbSettings['dbName']); |
| 139 | 139 | $this->temp_variables['action'] = $action; |
| 140 | - | |
| 140 | + | |
| 141 | 141 | if (is_null($action) || ($action == 'preview')) { |
| 142 | 142 | $this->temp_variables['title'] = 'Preview Upgrade'; |
| 143 | 143 | $this->temp_variables['upgradeTable'] = $this->generateUpgradeTable(); |
| ... | ... | @@ -154,10 +154,10 @@ class upgradeDatabase extends Step |
| 154 | 154 | } |
| 155 | 155 | $this->temp_variables['backupSuccessful'] = true; |
| 156 | 156 | } |
| 157 | - | |
| 157 | + | |
| 158 | 158 | return true; |
| 159 | 159 | } |
| 160 | - | |
| 160 | + | |
| 161 | 161 | private function generateUpgradeTable() { |
| 162 | 162 | $this->sysVersion = $this->readVersion(); |
| 163 | 163 | $this->temp_variables['systemVersion'] = $this->sysVersion; |
| ... | ... | @@ -197,7 +197,7 @@ class upgradeDatabase extends Step |
| 197 | 197 | $this->error[] = "KT installation version not found"; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - return false; | |
| 200 | + return false; | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
| ... | ... | @@ -213,14 +213,14 @@ class upgradeDatabase extends Step |
| 213 | 213 | $this->error[$e] = false; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | - | |
| 216 | + | |
| 217 | 217 | public function storeSilent() { |
| 218 | 218 | $this->temp_variables['paths'] = $this->paths; |
| 219 | 219 | $this->temp_variables['sysVersion'] = $this->sysVersion; |
| 220 | 220 | $this->temp_variables['sysVersion'] = $this->sysVersion; |
| 221 | 221 | $this->temp_variables['dbSettings'] = $this->dbSettings; |
| 222 | 222 | } |
| 223 | - | |
| 223 | + | |
| 224 | 224 | private function upgradeConfirm() |
| 225 | 225 | { |
| 226 | 226 | if (!isset($_SESSION['backupStatus']) || $_SESSION['backupStatus'] === false) { |
| ... | ... | @@ -234,12 +234,12 @@ class upgradeDatabase extends Step |
| 234 | 234 | private function doDatabaseUpgrade() |
| 235 | 235 | { |
| 236 | 236 | $errors = false; |
| 237 | - | |
| 237 | + | |
| 238 | 238 | $this->temp_variables['detail'] = '<p>The table below describes the upgrades that have occurred to |
| 239 | 239 | upgrade your KnowledgeTree installation to <strong>' . $this->sysVersion . '</strong>'; |
| 240 | - | |
| 240 | + | |
| 241 | 241 | $this->performPreUpgradeActions(); |
| 242 | - | |
| 242 | + | |
| 243 | 243 | $res = $this->performAllUpgrades(); |
| 244 | 244 | if (!$res) { |
| 245 | 245 | $errors = true; |
| ... | ... | @@ -247,7 +247,7 @@ class upgradeDatabase extends Step |
| 247 | 247 | // TODO instantiate error details hideable section? |
| 248 | 248 | $this->temp_variables['upgradeStatus'] = '<font color="red">Database upgrade failed</font> |
| 249 | 249 | <br/><br/> |
| 250 | - Please restore from your backup and ensure that the database does not contain | |
| 250 | + Please restore from your backup and ensure that the database does not contain | |
| 251 | 251 | any unsupported modifications and try the upgrade process again. |
| 252 | 252 | <br/><br/> |
| 253 | 253 | If the problem persists, contact KnowledgeTree Support.'; |
| ... | ... | @@ -255,27 +255,27 @@ class upgradeDatabase extends Step |
| 255 | 255 | else { |
| 256 | 256 | $this->temp_variables['upgradeStatus'] = '<font color="green">Upgrade succeeded.</font>'; |
| 257 | 257 | } |
| 258 | - | |
| 258 | + | |
| 259 | 259 | $this->performPostUpgradeActions(); |
| 260 | - | |
| 261 | - | |
| 260 | + | |
| 261 | + | |
| 262 | 262 | return !$errors; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | private function performPreUpgradeActions() { |
| 266 | - | |
| 266 | + | |
| 267 | 267 | // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works. |
| 268 | 268 | // It should idealy work the same as the upgrades. |
| 269 | 269 | // Lock the scheduler |
| 270 | 270 | $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock'; |
| 271 | 271 | touch($lockFile); |
| 272 | 272 | return true; |
| 273 | - | |
| 273 | + | |
| 274 | 274 | } |
| 275 | - | |
| 275 | + | |
| 276 | 276 | private function deleteDirectory($sPath) { |
| 277 | 277 | if (empty($sPath) || !is_dir($sPath)) return; |
| 278 | - | |
| 278 | + | |
| 279 | 279 | if (!WINDOWS_OS) { |
| 280 | 280 | if (file_exists('/bin/rm')) { |
| 281 | 281 | $this->util->pexec(array('/bin/rm', '-rf', $sPath)); |
| ... | ... | @@ -303,28 +303,31 @@ class upgradeDatabase extends Step |
| 303 | 303 | closedir($hPath); |
| 304 | 304 | rmdir($sPath); |
| 305 | 305 | } |
| 306 | - | |
| 306 | + | |
| 307 | 307 | private function performPostUpgradeActions() { |
| 308 | - | |
| 308 | + | |
| 309 | 309 | // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works. |
| 310 | 310 | // It should idealy work the same as the upgrades. |
| 311 | - | |
| 311 | + | |
| 312 | 312 | // Ensure all plugins are re-registered. |
| 313 | 313 | $sql = "TRUNCATE plugin_helper"; |
| 314 | 314 | $this->util->dbUtilities->query($sql); |
| 315 | - | |
| 315 | + | |
| 316 | 316 | // Clear out all caches and proxies - they need to be regenerated with the new code |
| 317 | 317 | $this->deleteDirectory($this->proxyPath); |
| 318 | 318 | $this->deleteDirectory($this->cachePath); |
| 319 | - | |
| 319 | + | |
| 320 | + // Recreate the cache directory - it doesn't get regenerated | |
| 321 | + mkdir($this->cachePath, 0755); | |
| 322 | + | |
| 320 | 323 | // Unlock the scheduler |
| 321 | 324 | $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock'; |
| 322 | 325 | if(file_exists($lockFile)){ |
| 323 | 326 | unlink($lockFile); |
| 324 | 327 | } |
| 325 | - | |
| 328 | + | |
| 326 | 329 | return true; |
| 327 | - | |
| 330 | + | |
| 328 | 331 | } |
| 329 | 332 | |
| 330 | 333 | private function performAllUpgrades () { |
| ... | ... | @@ -343,11 +346,12 @@ class upgradeDatabase extends Step |
| 343 | 346 | } else { |
| 344 | 347 | $class = "even"; |
| 345 | 348 | } |
| 346 | - $this->temp_variables['upgradeTable'] .= sprintf('<div class="row %s"><div class="foo">%s</div>' . "\n", $class, | |
| 349 | + $this->temp_variables['upgradeTable'] .= sprintf('<div class="row %s"><div class="foo">%s</div>' . "\n", $class, | |
| 347 | 350 | htmlspecialchars($upgrade->getDescription())); |
| 348 | 351 | ++$row; |
| 349 | 352 | $res = $upgrade->performUpgrade(); |
| 350 | - $this->temp_variables['upgradeTable'] .= sprintf('<div class="bar">%s</div>', $this->showResult($res)); | |
| 353 | + $errors = $upgrade->getErrors(); | |
| 354 | + $this->temp_variables['upgradeTable'] .= sprintf('<div class="bar">%s</div>', $this->showResult($res, $errors)); | |
| 351 | 355 | $this->temp_variables['upgradeTable'] .= '<br>' . "\n"; |
| 352 | 356 | $this->temp_variables['upgradeTable'] .= "</div>\n"; |
| 353 | 357 | if ($res === false) { |
| ... | ... | @@ -355,11 +359,11 @@ class upgradeDatabase extends Step |
| 355 | 359 | break; |
| 356 | 360 | } |
| 357 | 361 | } |
| 358 | - | |
| 362 | + | |
| 359 | 363 | return $res; |
| 360 | 364 | } |
| 361 | - | |
| 362 | - private function showResult($res) { | |
| 365 | + | |
| 366 | + private function showResult($res, $errors = null) { | |
| 363 | 367 | if ($res && is_a($res, 'Upgrade_Already_Applied')) { |
| 364 | 368 | return '<span style="color: orange">Already applied</span>'; |
| 365 | 369 | } |
| ... | ... | @@ -367,7 +371,15 @@ class upgradeDatabase extends Step |
| 367 | 371 | return '<span style="color: green">Success</span>'; |
| 368 | 372 | } |
| 369 | 373 | if ($res === false) { |
| 370 | - return '<span style="color: red">Failure</span>'; | |
| 374 | + $str = '<span style="color: red">Failure</span>'; | |
| 375 | + if(is_array($errors)){ | |
| 376 | + $str .= '<ul style="padding-left: 20px; color: red;">'; | |
| 377 | + foreach ($errors as $error){ | |
| 378 | + $str .= '<li style="padding: 5px 2px 0;">'.$error."</li>\n"; | |
| 379 | + } | |
| 380 | + $str .= '</ul>'; | |
| 381 | + } | |
| 382 | + return $str; | |
| 371 | 383 | } |
| 372 | 384 | return $res; |
| 373 | 385 | } | ... | ... |