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