diff --git a/setup/upgrade/index.php b/setup/upgrade/index.php
index 30b902d..5048495 100644
--- a/setup/upgrade/index.php
+++ b/setup/upgrade/index.php
@@ -1,6 +1,6 @@
temp_variables = array("step_name"=>"backup", "silent"=>$this->silent);
@@ -65,7 +62,7 @@ class upgradeBackup extends Step {
$this->util = new UpgradeUtil();
}
- function doStep() {
+ public function doStep() {
parent::doStep();
if(!$this->inStep("backup")) {
$this->doRun();
@@ -92,17 +89,21 @@ class upgradeBackup extends Step {
else if($this->previous()) {
return 'previous';
}
+ else if ($this->upgrade()) {
+ header('Location: index.php?step_name=database');
+ exit;
+ }
$this->doRun();
return 'landing';
}
- function backupNow()
+ private function backupNow()
{
return isset($_POST['BackupNow']);
}
- function doRun($action = null) {
+ private function doRun($action = null) {
$this->temp_variables['action'] = $action;
if (is_null($action) || ($action == 'confirm')) {
@@ -127,29 +128,7 @@ class upgradeBackup extends Step {
private function storeSilent() {
}
- /*
- // these belong in a shared lib
- function set_state($value)
-{
- $_SESSION['state'] = $value;
-}
-function check_state($value, $state='Home')
-{
- if ($_SESSION['state'] != $value)
- {
- ?>
-
- check_state(1);
-// $this->set_state(2);
$targetfile = $_SESSION['backupFile'];
$stmt = $this->create_backup_stmt($targetfile);
$dir = $stmt['dir'];
@@ -163,7 +142,7 @@ function check_state($value, $state='Home')
$read = fread($handle, 10240);
pclose($handle);
$_SESSION['backupOutput']=$read;
- $dir = $this->resolveTempDir();
+ $dir = $this->util->resolveTempDir();
$_SESSION['backupFile'] = $stmt['target'];
if (OS_UNIX) {
@@ -177,21 +156,9 @@ function check_state($value, $state='Home')
$_SESSION['backupStatus'] = false;
}
}
- else
- {
- ?>
-
- The mysqldump utility was not found in the subdirectory.
-
-
- check_state(2);
-// $this->set_state(3);
-// title('Backup Status');
$status = $_SESSION['backupStatus'];
$filename = $_SESSION['backupFile'];
@@ -200,7 +167,7 @@ function check_state($value, $state='Home')
if ($status)
{
$stmt = $this->util->create_restore_stmt($filename);
- $this->temp_variables['display'] = 'The backup file "" has been created.
+ $this->temp_variables['display'] = 'The backup file "' . $filename . '" has been created.
It appears as though the backup has been successful.
';
if ($stmt['dir'] != '')
@@ -230,136 +197,78 @@ function check_state($value, $state='Home')
else
{
$this->temp_variables['display'] .= 'It appears as though the backup process has failed.
Unfortunately, it is difficult to diagnose these problems automatically
- and would recommend that you try to do the backup process manually.
-
- We appologise for the inconvenience.
-
-
-
-
' . $_SESSION['backupOutput'] . '
';
+ and would recommend that you try to do the backup process manually.
+
- performPostUpgradeActions();
- if (PEAR::isError($post_res)) {
- $this->temp_variables['postUpgrade'] = 'Post-Upgrade actions failed.';
- }
- else {
- $this->temp_variables['postUpgrade'] = 'Post-Upgrade actions succeeded.';
+ 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.
+
+ global $default;
+
+ // Lock the scheduler
+ $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
+ touch($lockFile);
+ return true;
+
}
-}
-
-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.
-
- global $default;
-
- // Lock the scheduler
- $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
- touch($lockFile);
- return true;
-
-}
-
-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.
-
- global $default;
-
- // Ensure all plugins are re-registered.
- $sql = "TRUNCATE plugin_helper";
- $res = DBUtil::runQuery($sql);
-
- // Clear out all caches and proxies - they need to be regenerated with the new code
- $proxyDir = $default->proxyCacheDirectory;
- KTUtil::deleteDirectory($proxyDir);
-
- $oKTCache = new KTCache();
- $oKTCache->deleteAllCaches();
-
- // Clear the configuration cache, it'll regenerate on next load
- $oKTConfig = new KTConfig();
- $oKTConfig->clearCache();
-
- // Unlock the scheduler
- $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
- if(file_exists($lockFile)){
- @unlink($lockFile);
+
+ 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.
+
+ global $default;
+
+ // Ensure all plugins are re-registered.
+ $sql = "TRUNCATE plugin_helper";
+ $res = DBUtil::runQuery($sql);
+
+ // Clear out all caches and proxies - they need to be regenerated with the new code
+ $proxyDir = $default->proxyCacheDirectory;
+ KTUtil::deleteDirectory($proxyDir);
+
+ $oKTCache = new KTCache();
+ $oKTCache->deleteAllCaches();
+
+ // Clear the configuration cache, it'll regenerate on next load
+ $oKTConfig = new KTConfig();
+ $oKTConfig->clearCache();
+
+ // Unlock the scheduler
+ $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
+ if(file_exists($lockFile)){
+ @unlink($lockFile);
+ }
+
+ return true;
+
}
- return true;
-
-}
-
-function performAllUpgrades () {
- global $default;
- $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
- $lastVersion = DBUtil::getOneResultKey($query, 'value');
- $currentVersion = $default->systemVersion;
-
- $upgrades = describeUpgrade($lastVersion, $currentVersion);
+ private function performAllUpgrades () {
+ global $default;
+
+ $row = 1;
+
+ $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
+ $lastVersion = DBUtil::getOneResultKey($query, 'value');
+ $currentVersion = $default->systemVersion;
- $this->temp_variables['upgradeTable'] = '';
-
- foreach ($upgrades as $upgrade) {
- if (($GLOBALS['row'] % 2) == 1) {
- $class = "odd";
- } else {
- $class = "even";
+ $upgrades = describeUpgrade($lastVersion, $currentVersion);
+
+ $this->temp_variables['upgradeTable'] = '';
+
+ foreach ($upgrades as $upgrade) {
+ if (($row % 2) == 1) {
+ $class = "odd";
+ } else {
+ $class = "even";
+ }
+ $this->temp_variables['upgradeTable'] .= sprintf('
\n";
+
+ return $res;
+ }
+
+ private function showResult($res) {
if (PEAR::isError($res)) {
- if (!is_a($res, 'Upgrade_Already_Applied')) {
- break;
- } else {
- $res = true;
+ if (is_a($res, 'Upgrade_Already_Applied')) {
+ return 'Already applied';
}
+ return sprintf('%s', htmlspecialchars($res->toString()));
}
- if ($res === false) {
- $res = PEAR::raiseError("Upgrade returned false");
- break;
+ if ($res === true) {
+ return 'Success';
}
- }
-
- return $res;
-}
-
-function showResult($res) {
- if (PEAR::isError($res)) {
- if (is_a($res, 'Upgrade_Already_Applied')) {
- return 'Already applied';
+ if ($res === false) {
+ return 'Failure';
}
- return sprintf('%s', htmlspecialchars($res->toString()));
+ return $res;
}
- if ($res === true) {
- return 'Success';
- }
- if ($res === false) {
- return 'Failure';
- }
- return $res;
-}
}
?>
\ No newline at end of file
diff --git a/setup/upgrade/steps/upgradeInstallation.php b/setup/upgrade/steps/upgradeInstallation.php
index bc7d0fc..2354f5a 100644
--- a/setup/upgrade/steps/upgradeInstallation.php
+++ b/setup/upgrade/steps/upgradeInstallation.php
@@ -1,6 +1,6 @@
temp_variables = array("step_name"=>"installation");
}
- function doStep() {
+ public function doStep() {
parent::doStep();
if($this->next()) {
return 'next';
@@ -72,13 +73,5 @@ class UpgradeInstallation extends step
return 'landing';
}
- function backup() {
- return isset($_POST['Backup']);
- }
-
- function restore() {
- return isset($_POST['Restore']);
- }
-
}
?>
\ No newline at end of file
diff --git a/setup/upgrade/steps/upgradeRestore.php b/setup/upgrade/steps/upgradeRestore.php
index 331e8dc..5b26336 100644
--- a/setup/upgrade/steps/upgradeRestore.php
+++ b/setup/upgrade/steps/upgradeRestore.php
@@ -1,6 +1,6 @@
util = new UpgradeUtil();
}
- function doStep() {
+ public function doStep() {
parent::doStep();
+ $this->temp_variables['restore'] = false;
+
if(!$this->inStep("restore")) {
$this->doRun();
return 'landing';
@@ -78,24 +78,40 @@ class upgradeRestore extends Step {
} else if($this->previous()) {
return 'previous';
}
+ else if ($this->restoreNow()) {
+ $this->temp_variables['restoreSuccessful'] = false;
+ $this->doRun(true);
+ return 'next';
+ }
$this->doRun();
return 'landing';
}
- function doRun() {
- $this->temp_variables['selected'] = false;
- if ($this->select()) {
- $this->restoreSelected();
- $this->temp_variables['selected'] = true;
+ private function restoreNow() {
+ return isset($_POST['RunRestore']);
+ }
+
+ private function doRun($restore = false) {
+ if (!$restore) {
+ $this->temp_variables['selected'] = false;
+ if ($this->select()) {
+ $this->restoreSelected();
+ $this->temp_variables['selected'] = true;
+ $this->temp_variables['availableBackups'] = true;
+ }
+ $this->restoreConfirm();
+ } // end not running a restore, just setting up
+ else {
+ $this->restoreDatabase();
}
- $this->restoreConfirm();
+
$this->storeSilent();// Set silent mode variables
return true;
}
- function select() {
+ private function select() {
return isset($_POST['RestoreSelect']);
}
@@ -105,183 +121,126 @@ class upgradeRestore extends Step {
*/
private function storeSilent() {
}
- /*
- // these belong in a shared lib
- function set_state($value)
-{
- $_SESSION['state'] = $value;
-}
-function check_state($value, $state='Home')
-{
- if ($_SESSION['state'] != $value)
- {
- ?>
-
- util->create_restore_stmt($filename);
- $dir = $stmt['dir'];
- if (is_file($dir . '/mysql') || is_file($dir . '/mysql.exe'))
+ private function restoreDatabase()
{
-
-?>
- The restore is now underway. Please wait till it completes.
-temp_variables['restore'] = true;
+ $status = $_SESSION['backupStatus'];
+ $filename = $_SESSION['backupFile'];
+ $stmt = $this->util->create_restore_stmt($filename);
+ $dir = $stmt['dir'];
+
+ if (is_file($dir . '/mysql') || is_file($dir . '/mysql.exe'))
{
-
- $handle = popen($stmt, 'r');
- if ($handle=='false')
+ $curdir=getcwd();
+ chdir($dir);
+
+ $ok=true;
+ $stmts=explode("\n",$stmt['cmd']);
+ foreach($stmts as $stmt)
{
- $ok=false;
- break;
+
+ $handle = popen($stmt, 'r');
+ if ($handle=='false')
+ {
+ $ok=false;
+ break;
+ }
+ $read = fread($handle, 10240);
+ pclose($handle);
+ $_SESSION['restoreOutput']=$read;
}
- $read = fread($handle, 10240);
- pclose($handle);
- $_SESSION['restoreOutput']=$read;
- }
-
+
$_SESSION['restoreStatus'] = $ok;
-
- }
- else
- {
-?>
-
- The mysql utility was not found in the subdirectory.
-
-
-restoreDone();
+ }
}
-}
-
-
-function restoreDone()
-{
-// check_state(5);
-// set_state(6);
-// title('Restore Status');
- $status = $_SESSION['restoreStatus'];
- $filename = $_SESSION['backupFile'];
-
- if ($status)
- {
-
-?>
- The restore of "" has been completed.
-
- It appears as though the restore has been successful.
-
-
-
-
-
-It appears as though the restore process has failed.
-Unfortunately, it is difficult to diagnose these problems automatically
-and would recommend that you try to do the backup process manually.
-
-We appologise for the inconvenience.
-
-
-
-
-
-
-temp_variables['display'] = 'The restore of "' . $filename . '" has been completed.
+
+ It appears as though the restore has been successful.
+
';
+
+ $this->temp_variables['title'] = 'Restore Complete';
+ $this->temp_variables['restoreSuccessful'] = true;
+ }
+ else
+ {
+ $this->temp_variables['display'] = 'It appears as though the restore process has failed.
+ Unfortunately, it is difficult to diagnose these problems automatically
+ and would recommend that you try to do the backup process manually.
+
-
-
-
-
+
+
-
\ No newline at end of file
diff --git a/setup/upgrade/templates/installation.tpl b/setup/upgrade/templates/installation.tpl
index e33d25f..b51f7a1 100644
--- a/setup/upgrade/templates/installation.tpl
+++ b/setup/upgrade/templates/installation.tpl
@@ -2,7 +2,6 @@
Current Installation
-
If you have just updated
your KnowledgeTree code base, you will need to complete the upgrade process in order to ensure your system is fully operational with the new version.