Permalink
Browse files

Issue #444: CLI backup/upgrade fixes and tweaks

* Added isset checks for argv[0]
* Updated usage message to reflect script filename change
* Made sure upgrade token is removed when running the CLI upgrade interface
* Calculate the time elapsed for migration run and output on completion
* Added timezone setting to upgrade script
  • Loading branch information...
1 parent fff41c6 commit f40b35bb76327e57db9cc7f5d6d070b1d5897cc2 Mark Wilkie committed with ginatrapani Jan 27, 2011
@@ -288,6 +288,8 @@ public function go() {
UpgradeController::isUpgrading( $this->isAdmin(), $classname) ) {
$this->setViewTemplate('install.upgradeneeded.tpl');
$this->disableCaching();
+ $option_dao = DAOFactory::getDAO('OptionDAO');
+ $option_dao->clearSessionData('application_options');
return $this->generateView();
} else {
$results = $this->control();
@@ -35,7 +35,7 @@
// don't run via the web...
if(isset($_SERVER['SERVER_NAME'])) {
- die("This script should only be run via the command line...");
+ die("This script should only be run via the command line.");
}
try {
@@ -44,7 +44,6 @@
usage();
}
-
if (count($argv) != 2 || ! preg_match('/^(\-\-export|\-\-import)$/', $argv[0]) ) {
usage();
} else {
@@ -71,12 +70,10 @@
print "\nImporting data from: $filename\n\n";
$backup_dao->import($filename);
print "\nImport completed...\n\n";
-
}
// release global mutex
BackupController::mutexLock(true);
-
}
}
} catch(Exception $e) {
@@ -29,27 +29,29 @@
*/
chdir('../..');
require_once 'init.php';
+//Avoid "Error: DateTime::__construct(): It is not safe to rely on the system's timezone settings" error
+require_once 'config.inc.php';
+date_default_timezone_set($THINKUP_CFG['timezone']);
// don't run via the web...
if(isset($_SERVER['SERVER_NAME'])) {
- die("This script should only be run via the command line...");
+ die("This script should only be run via the command line.");
}
// help?
array_shift($argv);
-if($argv[0] && preg_match('/^(\-h|\-\-help)$/i', $argv[0])) {
+if(isset($argv[0]) && preg_match('/^(\-h|\-\-help)$/i', $argv[0])) {
usage();
}
try {
-
// do we need a migration?
$db_version = UpgradeController::getCurrentDBVersion($cached = false);
$config = Config::getInstance();
$thinkup_db_version = $config->getValue('THINKUP_VERSION');
$filename = false;
if($db_version == $thinkup_db_version) {
- error_log("\nYour system is up to date...\n");
+ error_log("\nYour ThinkUp database structure is up to date.\n");
exit;
} else {
print "\nThinkup needs to be upgraded to version $thinkup_db_version, proceed => [y|n] ";
@@ -69,12 +71,11 @@
}
}
-
// set global mutex
BackupController::mutexLock();
// run backup first?
- if($argv[0] && preg_match('/^(\-h|\-\-help)$/i', $argv[0])) {
+ if(isset($argv[0]) && preg_match('/^(\-h|\-\-help)$/i', $argv[0])) {
usage();
} else if($filename) {
if( ! preg_match('/\.zip$/', $filename) ) {
@@ -85,14 +86,15 @@
$backup_dao = DAOFactory::getDAO('BackupDAO');
print "\nExporting data to: $filename\n\n";
$backup_dao->export($filename);
- print "\nBackup completed...\n\n";
+ print "\nBackup completed.\n\n";
}
}
-
// run updates...
// get migrations we need to run...
print "\nUpgrading Thinkup to version $thinkup_db_version...\n\n";
+
+ $upgrade_start_time = microtime(true);
putenv('CLI_BACKUP=true');
$upgrade_ctl = new UpgradeController();
$migrations = $upgrade_ctl->getMigrationList($db_version);
@@ -113,15 +115,20 @@
// release global mutex
BackupController::mutexLock();
- print "\nUpgrade complete...\n\n";
+ // delete upgrade token if it exists
+ $upgrade_ctl->deleteTokenFile();
+
+ $upgrade_end_time = microtime(true);
+ $total_time = $upgrade_end_time - $upgrade_start_time;
+ print "\nUpgrade complete. Total time elapsed: ".round($total_time, 2)." seconds\n\n";
} catch(Exception $e) {
error_log(" Error: " . $e->getMessage() . "\n");
}
function usage() {
print "\n Usage:\n\n";
- print " php update.php [--help]\n\n";
+ print " php upgrade.php [--help]\n\n";
print " --help - usage help\n\n";
exit;
}

0 comments on commit f40b35b

Please sign in to comment.