Skip to content
Snippets Groups Projects
Commit 679b6d91 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add error logging to upgrader

parent b97e2b88
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ Class SetupWizard {
function load_sql_file($file, $prefix, $abort=true, $debug=false) {
if(!file_exists($file) || !($schema=file_get_contents($file)))
return $this->abort('Error accessing SQL file '.basename($file));
return $this->abort('Error accessing SQL file '.basename($file), $debug);
return $this->load_sql($schema, $prefix, $abort, $debug);
}
......@@ -45,21 +45,20 @@ Class SetupWizard {
function load_sql($schema, $prefix, $abort=true, $debug=false) {
# Strip comments and remarks
$schema=preg_replace('%^\s*(#|--).*$%m','',$schema);
$schema=preg_replace('%^\s*(#|--).*$%m', '', $schema);
# Replace table prefis
$schema = str_replace('%TABLE_PREFIX%',$prefix, $schema);
$schema = str_replace('%TABLE_PREFIX%', $prefix, $schema);
# Split by semicolons - and cleanup
if(!($statements = array_filter(array_map('trim', @explode(';', $schema)))))
return $this->abort('Error parsing SQL schema');
return $this->abort('Error parsing SQL schema', $debug);
@mysql_query('SET SESSION SQL_MODE =""');
foreach($statements as $k=>$sql) {
if(!mysql_query($sql)) {
if($debug) echo "[$sql]=>".mysql_error();
if($abort)
return $this->abort("[$sql] - ".mysql_error());
}
if(mysql_query($sql)) continue;
$error = "[$sql] ".mysql_error();
if($abort)
return $this->abort($error, $debug);
}
return true;
......@@ -82,7 +81,7 @@ Class SetupWizard {
}
function check_php() {
return (version_compare(PHP_VERSION,$this->getPHPVersion())>=0);
return (version_compare(PHP_VERSION, $this->getPHPVersion())>=0);
}
function check_mysql() {
......@@ -96,8 +95,9 @@ Class SetupWizard {
/*
@error is a mixed var.
*/
function abort($error) {
function abort($error, $debug=false) {
if($debug) echo $error;
$this->onError($error);
return false; // Always false... It's an abort.
......@@ -106,13 +106,12 @@ Class SetupWizard {
function setError($error) {
if($error && is_array($error))
$this->errors = array_merge($this->errors,$error);
$this->errors = array_merge($this->errors, $error);
elseif($error)
$this->errors[] = $error;
}
function getErrors(){
return $this->errors;
}
......
......@@ -50,6 +50,8 @@ class Upgrader extends SetupWizard {
}
function onError($error) {
Sys::log(LOG_ERR, 'Upgrader Error', $error);
$this->setError($error);
$this->setState('aborted');
}
......@@ -197,18 +199,23 @@ class Upgrader extends SetupWizard {
if (!$this->load_sql_file($patch, $this->getTablePrefix()))
return false;
//TODO: Log the upgrade
//clear previous patch info -
unset($_SESSION['ost_upgrader'][$this->getShash()]);
//Load up post-upgrade tasks.... if any.
$phash = substr(basename($patch), 0, 17);
//Log the patch info
$logMsg = "Patch $phash applied ";
if(($info = $this->readPatchInfo($patch)) && $info['version'])
$logMsg.= ' ('.$info['version'].') ';
Sys::log(LOG_DEBUG, 'Upgrader - Patch applied', $logMsg);
//Check if the said patch has scripted tasks
if(!($tasks=$this->getTasksForPatch($phash)))
continue;
//We have tasks to perform - set the tasks and break.
//We have work to do... set the tasks and break.
$shash = substr($phash, 9, 8);
$_SESSION['ost_upgrader'][$shash]['tasks'] = $tasks;
$_SESSION['ost_upgrader'][$shash]['state'] = 'upgrade';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment