From 679b6d91de500f02ca03131760a80837a51d3068 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Wed, 25 Apr 2012 18:53:42 -0400 Subject: [PATCH] Add error logging to upgrader --- setup/inc/class.setup.php | 25 ++++++++++++------------- setup/inc/class.upgrader.php | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/setup/inc/class.setup.php b/setup/inc/class.setup.php index 34bc57486..cd1ef81f4 100644 --- a/setup/inc/class.setup.php +++ b/setup/inc/class.setup.php @@ -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; } diff --git a/setup/inc/class.upgrader.php b/setup/inc/class.upgrader.php index 9e208426f..73af7e606 100644 --- a/setup/inc/class.upgrader.php +++ b/setup/inc/class.upgrader.php @@ -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'; -- GitLab