Skip to content

Commit

Permalink
[BUGFIX] Exclude logger from serialize on save for scheduler task
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Joerg Boesche authored and bmack committed Dec 21, 2018
1 parent 1bcd1e4 commit 6342c00
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions typo3/sysext/scheduler/Classes/Task/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;

Expand Down Expand Up @@ -99,6 +100,29 @@ public function __construct()
$this->execution = GeneralUtility::makeInstance(Execution::class);
}

/**
* 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
Expand Down

0 comments on commit 6342c00

Please sign in to comment.