Commit dffad70a585ca3abc465558aeba205c0536324e0
1 parent
d727b7ad
Refactored shared functions into base Step class for upgrades
Committed by: Paul Barrett
Showing
6 changed files
with
68 additions
and
148 deletions
setup/upgrade/lib/UpgradeItems.inc.php
| ... | ... | @@ -122,21 +122,30 @@ class UpgradeItem { |
| 122 | 122 | return $this->type; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - function runDBQuery($query, $checkResult = false, $typeCheck = false) { | |
| 126 | - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path | |
| 127 | - $wizConfigHandler = new configuration(); | |
| 128 | - $configPath = $wizConfigHandler->readConfigPathIni(); | |
| 129 | - if(!isset($this->iniUtilities) || !is_object($this->iniUtilities)) { | |
| 125 | + /** | |
| 126 | + * Runs a DB query and returns a result based on arguments which specify what to look for | |
| 127 | + * | |
| 128 | + * @param string $query The query to run | |
| 129 | + * @param boolean $checkResult Whether to check that a result was found (not needed for update/delete, only select): This result may be empty | |
| 130 | + * @param boolean $resultCheck Whether to check for returned results from the query | |
| 131 | + * @return unknown | |
| 132 | + */ | |
| 133 | + function runDBQuery($query, $checkResult = false, $resultCheck = false) { | |
| 134 | + if(!isset($this->iniUtilities) || !is_object($this->iniUtilities)) { | |
| 130 | 135 | $this->dbUtilities = new dbUtilities(); |
| 131 | 136 | $this->iniUtilities = new iniUtilities(); |
| 132 | 137 | } |
| 138 | + | |
| 139 | + $wizConfigHandler = new configuration(); | |
| 140 | + $configPath = $wizConfigHandler->readConfigPathIni(); | |
| 141 | + | |
| 133 | 142 | $this->iniUtilities->load($configPath); |
| 134 | 143 | $dconf = $this->iniUtilities->getSection('db'); |
| 135 | 144 | $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); |
| 136 | 145 | $result = $this->dbUtilities->query($query); |
| 137 | 146 | if($checkResult) { |
| 138 | 147 | $assArr = $this->dbUtilities->fetchAssoc($result); |
| 139 | - if($typeCheck) { | |
| 148 | + if($resultCheck) { | |
| 140 | 149 | return !is_null($assArr); |
| 141 | 150 | } else { |
| 142 | 151 | return is_null($assArr); |
| ... | ... | @@ -212,9 +221,8 @@ class UpgradeItem { |
| 212 | 221 | function getAllUpgrades() { |
| 213 | 222 | return array(); |
| 214 | 223 | } |
| 215 | - | |
| 216 | 224 | |
| 217 | -} | |
| 225 | +} // end class UpgradeItem | |
| 218 | 226 | |
| 219 | 227 | class SQLUpgradeItem extends UpgradeItem { |
| 220 | 228 | |
| ... | ... | @@ -357,10 +365,10 @@ class SQLUpgradeItem extends UpgradeItem { |
| 357 | 365 | return $this->dbUtilities->runQueries($queries); |
| 358 | 366 | } |
| 359 | 367 | |
| 360 | - | |
| 361 | -} | |
| 368 | +} // end class SQLUpgradeItem | |
| 362 | 369 | |
| 363 | 370 | class KTRebuildPermissionObserver { |
| 371 | + | |
| 364 | 372 | function start() { |
| 365 | 373 | $this->lastBeat = time(); |
| 366 | 374 | } |
| ... | ... | @@ -374,9 +382,11 @@ class KTRebuildPermissionObserver { |
| 374 | 382 | } |
| 375 | 383 | function end() { |
| 376 | 384 | } |
| 385 | + | |
| 377 | 386 | } |
| 378 | 387 | |
| 379 | 388 | class RecordUpgradeItem extends UpgradeItem { |
| 389 | + | |
| 380 | 390 | function RecordUpgradeItem ($version, $oldversion = null) { |
| 381 | 391 | $this->type = "upgrade"; |
| 382 | 392 | if (is_null($oldversion)) { |
| ... | ... | @@ -483,6 +493,7 @@ class RecordUpgradeItem extends UpgradeItem { |
| 483 | 493 | @unlink($sFile); |
| 484 | 494 | } |
| 485 | 495 | } |
| 486 | -} | |
| 496 | + | |
| 497 | +} // end class RecordUpgradeItem | |
| 487 | 498 | |
| 488 | 499 | ?> | ... | ... |
setup/upgrade/step.php
| ... | ... | @@ -39,6 +39,9 @@ |
| 39 | 39 | * @package Upgrader |
| 40 | 40 | * @version Version 0.1 |
| 41 | 41 | */ |
| 42 | + | |
| 43 | +require_once("../wizard/steps/configuration.php"); // configuration to read the ini path | |
| 44 | + | |
| 42 | 45 | class Step |
| 43 | 46 | { |
| 44 | 47 | /** |
| ... | ... | @@ -435,6 +438,44 @@ class Step |
| 435 | 438 | |
| 436 | 439 | return $_SESSION[$package][$class]; |
| 437 | 440 | } |
| 441 | + | |
| 442 | + protected function readConfig() { | |
| 443 | + $wizConfigHandler = new configuration(); | |
| 444 | + $path = $wizConfigHandler->readConfigPathIni(); | |
| 445 | + $this->util->iniUtilities->load($path); | |
| 446 | + $dbSettings = $this->util->iniUtilities->getSection('db'); | |
| 447 | + $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], | |
| 448 | + 'dbName'=> $dbSettings['dbName'], | |
| 449 | + 'dbUser'=> $dbSettings['dbUser'], | |
| 450 | + 'dbPass'=> $dbSettings['dbPass'], | |
| 451 | + 'dbPort'=> $dbSettings['dbPort'], | |
| 452 | + 'dbAdminUser'=> $dbSettings['dbAdminUser'], | |
| 453 | + 'dbAdminPass'=> $dbSettings['dbAdminPass'], | |
| 454 | + ); | |
| 455 | + $this->paths = $this->util->iniUtilities->getSection('urls'); | |
| 456 | + $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); | |
| 457 | + $this->sysVersion = $this->readVersion(); | |
| 458 | + $this->cachePath = $wizConfigHandler->readCachePath(); | |
| 459 | + $this->proxyPath = $this->cachePath."/.."; // Total guess. | |
| 460 | + $this->proxyPath = realpath($this->proxyPath."/proxies"); | |
| 461 | + $this->storeSilent(); | |
| 462 | + } | |
| 463 | + | |
| 464 | + protected function readVersion() { | |
| 465 | + $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; | |
| 466 | + if(file_exists($verFile)) { | |
| 467 | + $foundVersion = file_get_contents($verFile); | |
| 468 | + return $foundVersion; | |
| 469 | + } else { | |
| 470 | + $this->error[] = "KT installation version not found"; | |
| 471 | + } | |
| 472 | + | |
| 473 | + return false; | |
| 474 | + } | |
| 475 | + | |
| 476 | + protected function storeSilent() { | |
| 477 | + | |
| 478 | + } | |
| 438 | 479 | } |
| 439 | 480 | |
| 440 | 481 | ?> |
| 441 | 482 | \ No newline at end of file | ... | ... |
setup/upgrade/steps/upgradeBackup.php
| ... | ... | @@ -245,43 +245,6 @@ class upgradeBackup extends Step { |
| 245 | 245 | $this->temp_variables['dir'] = $dir; |
| 246 | 246 | $this->temp_variables['display'] = $stmt['display']; |
| 247 | 247 | } |
| 248 | - | |
| 249 | - // TODO this function needs to be refactored out into the parent Step class?? | |
| 250 | - private function readConfig() { | |
| 251 | - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path | |
| 252 | - $wizConfigHandler = new configuration(); | |
| 253 | - $path = $wizConfigHandler->readConfigPathIni(); | |
| 254 | - $this->util->iniUtilities->load($path); | |
| 255 | - $dbSettings = $this->util->iniUtilities->getSection('db'); | |
| 256 | - | |
| 257 | - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], | |
| 258 | - 'dbName'=> $dbSettings['dbName'], | |
| 259 | - 'dbUser'=> $dbSettings['dbUser'], | |
| 260 | - 'dbPass'=> $dbSettings['dbPass'], | |
| 261 | - 'dbPort'=> $dbSettings['dbPort'], | |
| 262 | - // dbSocket doesn't exist as far as I can find, where was it coming from? | |
| 263 | - //'dbSocket'=> $dbSettings['dbSocket'], | |
| 264 | - 'dbAdminUser'=> $dbSettings['dbAdminUser'], | |
| 265 | - 'dbAdminPass'=> $dbSettings['dbAdminPass'], | |
| 266 | - ); | |
| 267 | - $this->paths = $this->util->iniUtilities->getSection('urls'); | |
| 268 | - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); | |
| 269 | - $this->temp_variables['dbSettings'] = $this->dbSettings; | |
| 270 | - $this->sysVersion = $this->readVersion(); | |
| 271 | - $this->cachePath = $wizConfigHandler->readCachePath(); | |
| 272 | - } | |
| 273 | - | |
| 274 | - // TODO this function needs to be refactored out into the parent Step class | |
| 275 | - public function readVersion() { | |
| 276 | - $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; | |
| 277 | - if(file_exists($verFile)) { | |
| 278 | - $foundVersion = file_get_contents($verFile); | |
| 279 | - return $foundVersion; | |
| 280 | - } else { | |
| 281 | - $this->error[] = "KT installation version not found"; | |
| 282 | - } | |
| 283 | 248 | |
| 284 | - return false; | |
| 285 | - } | |
| 286 | 249 | } |
| 287 | 250 | ?> |
| 288 | 251 | \ No newline at end of file | ... | ... |
setup/upgrade/steps/upgradeComplete.php
| ... | ... | @@ -61,7 +61,7 @@ class upgradeComplete extends Step { |
| 61 | 61 | * Set all silent mode varibles |
| 62 | 62 | * |
| 63 | 63 | */ |
| 64 | - private function storeSilent() { | |
| 64 | + protected function storeSilent() { | |
| 65 | 65 | $v = $this->getDataFromSession('upgradeProperties'); |
| 66 | 66 | $this->temp_variables['sysVersion'] = $v['upgrade_version']; |
| 67 | 67 | } | ... | ... |
setup/upgrade/steps/upgradeDatabase.php
| ... | ... | @@ -65,15 +65,6 @@ class upgradeDatabase extends Step |
| 65 | 65 | private $dbBinary = ''; // TODO:multiple databases |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * List of errors encountered | |
| 69 | - * | |
| 70 | - * @author KnowledgeTree Team | |
| 71 | - * @access public | |
| 72 | - * @var array | |
| 73 | - */ | |
| 74 | - public $error = array(); | |
| 75 | - | |
| 76 | - /** | |
| 77 | 68 | * List of errors used in template |
| 78 | 69 | * |
| 79 | 70 | * @author KnowledgeTree Team |
| ... | ... | @@ -143,8 +134,10 @@ class upgradeDatabase extends Step |
| 143 | 134 | |
| 144 | 135 | private function doRun($action = null) { |
| 145 | 136 | $this->readConfig(); |
| 137 | + | |
| 146 | 138 | $con = $this->util->dbUtilities->load($this->dbSettings['dbHost'], $this->dbSettings['dbPort'], $this->dbSettings['dbUser'],$this->dbSettings['dbPass'], $this->dbSettings['dbName']); |
| 147 | 139 | $this->temp_variables['action'] = $action; |
| 140 | + | |
| 148 | 141 | if (is_null($action) || ($action == 'preview')) { |
| 149 | 142 | $this->temp_variables['title'] = 'Preview Upgrade'; |
| 150 | 143 | $this->temp_variables['upgradeTable'] = $this->generateUpgradeTable(); |
| ... | ... | @@ -206,31 +199,6 @@ class upgradeDatabase extends Step |
| 206 | 199 | |
| 207 | 200 | return false; |
| 208 | 201 | } |
| 209 | - | |
| 210 | - /** | |
| 211 | - * Stores varibles used by template | |
| 212 | - * | |
| 213 | - * @author KnowledgeTree Team | |
| 214 | - * @params none | |
| 215 | - * @access public | |
| 216 | - * @return array | |
| 217 | - */ | |
| 218 | - public function getStepVars() { | |
| 219 | - return $this->temp_variables; | |
| 220 | - } | |
| 221 | - | |
| 222 | - /** | |
| 223 | - * Returns database errors | |
| 224 | - * | |
| 225 | - * @author KnowledgeTree Team | |
| 226 | - * @access public | |
| 227 | - * @params none | |
| 228 | - * @return array | |
| 229 | - */ | |
| 230 | - public function getErrors() { | |
| 231 | - | |
| 232 | - return $this->error; | |
| 233 | - } | |
| 234 | 202 | |
| 235 | 203 | /** |
| 236 | 204 | * Initialize errors to false |
| ... | ... | @@ -246,29 +214,6 @@ class upgradeDatabase extends Step |
| 246 | 214 | } |
| 247 | 215 | } |
| 248 | 216 | |
| 249 | - private function readConfig() { | |
| 250 | - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path | |
| 251 | - $wizConfigHandler = new configuration(); | |
| 252 | - $path = $wizConfigHandler->readConfigPathIni(); | |
| 253 | - $this->util->iniUtilities->load($path); | |
| 254 | - $dbSettings = $this->util->iniUtilities->getSection('db'); | |
| 255 | - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], | |
| 256 | - 'dbName'=> $dbSettings['dbName'], | |
| 257 | - 'dbUser'=> $dbSettings['dbUser'], | |
| 258 | - 'dbPass'=> $dbSettings['dbPass'], | |
| 259 | - 'dbPort'=> $dbSettings['dbPort'], | |
| 260 | - 'dbAdminUser'=> $dbSettings['dbAdminUser'], | |
| 261 | - 'dbAdminPass'=> $dbSettings['dbAdminPass'], | |
| 262 | - ); | |
| 263 | - $this->paths = $this->util->iniUtilities->getSection('urls'); | |
| 264 | - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); | |
| 265 | - $this->sysVersion = $this->readVersion(); | |
| 266 | - $this->cachePath = $wizConfigHandler->readCachePath(); | |
| 267 | - $this->proxyPath = $this->cachePath."/.."; // Total guess. | |
| 268 | - $this->proxyPath = realpath($this->proxyPath."/proxies"); | |
| 269 | - $this->storeSilent(); | |
| 270 | - } | |
| 271 | - | |
| 272 | 217 | public function storeSilent() { |
| 273 | 218 | $this->temp_variables['paths'] = $this->paths; |
| 274 | 219 | $this->temp_variables['sysVersion'] = $this->sysVersion; |
| ... | ... | @@ -416,10 +361,8 @@ class upgradeDatabase extends Step |
| 416 | 361 | } |
| 417 | 362 | |
| 418 | 363 | private function showResult($res) { |
| 419 | - if ($res) { | |
| 420 | - if (is_a($res, 'Upgrade_Already_Applied')) { | |
| 421 | - return '<span style="color: orange">Already applied</span>'; | |
| 422 | - } | |
| 364 | + if ($res && is_a($res, 'Upgrade_Already_Applied')) { | |
| 365 | + return '<span style="color: orange">Already applied</span>'; | |
| 423 | 366 | } |
| 424 | 367 | if ($res === true) { |
| 425 | 368 | return '<span style="color: green">Success</span>'; | ... | ... |
setup/upgrade/steps/upgradeRestore.php
| ... | ... | @@ -221,43 +221,5 @@ class upgradeRestore extends Step { |
| 221 | 221 | $this->temp_variables['selected'] = true; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - // TODO this function needs to be refactored out into the parent Step class?? | |
| 225 | - private function readConfig() { | |
| 226 | - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path | |
| 227 | - $wizConfigHandler = new configuration(); | |
| 228 | - $path = $wizConfigHandler->readConfigPathIni(); | |
| 229 | - $this->util->iniUtilities->load($path); | |
| 230 | - $dbSettings = $this->util->iniUtilities->getSection('db'); | |
| 231 | - | |
| 232 | - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], | |
| 233 | - 'dbName'=> $dbSettings['dbName'], | |
| 234 | - 'dbUser'=> $dbSettings['dbUser'], | |
| 235 | - 'dbPass'=> $dbSettings['dbPass'], | |
| 236 | - 'dbPort'=> $dbSettings['dbPort'], | |
| 237 | - // dbSocket doesn't exist as far as I can find, where was it coming from? | |
| 238 | - //'dbSocket'=> $dbSettings['dbSocket'], | |
| 239 | - 'dbAdminUser'=> $dbSettings['dbAdminUser'], | |
| 240 | - 'dbAdminPass'=> $dbSettings['dbAdminPass'], | |
| 241 | - ); | |
| 242 | - $this->paths = $this->util->iniUtilities->getSection('urls'); | |
| 243 | - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); | |
| 244 | - $this->temp_variables['dbSettings'] = $this->dbSettings; | |
| 245 | - $this->sysVersion = $this->readVersion(); | |
| 246 | - $this->cachePath = $wizConfigHandler->readCachePath(); | |
| 247 | - } | |
| 248 | - | |
| 249 | - // TODO this function needs to be refactored out into the parent Step class | |
| 250 | - public function readVersion() { | |
| 251 | - $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; | |
| 252 | - if(file_exists($verFile)) { | |
| 253 | - $foundVersion = file_get_contents($verFile); | |
| 254 | - return $foundVersion; | |
| 255 | - } else { | |
| 256 | - $this->error[] = "KT installation version not found"; | |
| 257 | - } | |
| 258 | - | |
| 259 | - return false; | |
| 260 | - } | |
| 261 | - | |
| 262 | 224 | } |
| 263 | 225 | ?> |
| 264 | 226 | \ No newline at end of file | ... | ... |