diff --git a/setup/upgrade/lib/UpgradeItems.inc.php b/setup/upgrade/lib/UpgradeItems.inc.php index d92880b..561401c 100644 --- a/setup/upgrade/lib/UpgradeItems.inc.php +++ b/setup/upgrade/lib/UpgradeItems.inc.php @@ -122,21 +122,30 @@ class UpgradeItem { return $this->type; } - function runDBQuery($query, $checkResult = false, $typeCheck = false) { - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path - $wizConfigHandler = new configuration(); - $configPath = $wizConfigHandler->readConfigPathIni(); - if(!isset($this->iniUtilities) || !is_object($this->iniUtilities)) { + /** + * Runs a DB query and returns a result based on arguments which specify what to look for + * + * @param string $query The query to run + * @param boolean $checkResult Whether to check that a result was found (not needed for update/delete, only select): This result may be empty + * @param boolean $resultCheck Whether to check for returned results from the query + * @return unknown + */ + function runDBQuery($query, $checkResult = false, $resultCheck = false) { + if(!isset($this->iniUtilities) || !is_object($this->iniUtilities)) { $this->dbUtilities = new dbUtilities(); $this->iniUtilities = new iniUtilities(); } + + $wizConfigHandler = new configuration(); + $configPath = $wizConfigHandler->readConfigPathIni(); + $this->iniUtilities->load($configPath); $dconf = $this->iniUtilities->getSection('db'); $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); $result = $this->dbUtilities->query($query); if($checkResult) { $assArr = $this->dbUtilities->fetchAssoc($result); - if($typeCheck) { + if($resultCheck) { return !is_null($assArr); } else { return is_null($assArr); @@ -212,9 +221,8 @@ class UpgradeItem { function getAllUpgrades() { return array(); } - -} +} // end class UpgradeItem class SQLUpgradeItem extends UpgradeItem { @@ -357,10 +365,10 @@ class SQLUpgradeItem extends UpgradeItem { return $this->dbUtilities->runQueries($queries); } - -} +} // end class SQLUpgradeItem class KTRebuildPermissionObserver { + function start() { $this->lastBeat = time(); } @@ -374,9 +382,11 @@ class KTRebuildPermissionObserver { } function end() { } + } class RecordUpgradeItem extends UpgradeItem { + function RecordUpgradeItem ($version, $oldversion = null) { $this->type = "upgrade"; if (is_null($oldversion)) { @@ -483,6 +493,7 @@ class RecordUpgradeItem extends UpgradeItem { @unlink($sFile); } } -} + +} // end class RecordUpgradeItem ?> diff --git a/setup/upgrade/step.php b/setup/upgrade/step.php index 2cf5254..355fabe 100644 --- a/setup/upgrade/step.php +++ b/setup/upgrade/step.php @@ -39,6 +39,9 @@ * @package Upgrader * @version Version 0.1 */ + +require_once("../wizard/steps/configuration.php"); // configuration to read the ini path + class Step { /** @@ -435,6 +438,44 @@ class Step return $_SESSION[$package][$class]; } + + protected function readConfig() { + $wizConfigHandler = new configuration(); + $path = $wizConfigHandler->readConfigPathIni(); + $this->util->iniUtilities->load($path); + $dbSettings = $this->util->iniUtilities->getSection('db'); + $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], + 'dbName'=> $dbSettings['dbName'], + 'dbUser'=> $dbSettings['dbUser'], + 'dbPass'=> $dbSettings['dbPass'], + 'dbPort'=> $dbSettings['dbPort'], + 'dbAdminUser'=> $dbSettings['dbAdminUser'], + 'dbAdminPass'=> $dbSettings['dbAdminPass'], + ); + $this->paths = $this->util->iniUtilities->getSection('urls'); + $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); + $this->sysVersion = $this->readVersion(); + $this->cachePath = $wizConfigHandler->readCachePath(); + $this->proxyPath = $this->cachePath."/.."; // Total guess. + $this->proxyPath = realpath($this->proxyPath."/proxies"); + $this->storeSilent(); + } + + protected function readVersion() { + $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; + if(file_exists($verFile)) { + $foundVersion = file_get_contents($verFile); + return $foundVersion; + } else { + $this->error[] = "KT installation version not found"; + } + + return false; + } + + protected function storeSilent() { + + } } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeBackup.php b/setup/upgrade/steps/upgradeBackup.php index 51d2192..51f28d8 100644 --- a/setup/upgrade/steps/upgradeBackup.php +++ b/setup/upgrade/steps/upgradeBackup.php @@ -245,43 +245,6 @@ class upgradeBackup extends Step { $this->temp_variables['dir'] = $dir; $this->temp_variables['display'] = $stmt['display']; } - - // TODO this function needs to be refactored out into the parent Step class?? - private function readConfig() { - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path - $wizConfigHandler = new configuration(); - $path = $wizConfigHandler->readConfigPathIni(); - $this->util->iniUtilities->load($path); - $dbSettings = $this->util->iniUtilities->getSection('db'); - - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], - 'dbName'=> $dbSettings['dbName'], - 'dbUser'=> $dbSettings['dbUser'], - 'dbPass'=> $dbSettings['dbPass'], - 'dbPort'=> $dbSettings['dbPort'], - // dbSocket doesn't exist as far as I can find, where was it coming from? - //'dbSocket'=> $dbSettings['dbSocket'], - 'dbAdminUser'=> $dbSettings['dbAdminUser'], - 'dbAdminPass'=> $dbSettings['dbAdminPass'], - ); - $this->paths = $this->util->iniUtilities->getSection('urls'); - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); - $this->temp_variables['dbSettings'] = $this->dbSettings; - $this->sysVersion = $this->readVersion(); - $this->cachePath = $wizConfigHandler->readCachePath(); - } - - // TODO this function needs to be refactored out into the parent Step class - public function readVersion() { - $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; - if(file_exists($verFile)) { - $foundVersion = file_get_contents($verFile); - return $foundVersion; - } else { - $this->error[] = "KT installation version not found"; - } - return false; - } } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeComplete.php b/setup/upgrade/steps/upgradeComplete.php index 11f48d8..efa0ef9 100644 --- a/setup/upgrade/steps/upgradeComplete.php +++ b/setup/upgrade/steps/upgradeComplete.php @@ -61,7 +61,7 @@ class upgradeComplete extends Step { * Set all silent mode varibles * */ - private function storeSilent() { + protected function storeSilent() { $v = $this->getDataFromSession('upgradeProperties'); $this->temp_variables['sysVersion'] = $v['upgrade_version']; } diff --git a/setup/upgrade/steps/upgradeDatabase.php b/setup/upgrade/steps/upgradeDatabase.php index a89defa..fa3b973 100644 --- a/setup/upgrade/steps/upgradeDatabase.php +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -65,15 +65,6 @@ class upgradeDatabase extends Step private $dbBinary = ''; // TODO:multiple databases /** - * List of errors encountered - * - * @author KnowledgeTree Team - * @access public - * @var array - */ - public $error = array(); - - /** * List of errors used in template * * @author KnowledgeTree Team @@ -143,8 +134,10 @@ class upgradeDatabase extends Step private function doRun($action = null) { $this->readConfig(); + $con = $this->util->dbUtilities->load($this->dbSettings['dbHost'], $this->dbSettings['dbPort'], $this->dbSettings['dbUser'],$this->dbSettings['dbPass'], $this->dbSettings['dbName']); $this->temp_variables['action'] = $action; + if (is_null($action) || ($action == 'preview')) { $this->temp_variables['title'] = 'Preview Upgrade'; $this->temp_variables['upgradeTable'] = $this->generateUpgradeTable(); @@ -206,31 +199,6 @@ class upgradeDatabase extends Step return false; } - - /** - * Stores varibles used by template - * - * @author KnowledgeTree Team - * @params none - * @access public - * @return array - */ - public function getStepVars() { - return $this->temp_variables; - } - - /** - * Returns database errors - * - * @author KnowledgeTree Team - * @access public - * @params none - * @return array - */ - public function getErrors() { - - return $this->error; - } /** * Initialize errors to false @@ -246,29 +214,6 @@ class upgradeDatabase extends Step } } - private function readConfig() { - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path - $wizConfigHandler = new configuration(); - $path = $wizConfigHandler->readConfigPathIni(); - $this->util->iniUtilities->load($path); - $dbSettings = $this->util->iniUtilities->getSection('db'); - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], - 'dbName'=> $dbSettings['dbName'], - 'dbUser'=> $dbSettings['dbUser'], - 'dbPass'=> $dbSettings['dbPass'], - 'dbPort'=> $dbSettings['dbPort'], - 'dbAdminUser'=> $dbSettings['dbAdminUser'], - 'dbAdminPass'=> $dbSettings['dbAdminPass'], - ); - $this->paths = $this->util->iniUtilities->getSection('urls'); - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); - $this->sysVersion = $this->readVersion(); - $this->cachePath = $wizConfigHandler->readCachePath(); - $this->proxyPath = $this->cachePath."/.."; // Total guess. - $this->proxyPath = realpath($this->proxyPath."/proxies"); - $this->storeSilent(); - } - public function storeSilent() { $this->temp_variables['paths'] = $this->paths; $this->temp_variables['sysVersion'] = $this->sysVersion; @@ -416,10 +361,8 @@ class upgradeDatabase extends Step } private function showResult($res) { - if ($res) { - if (is_a($res, 'Upgrade_Already_Applied')) { - return 'Already applied'; - } + if ($res && is_a($res, 'Upgrade_Already_Applied')) { + return 'Already applied'; } if ($res === true) { return 'Success'; diff --git a/setup/upgrade/steps/upgradeRestore.php b/setup/upgrade/steps/upgradeRestore.php index c540f3b..1cdc480 100644 --- a/setup/upgrade/steps/upgradeRestore.php +++ b/setup/upgrade/steps/upgradeRestore.php @@ -221,43 +221,5 @@ class upgradeRestore extends Step { $this->temp_variables['selected'] = true; } - // TODO this function needs to be refactored out into the parent Step class?? - private function readConfig() { - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path - $wizConfigHandler = new configuration(); - $path = $wizConfigHandler->readConfigPathIni(); - $this->util->iniUtilities->load($path); - $dbSettings = $this->util->iniUtilities->getSection('db'); - - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], - 'dbName'=> $dbSettings['dbName'], - 'dbUser'=> $dbSettings['dbUser'], - 'dbPass'=> $dbSettings['dbPass'], - 'dbPort'=> $dbSettings['dbPort'], - // dbSocket doesn't exist as far as I can find, where was it coming from? - //'dbSocket'=> $dbSettings['dbSocket'], - 'dbAdminUser'=> $dbSettings['dbAdminUser'], - 'dbAdminPass'=> $dbSettings['dbAdminPass'], - ); - $this->paths = $this->util->iniUtilities->getSection('urls'); - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); - $this->temp_variables['dbSettings'] = $this->dbSettings; - $this->sysVersion = $this->readVersion(); - $this->cachePath = $wizConfigHandler->readCachePath(); - } - - // TODO this function needs to be refactored out into the parent Step class - public function readVersion() { - $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; - if(file_exists($verFile)) { - $foundVersion = file_get_contents($verFile); - return $foundVersion; - } else { - $this->error[] = "KT installation version not found"; - } - - return false; - } - } ?> \ No newline at end of file