[BUGFIX] Avoid fatal error in scheduler 18/57118/2
authorBenni Mack <benni@typo3.org>
Mon, 4 Jun 2018 06:48:01 +0000 (08:48 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 4 Jun 2018 18:56:26 +0000 (20:56 +0200)
The scheduler object cleans up execution
arrays on instantiation. Due to the PSR-3
refactoring, the logger is instantiated
after the constructor is called - resulting
in a fatal error ("Call to member function info()
on null") when cleaning up the execution array.

The patch manually instantiates a logger if
there isn't one already.

Resolves: #85148
Releases: master
Change-Id: I5ff3a06a2b9d7e511d5d243df545359a48bf84b1
Reviewed-on: https://review.typo3.org/57118
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.de>
Tested-by: Daniel Gorges <daniel.gorges@b13.de>
Reviewed-by: Steffen Frese <steffenf14@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/scheduler/Classes/Scheduler.php

index 4bc03bd..d8d8f2c 100644 (file)
@@ -16,10 +16,12 @@ namespace TYPO3\CMS\Scheduler;
 
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
+use Psr\Log\LoggerInterface;
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
+use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -447,6 +449,11 @@ class Scheduler implements SingletonInterface, LoggerAwareInterface
      */
     public function log($message, $status = 0, $code = '')
     {
+        // this method could be called from the constructor (via "cleanExecutionArrays") and no logger is instantiated
+        // by then, that's why check if the logger is available
+        if (!($this->logger instanceof LoggerInterface)) {
+            $this->setLogger(GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__));
+        }
         $message = trim('[scheduler]: ' . $code) . ' - ' . $message;
         switch ((int)$status) {
             // error (user problem)