[BUGFIX] Exclude logger from serialize on save for scheduler task 37/59237/4
authorJoerg Boesche <typo3@joergboesche.de>
Thu, 20 Dec 2018 10:57:32 +0000 (11:57 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 21 Dec 2018 09:33:42 +0000 (10:33 +0100)
Exclusion of the logger instance from the record during save to database.
Prevent hard-coded logfile paths in database record.
Set the logger at runtime if the task is executed.

Resolves: #86785
Releases: master, 9.5
Change-Id: I30cf258042a2ca6ec3e79a52dcf3a3849cfbe77d
Reviewed-on: https://review.typo3.org/59237
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Chris Müller <typo3@krue.ml>
Tested-by: Chris Müller <typo3@krue.ml>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/9.5.x/Important-86785-CallingSchedulerTaskThrowsLoggerError.rst [new file with mode: 0644]
typo3/sysext/scheduler/Classes/Task/AbstractTask.php

diff --git a/typo3/sysext/core/Documentation/Changelog/9.5.x/Important-86785-CallingSchedulerTaskThrowsLoggerError.rst b/typo3/sysext/core/Documentation/Changelog/9.5.x/Important-86785-CallingSchedulerTaskThrowsLoggerError.rst
new file mode 100644 (file)
index 0000000..84d0ada
--- /dev/null
@@ -0,0 +1,24 @@
+.. include:: ../../Includes.txt
+
+=========================================================================================
+Important: #86785 - Calling scheduler command on CLI throws error if not in /var/www/html
+=========================================================================================
+
+See :issue:`86785`
+
+Description
+===========
+
+Calling the scheduler command on CLI or in backend throws an error, if the TYPO3 CMS installation is not running in @/var/www/html/@.
+
+After saving the scheduler task, the logger instance is serialized to the database with absolute paths (FileWriter::class).
+Exclusion of the logger instance from the record during save to database.
+
+Impact
+======
+
+The stored and serialized tasks from upgraded TYPO3 instances and new saved tasks still work as before.
+The logger instance is initialized while running the scheduler task and is not saved to the serialized task
+object anymore. The logger (FileWriter::class) can open and write the log file to the current environment paths.
+
+.. index:: Backend, ext:scheduler, NotScanned
index d488c84..fdaa290 100644 (file)
@@ -19,6 +19,7 @@ use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Scheduler\Execution;
 
@@ -100,6 +101,29 @@ abstract class AbstractTask implements LoggerAwareInterface
     }
 
     /**
+     * Restore logger after save to database
+     */
+    public function __wakeup()
+    {
+        if ($this->logger === null) {
+            $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
+        }
+    }
+
+    /**
+     * Prevent several objects from being serialized.
+     * Logger does not need to be saved to task
+     * @return array
+     */
+    public function __sleep()
+    {
+        $vars = get_object_vars($this);
+        unset($vars['logger']);
+
+        return array_keys($vars);
+    }
+
+    /**
      * This is the main method that is called when a task is executed
      * It MUST be implemented by all classes inheriting from this one
      * Note that there is no error handling, errors and failures are expected