From fc60e83f2c0acdcceac4a08f5e7e4d086dfb86d8 Mon Sep 17 00:00:00 2001
From: Francois Suter <francois.suter@typo3.org>
Date: Sun, 16 Jan 2011 20:43:26 +0000
Subject: [PATCH] Fixed bug #17070: Scheduler: BE module does not use new cron
 parser

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10092 709f56b5-9817-0410-a4d7-c38de5d9e867
---
 ChangeLog                             |  1 +
 typo3/sysext/scheduler/mod1/index.php | 49 +++++++++++++++------------
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0fd013131faa..4c51bd441107 100755
--- 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>
 
diff --git a/typo3/sysext/scheduler/mod1/index.php b/typo3/sysext/scheduler/mod1/index.php
index 691b2fb0b65a..43b21a06f0b4 100755
--- a/typo3/sysext/scheduler/mod1/index.php
+++ b/typo3/sysext/scheduler/mod1/index.php
@@ -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;
+				}
 			}
 		}
 
-- 
GitLab