[BUGFIX] Extbase scheduler task serialization 08/23708/2
authorarjenhoekema <arjenhoekema@gmail.com>
Thu, 5 Sep 2013 07:49:11 +0000 (09:49 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 9 Sep 2013 19:48:52 +0000 (21:48 +0200)
When using Command Controllers as scheduled tasks the Extbase
Scheduled Task is serialized. Some singleton properties like
'objectManager', 'commandManager' and 'taskExecutor' are serialized
leading to duplicates of this objects.

Added magic "__sleep" and "__wakeup" methods destructing and
re-constructing the above objects.

Resolves: #50723
Releases: 6.2, 6.1, 6.0
Change-Id: I0a84487a1d8885f75dd4b4eaf004bb0dc93645c2
Reviewed-on: https://review.typo3.org/23708
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/extbase/Classes/Scheduler/Task.php

index 5b6c26c..1b59e3b 100644 (file)
@@ -73,6 +73,30 @@ class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
        }
 
        /**
+        * Sleep
+        *
+        * @return array Properties to serialize
+        */
+       public function __sleep() {
+               $properties = get_object_vars($this);
+               unset($properties['commandManager']);
+               unset($properties['objectManager']);
+               unset($properties['taskExecutor']);
+               return array_keys($properties);
+       }
+
+       /**
+        * Wakeup
+        *
+        * @return void
+        */
+       public function __wakeup() {
+               $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $this->commandManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager');
+               $this->taskExecutor = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor');
+       }
+
+       /**
         * Function execute from the Scheduler
         *
         * @return boolean TRUE on successful execution, FALSE on error