[BUGFIX] Editing start-/end time of scheduled task not working correctly 60/51960/8
authorThomas Hohn <thomas@hohn.dk>
Mon, 6 Mar 2017 05:41:53 +0000 (06:41 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Mon, 13 Mar 2017 08:37:49 +0000 (09:37 +0100)
The start/end value can now contain either the start-/end time as
unix timestamp or as formatted date when using the datepicker.
In the later case the value must be converted to an unix timestamp
before storing it in the DB.

Resolves: #79814
Related: #77702
Releases: master
Change-Id: I750c1bc6d4634b89423e26a0dea48d2001115f18
Reviewed-on: https://review.typo3.org/51960
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christer V <cvi@systime.dk>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Thomas Maroschik <tmaroschik@dfau.de>
Tested-by: Thomas Maroschik <tmaroschik@dfau.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php

index 7167fad..2502427 100644 (file)
@@ -1343,24 +1343,31 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
         if (empty($this->submittedData['start'])) {
             $this->addMessage($this->getLanguageService()->getLL('msg.noStartDate'), FlashMessage::ERROR);
             $result = false;
-        } else {
+        } elseif (is_string($this->submittedData['start']) && (!is_numeric($this->submittedData['start']))) {
             try {
-                $this->submittedData['start'] = (int)$this->submittedData['start'];
+                $this->submittedData['start'] = $this->convertToTimestamp($this->submittedData['start']);
             } catch (\Exception $e) {
                 $this->addMessage($this->getLanguageService()->getLL('msg.invalidStartDate'), FlashMessage::ERROR);
                 $result = false;
             }
+        } else {
+            $this->submittedData['start'] = (int)$this->submittedData['start'];
         }
         // Check end date, if recurring task
         if ((int)$this->submittedData['type'] === AbstractTask::TYPE_RECURRING && !empty($this->submittedData['end'])) {
-            try {
-                $this->submittedData['end'] = (int)$this->submittedData['end'];
-                if ($this->submittedData['end'] < $this->submittedData['start']) {
-                    $this->addMessage($this->getLanguageService()->getLL('msg.endDateSmallerThanStartDate'), FlashMessage::ERROR);
+            if (is_string($this->submittedData['end']) && (!is_numeric($this->submittedData['end']))) {
+                try {
+                    $this->submittedData['end'] = $this->convertToTimestamp($this->submittedData['end']);
+                } catch (\Exception $e) {
+                    $this->addMessage($this->getLanguageService()->getLL('msg.invalidStartDate'), FlashMessage::ERROR);
                     $result = false;
                 }
-            } catch (\Exception $e) {
-                $this->addMessage($this->getLanguageService()->getLL('msg.invalidEndDate'), FlashMessage::ERROR);
+            } else {
+                $this->submittedData['end'] = (int)$this->submittedData['end'];
+            }
+            if ($this->submittedData['end'] < $this->submittedData['start']) {
+                $this->addMessage($this->getLanguageService()->getLL('msg.endDateSmallerThanStartDate'),
+                    FlashMessage::ERROR);
                 $result = false;
             }
         }
@@ -1412,6 +1419,24 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
         return $result;
     }
 
+    /**
+     * Convert input to DateTime and retrieve timestamp
+     *
+     * @param string $input
+     * @return int
+     *
+     */
+    protected function convertToTimestamp(string $input): int
+    {
+        // Convert to ISO 8601 dates
+        $dateTime = new \DateTime($input);
+        $value = $dateTime->getTimestamp();
+        if ($value !== 0) {
+            $value -= date('Z', $value);
+        }
+        return $value;
+    }
+
     /*************************
      *
      * APPLICATION LOGIC UTILITIES