Fixed bug #16321: [scheduler] Numeric zero for representation of weekday sunday is...
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 26 Nov 2010 20:58:54 +0000 (20:58 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 26 Nov 2010 20:58:54 +0000 (20:58 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-4@9657 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/scheduler/class.tx_scheduler_croncmd.php
typo3/sysext/scheduler/tests/tx_scheduler_croncmdTest.php

index a41b3b3..4b531b4 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 
 2010-11-26  Christian Kuhn  <lolli@schwarzbu.ch>
 
+       * Fixed bug #16321: [scheduler] Numeric zero for representation of weekday sunday is not accepted (Thanks to Marcus Krause)
        * Fixed bug #16582: [Caching framework] Remove misleading memcached configuration example from config_default
        * Fixed bug #16317: [scheduler] Valid values generated from cron command does not contain integers only (Thanks to Marcus Krause)
 
index a765ae2..d735bd9 100644 (file)
@@ -195,16 +195,23 @@ class tx_scheduler_CronCmd {
                        // Consider special field 'day of week'
                        // @TODO: Implement lists and ranges for day of week (2,3 and 1-5 and */2,3 and 1,1-5/2)
                        // @TODO: Support usage of day names in day of week field ("mon", "sun", etc.)
-               if ((strpos($this->cmd_sections[4], '*') === FALSE && preg_match('/[1-7]{1}/', $this->cmd_sections[4]) !== FALSE)) {
+               if ((strpos($this->cmd_sections[4], '*') === FALSE && preg_match('/[0-7]{1}/', $this->cmd_sections[4]) !== FALSE)) {
                                // Unset days from 'day of month' if * is given
                                // * * * * 1 results to every monday of this month
                                // * * 1,2 * 1 results to every monday, plus first and second day of month
                        if ($this->cmd_sections[2] == '*') {
                                $validDays = array();
                        }
+
+                               // Allow 0 as representation for sunday and convert to 7
+                       $dayOfWeek = $this->cmd_sections[4];
+                       if ($dayOfWeek === '0') {
+                               $dayOfWeek = '7';
+                       }
+
                                // Get list
                        for ($i = 1; $i <= $max_days; $i++) {
-                               if (strftime('%u', mktime(0, 0, 0, $currentMonth, $i, $currentYear)) == $this->cmd_sections[4]) {
+                               if (strftime('%u', mktime(0, 0, 0, $currentMonth, $i, $currentYear)) == $dayOfWeek) {
                                        if (!in_array($i, $validDays)) {
                                                $validDays[] = $i;
                                        }
index fbb5fad..9cd6c9b 100644 (file)
@@ -189,6 +189,38 @@ class tx_scheduler_croncmdTest extends tx_phpunit_testcase {
        }
 
        /**
+        * @test
+        */
+       public function weekdayPartCorrectlyParsesZeroAsSunday() {
+               $cronCmdInstance = t3lib_div::makeInstance('tx_scheduler_cronCmd', '0 0 * * 0', self::TIMESTAMP);
+               $expectedResult = array(
+                       '0' => 3,
+                       '1' => 10,
+                       '2' => 17,
+                       '3' => 24,
+                       '4' => 31,
+               );
+               $actualResult = $cronCmdInstance->valid_values;
+               $this->assertEquals($expectedResult, $actualResult[2]);
+       }
+
+       /**
+        * @test
+        */
+       public function weekdayPartCorrectlyParsesSevenAsSunday() {
+               $cronCmdInstance = t3lib_div::makeInstance('tx_scheduler_cronCmd', '0 0 * * 7', self::TIMESTAMP);
+               $expectedResult = array(
+                       '0' => 3,
+                       '1' => 10,
+                       '2' => 17,
+                       '3' => 24,
+                       '4' => 31,
+               );
+               $actualResult = $cronCmdInstance->valid_values;
+               $this->assertEquals($expectedResult, $actualResult[2]);
+       }
+
+       /**
         * Tests whether dayList is correctly calculated for a combination of day of month and day of weeks
         *
         * @test