[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Scheduler / Task.php
index 1dcc77c..6fbd16c 100644 (file)
@@ -1,28 +1,18 @@
 <?php
 namespace TYPO3\CMS\Extbase\Scheduler;
 
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2011 Claus Due, Wildside A/S <claus@wildside.dk>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+/**
+ * This file is part of the TYPO3 CMS project.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
  *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
 /**
  * Scheduler task to execute CommandController commands
  */
@@ -59,19 +49,50 @@ class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
        protected $taskExecutor;
 
        /**
-        * Function execute from the Scheduler
+        * Instantiates the Object Manager
+        */
+       public function __construct() {
+               parent::__construct();
+               $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');
+       }
+
+       /**
+        * Sleep
         *
-        * @return boolean TRUE on successful execution, FALSE on error
+        * @return array Properties to serialize
         */
-       public function execute() {
+       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
+        */
+       public function execute() {
                try {
                        $this->taskExecutor->execute($this);
                        return TRUE;
                } catch (\Exception $e) {
-                       \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), $this->commandIdentifier, 3);
+                       $this->logException($e);
                        return FALSE;
                }
        }
@@ -124,7 +145,7 @@ class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
         */
        public function addDefaultValue($argumentName, $argumentValue) {
                if (is_bool($argumentValue)) {
-                       $argumentValue = intval($argumentValue);
+                       $argumentValue = (int)$argumentValue;
                }
                $this->defaults[$argumentName] = $argumentValue;
        }
@@ -147,6 +168,11 @@ class Task extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
                }
                return $label;
        }
-}
 
-?>
\ No newline at end of file
+       /**
+        * @param \Exception $e
+        */
+       protected function logException(\Exception $e) {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), $this->commandIdentifier, 3);
+       }
+}