From f300a7656f2561839df9b7d9ee73ad01c2b78b77 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 12 Aug 2013 18:22:19 +0000 Subject: [PATCH] Always log stuff during upgrades (for real) Anything that would happen after the last patch was applied would never be logged, because the system would immediately indicate that no upgrade was pending. --- include/class.osticket.php | 8 ++++---- include/class.upgrader.php | 17 ++++++++++------- .../streams/core/15b30765-dd0022fb.task.php | 7 +++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/class.osticket.php b/include/class.osticket.php index b877527f0..7d75834d4 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -242,8 +242,8 @@ class osTicket { } - function logDebug($title, $message, $alert=false) { - return $this->log(LOG_DEBUG, $title, $message, $alert); + function logDebug($title, $message, $force=false) { + return $this->log(LOG_DEBUG, $title, $message, false, $force); } function logInfo($title, $message, $alert=false) { @@ -266,7 +266,7 @@ class osTicket { return $this->log(LOG_ERR, $title, $error, $alert); } - function log($priority, $title, $message, $alert=false) { + function log($priority, $title, $message, $alert=false, $force=false) { //We are providing only 3 levels of logs. Windows style. switch($priority) { @@ -292,7 +292,7 @@ class osTicket { $this->alertAdmin($title, $message); //Logging everything during upgrade. - if($this->getConfig()->getLogLevel()<$level && !$this->isUpgradePending()) + if($this->getConfig()->getLogLevel()<$level && !$force) return false; //Save log based on system log level settings. diff --git a/include/class.upgrader.php b/include/class.upgrader.php index 076a00ab5..d0f200040 100644 --- a/include/class.upgrader.php +++ b/include/class.upgrader.php @@ -326,11 +326,10 @@ class StreamUpgrader extends SetupWizard { function doTask() { - global $ost; if(!($task = $this->getTask())) return false; //Nothing to do. - $ost->logDebug( + $this->log( sprintf('Upgrader - %s (task pending).', $this->getShash()), sprintf('The %s task reports there is work to do', get_class($task)) @@ -379,7 +378,7 @@ class StreamUpgrader extends SetupWizard { if(($info = $this->readPatchInfo($patch)) && $info['version']) $logMsg.= ' ('.$info['version'].') '; - $ost->logDebug("Upgrader - $shash applied", $logMsg); + $this->log("Upgrader - $shash applied", $logMsg); $this->signature = $shash; //Update signature to the *new* HEAD $this->phash = $phash; @@ -405,10 +404,14 @@ class StreamUpgrader extends SetupWizard { return true; } - /************* TASKS **********************/ - function cleanup() { + function log($title, $message, $level=LOG_DEBUG) { global $ost; + // Never alert the admin, and force the write to the database + $ost->log($level, $title, $message, false, true); + } + /************* TASKS **********************/ + function cleanup() { $file = $this->getSQLDir().$this->phash.'.cleanup.sql'; if(!file_exists($file)) //No cleanup script. @@ -416,12 +419,12 @@ class StreamUpgrader extends SetupWizard { //We have a cleanup script ::XXX: Don't abort on error? if($this->load_sql_file($file, $this->getTablePrefix(), false, true)) { - $ost->logDebug("Upgrader - {$this->phash} cleanup", + $this->log("Upgrader - {$this->phash} cleanup", "Applied cleanup script {$file}"); return 0; } - $ost->logDebug('Upgrader', sprintf("%s: Unable to process cleanup file", + $this->log('Upgrader', sprintf("%s: Unable to process cleanup file", $this->phash)); return 0; } diff --git a/include/upgrader/streams/core/15b30765-dd0022fb.task.php b/include/upgrader/streams/core/15b30765-dd0022fb.task.php index 6e2739218..bb2df98bd 100644 --- a/include/upgrader/streams/core/15b30765-dd0022fb.task.php +++ b/include/upgrader/streams/core/15b30765-dd0022fb.task.php @@ -153,7 +153,9 @@ class AttachmentMigrater extends MigrationTask { if(!($res=db_query($sql))) return $this->error('Unable to query DB for attached files to migrate!'); - $ost->logDebug("Attachment migration", 'Found '.db_num_rows($res).' attachments to migrate'); + // Force the log message to the database + $ost->logDebug("Attachment migration", 'Found '.db_num_rows($res) + .' attachments to migrate', true); if(!db_num_rows($res)) return 0; //Nothing else to do!! @@ -217,7 +219,8 @@ class AttachmentMigrater extends MigrationTask { $this->errors++; $this->errorList[] = $what; - $ost->logDebug('Upgrader: Attachment Migrater', $what); + // Log the error but don't send the alert email + $ost->logError('Upgrader: Attachment Migrater', $what, false); # Assist in returning FALSE for inline returns with this method return false; } -- GitLab