diff --git a/setup/upgrade/steps/upgradeBackup.php b/setup/upgrade/steps/upgradeBackup.php index 158c11d..47db877 100644 --- a/setup/upgrade/steps/upgradeBackup.php +++ b/setup/upgrade/steps/upgradeBackup.php @@ -110,8 +110,10 @@ class upgradeBackup extends Step { $this->backupConfirm(); } else { - $this->temp_variables['title'] = 'Backup In Progress'; + $this->temp_variables['title'] = 'Backup Created'; $this->backup(); + // TODO error checking (done in backupDone at the moment) + $this->backupDone(); } $this->storeSilent();// Set silent mode variables @@ -125,6 +127,7 @@ class upgradeBackup extends Step { private function storeSilent() { } + /* // these belong in a shared lib function set_state($value) { @@ -142,34 +145,25 @@ function check_state($value, $state='Home') exit; } } +*/ private function backup() { // $this->check_state(1); // $this->set_state(2); - $targetfile=$_SESSION['backupFile']; + $targetfile = $_SESSION['backupFile']; $stmt = $this->create_backup_stmt($targetfile); $dir = $stmt['dir']; if (is_file($dir . '/mysqladmin') || is_file($dir . '/mysqladmin.exe')) { - ob_flush(); - flush(); - ?> - The backup is now underway. Please wait till it completes. - resolveTempDir(); + $dir = $this->resolveTempDir(); $_SESSION['backupFile'] = $stmt['target']; if (OS_UNIX) { @@ -197,75 +191,52 @@ function check_state($value, $state='Home') private function backupDone() { // $this->check_state(2); // $this->set_state(3); - title('Backup Status'); +// title('Backup Status'); $status = $_SESSION['backupStatus']; - $filename=$_SESSION['backupFile']; + $filename = $_SESSION['backupFile']; + + $this->temp_variables['backupStatus'] = $status; if ($status) { - $stmt=create_restore_stmt($filename); - ?> - The backup file "" has been created. + $stmt = $this->util->create_restore_stmt($filename); + $this->temp_variables['display'] = 'The backup file "" has been created.

It appears as though the backup has been successful. -

- '; if ($stmt['dir'] != '') { - ?> - Manually, you would do the following to restore the backup: + $this->temp_variables['dir'] = $stmt['dir']; + $this->temp_variables['display'] .= 'Manually, you would do the following to restore the backup:

- cd -
- cd ' . $stmt['dir'] . ' +
'; } else { - ?> - The mysql backup utility could not be found automatically. Please edit the config.ini and update the backup/mysql Directory entry. + $this->temp_variables['display'] .= 'The mysql backup utility could not be found automatically. Please edit the config.ini and update the backup/mysql Directory entry.

If you need to restore from this backup, you should be able to use the following statements:

-
- '; } - ?> - -
- - temp_variables['display'] .= '' . $stmt['display'] . ' +

'; } else { - ?> - It appears as though the backup process has failed.

Unfortunately, it is difficult to diagnose these problems automatically + $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'] . ''; } } diff --git a/setup/upgrade/steps/upgradeRestore.php b/setup/upgrade/steps/upgradeRestore.php index 8e346c1..290e62e 100644 --- a/setup/upgrade/steps/upgradeRestore.php +++ b/setup/upgrade/steps/upgradeRestore.php @@ -244,117 +244,6 @@ We appologise for the inconvenience. } -function create_restore_stmt($targetfile) -{ - $oKTConfig =& KTConfig::getSingleton(); - - $adminUser = $oKTConfig->get('db/dbAdminUser'); - $adminPwd = $oKTConfig->get('db/dbAdminPass'); - $dbHost = $oKTConfig->get('db/dbHost'); - $dbName = $oKTConfig->get('db/dbName'); - $dbPort = trim($oKTConfig->get('db/dbPort')); - if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port'); - if (empty($dbPort)) $dbPort='3306'; - $dbSocket = trim($oKTConfig->get('db/dbSocket')); - if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); - if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; - - $dir = $this->resolveMysqlDir(); - - $info['dir']=$dir; - - $prefix=''; - if (OS_UNIX) - { - $prefix .= "./"; - } - - if (@stat($dbSocket) !== false) - { - $mechanism="--socket=\"$dbSocket\""; - } - else - { - $mechanism="--port=\"$dbPort\""; - } - - $tmpdir = $this->resolveTempDir(); - - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"
"; - $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"
"; - - - $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n"; - $info['display']=$stmt; - - - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n"; - $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n"; - - $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\""; - $info['cmd']=$stmt; - return $info; -} - -function resolveMysqlDir() -{ - // possibly detect existing installations: - - if (OS_UNIX) - { - $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); - $mysqlname ='mysql'; - } - else - { - $dirs = explode(';', $_SERVER['PATH']); - $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin'; - $dirs[] = 'c:/program files/ktdms/mysql/bin'; - $mysqlname ='mysql.exe'; - } - - $oKTConfig =& KTConfig::getSingleton(); - $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); - $dirs[] = $mysqldir; - - if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) - { - $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); - } - - foreach($dirs as $dir) - { - if (is_file($dir . '/' . $mysqlname)) - { - return $dir; - } - } - - return ''; -} - -function resolveTempDir() -{ - - if (OS_UNIX) - { - $dir='/tmp/kt-db-backup'; - } - else - { - $dir='c:/kt-db-backup'; - } - $oKTConfig =& KTConfig::getSingleton(); - $dir = $oKTConfig->get('backup/backupDirectory',$dir); - - if (!is_dir($dir)) - { - mkdir($dir); - } - return $dir; -} - - function restoreSelect() { // title('Select Backup to Restore'); diff --git a/setup/upgrade/templates/backup.tpl b/setup/upgrade/templates/backup.tpl index d710feb..605eb77 100644 --- a/setup/upgrade/templates/backup.tpl +++ b/setup/upgrade/templates/backup.tpl @@ -1,4 +1,4 @@ -

+


- Are you sure you want to perform the backup? - -

-Your mysql installation has been resolved. Manually, you would do the following: -

-

- - -
-cd "" -
-

+ Are you sure you want to perform the backup? + +

+ Your mysql installation has been resolved. Manually, you would do the following: +

+

+ + +
+ cd "" +
+

+ + + KnowledgeTree Upgrade Wizard + + + + + + + +
+ +
+
+ +
+
+

+ +
+ ".$error.""; + ?> + + '; + foreach ($errors as $msg){ + echo $msg . "
"; + ?> + Refresh + '; + } + } + ?> +

+ +
+ +
+
+
+
 
+
+ + +
+ + + \ No newline at end of file diff --git a/setup/upgrade/upgradeUtil.php b/setup/upgrade/upgradeUtil.php index 3ae678b..e13c97f 100644 --- a/setup/upgrade/upgradeUtil.php +++ b/setup/upgrade/upgradeUtil.php @@ -79,6 +79,31 @@ class UpgradeUtil { ob_end_clean(); echo $contents; } + + /** + * Function to send output to the browser prior to normal dynamic loading of a template after code execution + * + * @param string $template The name of the template to use + * @param array $output [optional] Optional array containing output text to be inserted into the template + * @return + */ + public function flushOutput($template, $output = null) { + if (is_array($output)) { + foreach ($output as $key => $value) { + $template_vars[$key] = $value; + } + } + $file = "templates/" . $template; + if (!file_exists($file)) { + return false; + } + extract($template_vars); // Extract the vars to local namespace + ob_start(); + include($file); + $contents = ob_get_contents(); + ob_end_clean(); + echo $contents; + } /** * Check if system needs to be upgraded @@ -637,6 +662,116 @@ class UpgradeUtil { } return join(" ", $aSafeArgs); } + + function create_restore_stmt($targetfile) +{ + $oKTConfig =& KTConfig::getSingleton(); + + $adminUser = $oKTConfig->get('db/dbAdminUser'); + $adminPwd = $oKTConfig->get('db/dbAdminPass'); + $dbHost = $oKTConfig->get('db/dbHost'); + $dbName = $oKTConfig->get('db/dbName'); + $dbPort = trim($oKTConfig->get('db/dbPort')); + if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port'); + if (empty($dbPort)) $dbPort='3306'; + $dbSocket = trim($oKTConfig->get('db/dbSocket')); + if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); + if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; + + $dir = $this->resolveMysqlDir(); + + $info['dir']=$dir; + + $prefix=''; + if (OS_UNIX) + { + $prefix .= "./"; + } + + if (@stat($dbSocket) !== false) + { + $mechanism="--socket=\"$dbSocket\""; + } + else + { + $mechanism="--port=\"$dbPort\""; + } + + $tmpdir = $this->resolveTempDir(); + + $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"
"; + $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"
"; + + + $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n"; + $info['display']=$stmt; + + + $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n"; + $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n"; + + $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\""; + $info['cmd']=$stmt; + return $info; +} + +function resolveMysqlDir() +{ + // possibly detect existing installations: + + if (OS_UNIX) + { + $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); + $mysqlname ='mysql'; + } + else + { + $dirs = explode(';', $_SERVER['PATH']); + $dirs[] ='c:/Program Files/MySQL/MySQL Server 5.0/bin'; + $dirs[] = 'c:/program files/ktdms/mysql/bin'; + $mysqlname ='mysql.exe'; + } + + $oKTConfig =& KTConfig::getSingleton(); + $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); + $dirs[] = $mysqldir; + + if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) + { + $dirs [] = realpath(dirname($FILE) . '/../../mysql/bin'); + } + + foreach($dirs as $dir) + { + if (is_file($dir . '/' . $mysqlname)) + { + return $dir; + } + } + + return ''; +} + +function resolveTempDir() +{ + + if (OS_UNIX) + { + $dir='/tmp/kt-db-backup'; + } + else + { + $dir='c:/kt-db-backup'; + } + $oKTConfig =& KTConfig::getSingleton(); + $dir = $oKTConfig->get('backup/backupDirectory',$dir); + + if (!is_dir($dir)) + { + mkdir($dir); + } + return $dir; +} } ?> \ No newline at end of file