diff --git a/setup/upgrade/lib/UpgradeItems.inc.php b/setup/upgrade/lib/UpgradeItems.inc.php index 0aa4fe5..80d8696 100644 --- a/setup/upgrade/lib/UpgradeItems.inc.php +++ b/setup/upgrade/lib/UpgradeItems.inc.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -57,16 +57,16 @@ require_once("../wizard/dbUtilities.php"); // {{{ Upgrade_Already_Applied class Upgrade_Already_Applied { - + function Upgrade_Already_Applied($oUpgradeItem) { $this->oUpgradeItem = $oUpgradeItem; } - + } // }}} class UpgradeItem { - + public $type = ""; public $name; public $version; @@ -76,7 +76,8 @@ class UpgradeItem { public $parent; public $date; public $result; - + protected $error; + function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) { $this->name = $name; $this->version = $version; @@ -86,7 +87,7 @@ class UpgradeItem { $this->description = $description; $this->phase = $phase; $this->priority = $priority; - + $this->dbUtilities = new dbUtilities(); $this->iniUtilities = new iniUtilities(); } @@ -122,6 +123,14 @@ class UpgradeItem { return $this->type; } + public function getErrors() + { + if(isset($this->error[0])){ + return $this->error[0]; + } + return $this->error; + } + /** * Runs a DB query and returns a result based on arguments which specify what to look for * @@ -135,13 +144,13 @@ class UpgradeItem { $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']); + $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbAdminUser'], $dconf['dbAdminPass'], $dconf['dbName']); $result = $this->dbUtilities->query($query); if($checkResult) { $assArr = $this->dbUtilities->fetchAssoc($result); @@ -153,7 +162,7 @@ class UpgradeItem { } return !is_null($result); } - + function _upgradeTableInstalled() { $query = "SELECT COUNT(id) FROM upgrades"; $res = $this->runDBQuery($query, true, true); @@ -169,7 +178,7 @@ class UpgradeItem { } $query = "SELECT id FROM upgrades WHERE descriptor = '".$this->getDescriptor()."' AND result = 1"; $res = $this->runDBQuery($query, true, false); - + if(!$res) { return true; } @@ -214,7 +223,7 @@ class UpgradeItem { } $sql = "INSERT INTO upgrades (`id`, `descriptor`, `description`, `date_performed`, `result`, `parent`) VALUES (NULL, '". $this->getDescriptor()."', '".$this->description."', '".$this->date."', '".$result."', '".$parentid."')"; $this->dbUtilities->query($sql); - + return true; } @@ -225,7 +234,7 @@ class UpgradeItem { } // end class UpgradeItem class SQLUpgradeItem extends UpgradeItem { - + function SQLUpgradeItem($path, $version = null, $description = null, $phase = null, $priority = null) { $this->type = "sql"; $this->priority = 0; @@ -366,11 +375,11 @@ class SQLUpgradeItem extends UpgradeItem { $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); return $this->dbUtilities->runQueries($queries); } - + } // end class SQLUpgradeItem class KTRebuildPermissionObserver { - + function start() { $this->lastBeat = time(); } @@ -384,11 +393,11 @@ class KTRebuildPermissionObserver { } function end() { } - + } class RecordUpgradeItem extends UpgradeItem { - + function RecordUpgradeItem ($version, $oldversion = null) { $this->type = "upgrade"; if (is_null($oldversion)) { @@ -426,7 +435,7 @@ class RecordUpgradeItem extends UpgradeItem { KTPermissionUtil::rebuildPermissionLookups(true); $po->end(); */ - + $versionFile=KT_DIR . '/docs/VERSION-NAME.txt'; $fp = fopen($versionFile,'rt'); $systemVersion = fread($fp, filesize($versionFile)); @@ -495,7 +504,7 @@ class RecordUpgradeItem extends UpgradeItem { @unlink($sFile); } } - + } // end class RecordUpgradeItem ?> diff --git a/setup/upgrade/steps/upgradeDatabase.php b/setup/upgrade/steps/upgradeDatabase.php index 789f483..e87f80e 100644 --- a/setup/upgrade/steps/upgradeDatabase.php +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -1,6 +1,6 @@ temp_variables = array("step_name"=>"database", "silent"=>$this->silent, + $this->temp_variables = array("step_name"=>"database", "silent"=>$this->silent, "loadingText"=>"The database upgrade is under way. Please wait until it completes"); $this->initErrors(); if(!$this->inStep("database")) { @@ -119,25 +119,25 @@ class upgradeDatabase extends Step } return 'error'; } - + $this->doRun(); return 'landing'; } - + private function confirmUpgrade() { return isset($_POST['ConfirmUpgrade']); } - + private function upgrading() { return isset($_POST['RunUpgrade']); - } - + } + private function doRun($action = null) { $this->readConfig(); - + $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(); @@ -154,10 +154,10 @@ class upgradeDatabase extends Step } $this->temp_variables['backupSuccessful'] = true; } - + return true; } - + private function generateUpgradeTable() { $this->sysVersion = $this->readVersion(); $this->temp_variables['systemVersion'] = $this->sysVersion; @@ -197,7 +197,7 @@ class upgradeDatabase extends Step $this->error[] = "KT installation version not found"; } - return false; + return false; } /** @@ -213,14 +213,14 @@ class upgradeDatabase extends Step $this->error[$e] = false; } } - + public function storeSilent() { $this->temp_variables['paths'] = $this->paths; $this->temp_variables['sysVersion'] = $this->sysVersion; $this->temp_variables['sysVersion'] = $this->sysVersion; $this->temp_variables['dbSettings'] = $this->dbSettings; } - + private function upgradeConfirm() { if (!isset($_SESSION['backupStatus']) || $_SESSION['backupStatus'] === false) { @@ -234,12 +234,12 @@ class upgradeDatabase extends Step private function doDatabaseUpgrade() { $errors = false; - + $this->temp_variables['detail'] = '
The table below describes the upgrades that have occurred to
upgrade your KnowledgeTree installation to ' . $this->sysVersion . '';
-
+
$this->performPreUpgradeActions();
-
+
$res = $this->performAllUpgrades();
if (!$res) {
$errors = true;
@@ -247,7 +247,7 @@ class upgradeDatabase extends Step
// TODO instantiate error details hideable section?
$this->temp_variables['upgradeStatus'] = 'Database upgrade failed
- Please restore from your backup and ensure that the database does not contain
+ Please restore from your backup and ensure that the database does not contain
any unsupported modifications and try the upgrade process again.
If the problem persists, contact KnowledgeTree Support.';
@@ -255,27 +255,27 @@ class upgradeDatabase extends Step
else {
$this->temp_variables['upgradeStatus'] = 'Upgrade succeeded.';
}
-
+
$this->performPostUpgradeActions();
-
-
+
+
return !$errors;
}
private function performPreUpgradeActions() {
-
+
// This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
// It should idealy work the same as the upgrades.
// Lock the scheduler
$lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock';
touch($lockFile);
return true;
-
+
}
-
+
private function deleteDirectory($sPath) {
if (empty($sPath) || !is_dir($sPath)) return;
-
+
if (!WINDOWS_OS) {
if (file_exists('/bin/rm')) {
$this->util->pexec(array('/bin/rm', '-rf', $sPath));
@@ -303,28 +303,31 @@ class upgradeDatabase extends Step
closedir($hPath);
rmdir($sPath);
}
-
+
private function performPostUpgradeActions() {
-
+
// This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
// It should idealy work the same as the upgrades.
-
+
// Ensure all plugins are re-registered.
$sql = "TRUNCATE plugin_helper";
$this->util->dbUtilities->query($sql);
-
+
// Clear out all caches and proxies - they need to be regenerated with the new code
$this->deleteDirectory($this->proxyPath);
$this->deleteDirectory($this->cachePath);
-
+
+ // Recreate the cache directory - it doesn't get regenerated
+ mkdir($this->cachePath, 0755);
+
// Unlock the scheduler
$lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock';
if(file_exists($lockFile)){
unlink($lockFile);
}
-
+
return true;
-
+
}
private function performAllUpgrades () {
@@ -343,11 +346,12 @@ class upgradeDatabase extends Step
} else {
$class = "even";
}
- $this->temp_variables['upgradeTable'] .= sprintf('