Fixed bug #17070: Scheduler: BE module does not use new cron parser
authorFrancois Suter <francois.suter@typo3.org>
Sun, 16 Jan 2011 20:43:26 +0000 (20:43 +0000)
committerFrancois Suter <francois.suter@typo3.org>
Sun, 16 Jan 2011 20:43:26 +0000 (20:43 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10092 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/scheduler/mod1/index.php

index 0fd0131..4c51bd4 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
        * Follow-up to #16966: Missing trailing comma in sliding fields list caused SQL error
        * Fixed bug #17068: Scheduler: Improve display of status and additional information
        * Fixed bug #17069: Scheduler: Refresh icon has disappeared
+       * Fixed bug #17070: Scheduler: BE module does not use new cron parser
 
 2011-01-15  Jigal van Hemert  <jigal@xs4all.nl>
 
index 691b2fb..43b21a0 100755 (executable)
@@ -1392,32 +1392,39 @@ class tx_scheduler_Module extends t3lib_SCbase {
 
                        // Check type and validity of frequency, if recurring
                if ($this->submittedData['type'] == 2) {
-                       $parts = t3lib_div::trimExplode(' ', $this->submittedData['frequency']);
-                       $numParts = count($parts);
+                       $frequency = trim($this->submittedData['frequency']);
 
-                       if ($numParts == 0) {
-                                       // No parts, empty frequency, not valid
+                       if (empty($frequency)) {
+                                       // Empty frequency, not valid
 
                                $this->addMessage($GLOBALS['LANG']->getLL('msg.noFrequency'), t3lib_FlashMessage::ERROR);
-                               $result = false;
-                       } else if ($numParts == 1) {
-                                       // One part, assume it is an interval
-                                       // Make sure it has a valid value
-                               $interval = intval($this->submittedData['frequency']);
-                               if ($interval > 0) {
-                                       $this->submittedData['interval'] = $interval;
-                               } else {
-                                       $this->addMessage($GLOBALS['LANG']->getLL('msg.invalidFrequency'), t3lib_FlashMessage::ERROR);
-                                       $result = false;
-                               }
-                       } else if ($numParts == 5) {
-                                       // Five parts, assume it is a valid cron command
-                               $this->submittedData['croncmd'] = $this->submittedData['frequency'];
+                               $result = FALSE;
                        } else {
-                                       // Some other number of parts, assume it is an invalid cron command
+                               $cronErrorCode = 0;
+                               $cronErrorMessage = '';
 
-                               $this->addMessage($GLOBALS['LANG']->getLL('msg.invalidFrequency'), t3lib_FlashMessage::ERROR);
-                               $result = false;
+                                       // Try interpreting the cron command
+                               try {
+                                       tx_scheduler_CronCmd_Normalize::normalize($frequency);
+                                       $this->submittedData['croncmd'] = $frequency;
+                               }
+                                       // If the cron command was invalid, we may still have a valid frequency in seconds
+                               catch (Exception $e) {
+                                               // Store the exception's result
+                                       $cronErrorMessage = $e->getMessage();
+                                       $cronErrorCode = $e->getCode();
+                                               // Check if the frequency is a valid number
+                                               // If yes, assume it is a frequency in seconds, and unset cron error code
+                                       if (is_numeric($frequency)) {
+                                               $this->submittedData['interval'] = intval($frequency);
+                                               unset($cronErrorCode);
+                                       }
+                               }
+                                       // If there's a cron error code, issue validation error message
+                               if (!empty($cronErrorCode)) {
+                                       $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.frequencyError'), $cronErrorMessage, $cronErrorCode), t3lib_FlashMessage::ERROR);
+                                       $result = FALSE;
+                               }
                        }
                }