[BUGFIX] Log exception as array instead of serialized 17/42717/3
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:23:00 +0000 (00:23 +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/42717
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
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 b54826a..e855f28 100644 (file)
@@ -1086,13 +1086,13 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                                                // Check if the last run failed
                                                if (!empty($schedulerRecord['lastexecution_failure'])) {
                                                        // Try to get the stored exception object
-                                                       /** @var $exception \Exception */
-                                                       $exception = @unserialize($schedulerRecord['lastexecution_failure']);
+                                                       /** @var $exceptionArray array */
+                                                       $exceptionArray = @unserialize($schedulerRecord['lastexecution_failure']);
                                                        // If the exception could not be unserialized, issue a default error message
-                                                       if ($exception === FALSE || $exception instanceof \__PHP_Incomplete_Class) {
+                                                       if (!is_array($exceptionArray) || empty($exceptionArray)) {
                                                                $labelDescription = $this->getLanguageService()->getLL('msg.executionFailureDefault');
                                                        } else {
-                                                               $labelDescription = sprintf($this->getLanguageService()->getLL('msg.executionFailureReport'), $exception->getCode(), $exception->getMessage());
+                                                               $labelDescription = sprintf($this->getLanguageService()->getLL('msg.executionFailureReport'), $exceptionArray['code'], $exceptionArray['message']);
                                                        }
                                                        $labels[] = array(
                                                                'class' => 'danger',
index 2c94ba7..7fdf7a9 100644 (file)
@@ -424,14 +424,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
                                ));
                        }
                }