[BUGFIX] Log exception as array instead of serialized 36/42736/2
authorStephan Großberndt <stephan@grossberndt.de>
Tue, 18 Aug 2015 14:54:05 +0000 (16:54 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 18 Aug 2015 22:46:08 +0000 (00:46 +0200)
Log exceptions thrown by scheduler tasks as array instead of
serializing the whole exception in order to keep the size down.

Resolves: #69157
Releases: master, 6.2
Change-Id: Ifc6457f3de114779a522baa77443e5019f0dc4c1
Reviewed-on: http://review.typo3.org/42736
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/Classes/Task/AbstractTask.php

index d76e93d..293d5b0 100644 (file)
@@ -1126,13 +1126,12 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                                                $failureOutput = '';
                                                if (!empty($schedulerRecord['lastexecution_failure'])) {
                                                        // Try to get the stored exception object
-                                                       /** @var $exception \Exception */
-                                                       $exception = @unserialize($schedulerRecord['lastexecution_failure']);
-                                                       // If the exception could not be unserialized, issue a default error message
-                                                       if ($exception === FALSE || $exception instanceof \__PHP_Incomplete_Class) {
+                                                       /** @var $exceptionArray array */
+                                                       $exceptionArray = @unserialize($schedulerRecord['lastexecution_failure']);
+                                                       if (!is_array($exceptionArray) || empty($exceptionArray)) {
                                                                $failureDetail = $GLOBALS['LANG']->getLL('msg.executionFailureDefault');
                                                        } else {
-                                                               $failureDetail = sprintf($GLOBALS['LANG']->getLL('msg.executionFailureReport'), $exception->getCode(), $exception->getMessage());
+                                                               $failureDetail = sprintf($GLOBALS['LANG']->getLL('msg.executionFailureReport'), $exceptionArray['code'], $exceptionArray['message']);
                                                        }
                                                        $failureOutput = ' <img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_failure.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" title="' . htmlspecialchars($failureDetail) . '" />';
                                                }
@@ -1602,4 +1601,4 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                return $GLOBALS['TYPO3_DB'];
        }
 
-}
\ No newline at end of file
+}
index 7b0af8c..13cb3e9 100644 (file)
@@ -426,14 +426,21 @@ abstract class AbstractTask {
                                        // Log failed execution
                                        $logMessage = 'Task failed to execute successfully. Class: ' . get_class($this) . ', UID: ' . $this->taskUid . '. ' . $failure->getMessage();
                                        $this->scheduler->log($logMessage, 1, $failure->getCode());
-                                       $failure = serialize($failure);
+                                       // Do not serialize the complete exception or the trace, this can lead to huge strings > 50MB
+                                       $failureString = serialize(array(
+                                               'code' => $failure->getCode(),
+                                               'message' => $failure->getMessage(),
+                                               'file' => $failure->getFile(),
+                                               'line' => $failure->getLine(),
+                                               'traceString' => $failure->getTraceAsString(),
+                                       ));
                                } else {
-                                       $failure = '';
+                                       $failureString = '';
                                }
                                // Save the updated executions list
                                $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_scheduler_task', 'uid = ' . $this->taskUid, array(
                                        'serialized_executions' => $runningExecutionsSerialized,
-                                       'lastexecution_failure' => $failure
+                                       'lastexecution_failure' => $failureString
                                ));
                        }
                }