Fixed bug #12177: Scheduler: Corrected situation where a new single task with a creat...
authorFrancois Suter <francois.suter@typo3.org>
Tue, 20 Oct 2009 19:52:34 +0000 (19:52 +0000)
committerFrancois Suter <francois.suter@typo3.org>
Tue, 20 Oct 2009 19:52:34 +0000 (19:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6194 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/scheduler/class.tx_scheduler_execution.php
typo3/sysext/scheduler/class.tx_scheduler_task.php

index 11299e7..dc417d6 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2009-10-20  Francois Suter  <francois@typo3.org>
 
        * Added feature #12187: Added more usage of flashmessages to EM (thanks to Steffen Gebert)
+       * Fixed bug #12177: Scheduler: Corrected situation where a new single task with a creation date in the past would never run (thanks to Ingmar Schlecht)
 
 2009-10-20  Steffen Kamper  <info@sk-typo3.de>
 
index 311c581..31f1038 100644 (file)
@@ -63,7 +63,7 @@ class tx_scheduler_Execution {
         *
         * @var boolean $multiple
         */
-       protected $multiple = false;
+       protected $multiple = FALSE;
 
        /**
         * The cron command string of this task,
@@ -72,6 +72,15 @@ class tx_scheduler_Execution {
         */
        protected $cronCmd;
 
+       /**
+        * This flag is used to mark a new single execution
+        * See explanations in method setIsNewSingleExecution()
+        *
+        * @var boolean         $isNewSingleExecution
+        * @see tx_scheduler_Execution::setIsNewSingleExecution()
+        */
+       protected $isNewSingleExecution = FALSE;
+
 
        /**********************************
         * Setters and getters
@@ -172,6 +181,32 @@ class tx_scheduler_Execution {
                return $this->cronCmd;
        }
 
+       /**
+        * Set whether this is a newly created single execution.
+        * This is necessary for the following reason: if a new single-running task
+        * is created and its start date is in the past (even for only a few seconds),
+        * the next run time calculation (which happens upon saving) will disable
+        * that task, because it was meant to run only once and is in the past.
+        * Setting this flag to true preserves this task for a single run.
+        * Upon next execution, this flag is set to false.
+        *
+        * @param       boolean         Is newly created single execution?
+        * @return      void
+        * @see tx_scheduler_Execution::getNextExecution()
+        */
+       public function setIsNewSingleExecution($isNewSingleExecution) {
+               $this->isNewSingleExecution = $isNewSingleExecution;
+       }
+
+       /**
+        * Get whether this is a newly created single execution
+        *
+        * @return      boolean         Is newly created single execution?
+        */
+       public function getIsNewSingleExecution() {
+               return $this->isNewSingleExecution;
+       }
+
        /**********************************
         * Execution calculations and logic
         **********************************/
@@ -183,6 +218,11 @@ class tx_scheduler_Execution {
         */
        public function getNextExecution() {
 
+               if ($this->getIsNewSingleExecution()) {
+                       $this->setIsNewSingleExecution(FALSE);
+                       return $this->start;
+               }
+
                if (!$this->isEnded()) {
                                // If the schedule has not yet run out, find out the next date
 
@@ -245,7 +285,7 @@ class tx_scheduler_Execution {
        public function isEnded() {
                if (empty($this->end)) {
                                // If no end is defined, the schedule never ends
-                       $result = false;
+                       $result = FALSE;
                } else {
                                // Otherwise check if end is in the past
                        $result = $this->end < time();
index 4358e8a..2c5e912 100755 (executable)
@@ -196,6 +196,7 @@ abstract class tx_scheduler_Task {
                $execution->setEnd($timestamp);
                $execution->setCronCmd('');
                $execution->setMultiple(0);
+               $execution->setIsNewSingleExecution(TRUE);
                        // Replace existing execution object
                $this->execution = $execution;
        }