From e8d28067d873076ac892fa209b8c28bf3355a7b8 Mon Sep 17 00:00:00 2001 From: Jarrett Jordaan Date: Mon, 26 Oct 2009 16:55:12 +0200 Subject: [PATCH] Start Upgrade Refactor --- setup/migrate/steps/migrateComplete.php | 10 ++++++++++ setup/upgrade/step.php | 16 ++++++++++++++++ setup/upgrade/steps/upgradeInstallation.php | 5 ----- setup/upgrade/steps/upgradeWelcome.php | 35 ++++++++++------------------------- setup/wizard/install.lock | 0 setup/wizard/installUtil.php | 37 ------------------------------------- setup/wizard/steps/configuration.php | 36 +++++++++++++++++++++--------------- setup/wizard/steps/database.php | 1 - setup/wizard/templates/complete.tpl | 2 +- 9 files changed, 58 insertions(+), 84 deletions(-) create mode 100644 setup/wizard/install.lock diff --git a/setup/migrate/steps/migrateComplete.php b/setup/migrate/steps/migrateComplete.php index 3cc332c..38d0819 100644 --- a/setup/migrate/steps/migrateComplete.php +++ b/setup/migrate/steps/migrateComplete.php @@ -64,9 +64,19 @@ class migrateComplete extends Step { $this->checkServices(); $this->checkSqlDump(); $this->checkPaths(); + $this->removeInstallSessions(); $this->storeSilent();// Set silent mode variables } + private function removeInstallSessions() { + $isteps = array('dependencies', 'configuration', 'services', 'database', 'registration', 'install', 'complete'); + foreach ($isteps as $step) { + if(isset($_SESSION['installers'][$step])) { + $_SESSION['installers'][$step] = null; + } + } + } + private function checkPaths() { $installation = $this->getDataFromSession("installation"); // Get installation directory foreach ($installation['urlPaths'] as $path) { diff --git a/setup/upgrade/step.php b/setup/upgrade/step.php index 49890fd..e762275 100644 --- a/setup/upgrade/step.php +++ b/setup/upgrade/step.php @@ -420,6 +420,22 @@ class Step public function setErrors($error) { $this->error = $error; } + + /** + * Get session data from package + * + * @author KnowledgeTree Team + * @params none + * @access private + * @return boolean + */ + public function getDataFromPackage($package, $class) { + if(empty($_SESSION[$package][$class])) { + return false; + } + + return $_SESSION[$package][$class]; + } } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeInstallation.php b/setup/upgrade/steps/upgradeInstallation.php index 7a3d1e4..b65e6b2 100644 --- a/setup/upgrade/steps/upgradeInstallation.php +++ b/setup/upgrade/steps/upgradeInstallation.php @@ -54,19 +54,14 @@ class UpgradeInstallation extends step public function doStep() { $this->temp_variables = array("step_name"=>"installation"); -// parent::doStep(); if($this->next()) { return 'next'; } else if ($this->restore()) { -// header('Location: index.php?step_name=restore'); $this->util->redirect("index.php?step_name=restore"); -// exit; } else if ($this->upgrade()) { - //header('Location: index.php?step_name=database'); $this->util->redirect("index.php?step_name=database"); -// exit; } return 'landing'; diff --git a/setup/upgrade/steps/upgradeWelcome.php b/setup/upgrade/steps/upgradeWelcome.php index 0082985..2810a51 100644 --- a/setup/upgrade/steps/upgradeWelcome.php +++ b/setup/upgrade/steps/upgradeWelcome.php @@ -40,9 +40,6 @@ * @version Version 0.1 */ -require_once('../../config/dmsDefaults.php'); -require_once KT_LIB_DIR . '/authentication/authenticationutil.inc.php'; - class upgradeWelcome extends step { protected $silent = false; @@ -66,38 +63,26 @@ class upgradeWelcome extends step { // attempt login $username = $_REQUEST['username']; $password = $_REQUEST['password']; - $authenticated = $this->checkPassword($username, $password); - - if (!$authenticated) - { + if (!$authenticated) { session_unset(); return false; } - $_SESSION['setup_user'] = $username; - return true; } private function checkPassword($username, $password) { - global $default; - - $sTable = KTUtil::getTableName('users'); - $sQuery = "SELECT count(*) AS match_count FROM $sTable WHERE username = ? AND password = ?"; - $aParams = array($username, md5($password)); - $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'match_count'); - if (PEAR::isError($res)) { return false; } - else { - $sTable = KTUtil::getTableName('users_groups_link'); - $sQuery = "SELECT count(*) AS match_count FROM $sTable WHERE user_id = ? AND group_id = 1"; - $aParams = array($res); - $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'match_count'); - if (PEAR::isError($res)) { return false; } - else { - return ($res == 1); - } + $dconf = $this->getDataFromPackage('installers', 'database'); + $this->dbhandler->load($dconf['dhost'], $dconf['duname'], $dconf['dpassword'], $dconf['dname']); + $sQuery = "SELECT count(*) AS match_count FROM users WHERE username = '$username' AND password = '".md5($password)."'"; + $res = $this->dbhandler->query($sQuery); + $ass = $this->dbhandler->fetchAssoc($res); + if(isset($ass[0]['match_count'])) { + if($ass[0]['match_count']) + return true; } + return false; } } diff --git a/setup/wizard/install.lock b/setup/wizard/install.lock new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/setup/wizard/install.lock diff --git a/setup/wizard/installUtil.php b/setup/wizard/installUtil.php index 25452f5..8dcb4ce 100644 --- a/setup/wizard/installUtil.php +++ b/setup/wizard/installUtil.php @@ -692,43 +692,6 @@ class InstallUtil { return ''; } -/* function getOpenOffice() { - $cmd = "whereis soffice"; - $res = $this->getOpenOfficeHelper($cmd); - if($res != '' && preg_match('/soffice/', $res)) { - return $res; - } - $cmd = "which soffice"; - $res = $this->getOpenOfficeHelper($cmd); - if($res != '') { - return $res; - } - $cmd = "locate soffice"; - $res = $this->getOpenOfficeHelper($cmd); - if($res != '') { - return $res; - } - - return 'soffice'; - }*/ - -/* function getOpenOfficeHelper($cmd) { - $response = $this->pexec($cmd); - if(is_array($response['out'])) { - if (isset($response['out'][0])) { - $broke = explode(' ', $response['out'][0]); - foreach ($broke as $r) { - $match = preg_match('/bin/', $r); - if($match) { - return preg_replace('/soffice:/', '', $r); - } - } - } - } - - return ''; - }*/ - /** * Deletes migration lock file if a clean install is chosen * This is in case someone changes their mind after choosing upgrade/migrate and clicks back up to this step diff --git a/setup/wizard/steps/configuration.php b/setup/wizard/steps/configuration.php index 1b732f1..9d7e4ed 100644 --- a/setup/wizard/steps/configuration.php +++ b/setup/wizard/steps/configuration.php @@ -312,10 +312,11 @@ class configuration extends Step $paths = $conf['paths']; if ($this->util->isMigration()) { // Check if its an upgrade $this->readInstallation(); + $configPath = $paths['configFile']['path']; } else { $this->readConfigPath(); // initialise writing to config.ini } - $this->getFromConfigPath(); + $this->getFromConfigPath(); // Sets config Paths $ini = false; if(file_exists($configPath)) { $ini = new iniUtilities($configPath); @@ -540,6 +541,7 @@ class configuration extends Step return $configs; } + /** * Migration Path finder * @@ -571,9 +573,6 @@ class configuration extends Step } } - // Now for config path itself - if(isset($this->temp_variables[''])) - return true; } @@ -647,17 +646,24 @@ class configuration extends Step * @return boolean */ private function writeConfigPath($configPath = '') { - $configPath = $this->getContentPath(); - if(!$configPath) return false; - $ini = new iniUtilities($configPath); - $data = $ini->getFileByLine(); - $configContent = ''; - foreach ($data as $k=>$v) { - if(preg_match('/config.ini/', $k)) { - $configContent = $k; - break; - } - } + $conf = $this->getDataFromSession("configuration"); // get data from the server + $paths = $conf['paths']; + if(isset($paths['configFile']['path'])) { + $configPath = $this->getContentPath(); + $configContent = $paths['configFile']['path']; + } else { + $configPath = $this->getContentPath(); + if(!$configPath) return false; + $ini = new iniUtilities($configPath); + $data = $ini->getFileByLine(); + $configContent = ''; + foreach ($data as $k=>$v) { + if(preg_match('/config.ini/', $k)) { + $configContent = $k; + break; + } + } + } $fp = fopen($configPath, 'w'); if(fwrite($fp, $configContent)) return true; diff --git a/setup/wizard/steps/database.php b/setup/wizard/steps/database.php index 8089fd1..2fa45af 100644 --- a/setup/wizard/steps/database.php +++ b/setup/wizard/steps/database.php @@ -774,7 +774,6 @@ class database extends Step $dbMigrate = $this->util->getDataFromPackage('migrate', 'database'); $sqlFile = $dbMigrate['dumpLocation']; $this->parse_mysql_dump($sqlFile); - $this->dbhandler->load($this->dhost, $this->duname, $this->dpassword, $this->dname); $dropPluginHelper = "TRUNCATE plugin_helper;"; $this->dbhandler->query($dropPluginHelper); $updateUrls = 'UPDATE config_settings c SET c.value = "default" where c.group_name = "urls";'; diff --git a/setup/wizard/templates/complete.tpl b/setup/wizard/templates/complete.tpl index 611bf4b..e422980 100644 --- a/setup/wizard/templates/complete.tpl +++ b/setup/wizard/templates/complete.tpl @@ -134,7 +134,7 @@ $redirect = "http://".$_SERVER['SERVER_NAME'].":$port".$root_url."/admin.php"; ?> - Goto Database Upgrade + Goto Database Upgrade Goto Login -- libgit2 0.21.4