Skip to content
Extraits de code Groupes Projets
Valider 77ea9ff1 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Fixes #4263, fix bug in weekly scheduled time period and fix bugs in last commit.

parent d1b65966
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -88,14 +88,12 @@ class ScheduledTaskTimetable ...@@ -88,14 +88,12 @@ class ScheduledTaskTimetable
* - the task has to be executed * - the task has to be executed
* - the task has never been scheduled before * - the task has never been scheduled before
* *
* @param ScheduledTask $task * @param string $taskName
* *
* @return boolean * @return boolean
*/ */
public function taskShouldBeRescheduled($task) public function taskShouldBeRescheduled($taskName)
{ {
$taskName = $task->getName();
return !$this->taskHasBeenScheduledOnce($taskName) || $this->shouldExecuteTask($taskName); return !$this->taskHasBeenScheduledOnce($taskName) || $this->shouldExecuteTask($taskName);
} }
......
...@@ -31,30 +31,29 @@ class Weekly extends ScheduledTime ...@@ -31,30 +31,29 @@ class Weekly extends ScheduledTime
{ {
$currentTime = $this->getTime(); $currentTime = $this->getTime();
// Adds 7 days $daysFromNow = 7;
// Adjusts the scheduled day
if ($this->day !== null) {
$daysFromNow = ($this->day - date('N', $currentTime) + 7) % 7;
if ($daysFromNow == 0) {
$daysFromNow = 7;
}
}
// Adds correct number of days
$rescheduledTime = mktime(date('H', $currentTime), $rescheduledTime = mktime(date('H', $currentTime),
date('i', $currentTime), date('i', $currentTime),
date('s', $currentTime), date('s', $currentTime),
date('n', $currentTime), date('n', $currentTime),
date('j', $currentTime) + 7, date('j', $currentTime) + $daysFromNow,
date('Y', $currentTime) date('Y', $currentTime)
); );
// Adjusts the scheduled hour // Adjusts the scheduled hour
$rescheduledTime = $this->adjustHour($rescheduledTime); $rescheduledTime = $this->adjustHour($rescheduledTime);
// Adjusts the scheduled day
if ($this->day !== null) {
// Removes or adds a number of days to set the scheduled day to the one specified with setDay()
$rescheduledTime = mktime(date('H', $rescheduledTime),
date('i', $rescheduledTime),
date('s', $rescheduledTime),
date('n', $rescheduledTime),
date('j', $rescheduledTime) - (date('N', $rescheduledTime) - $this->day),
date('Y', $rescheduledTime)
);
}
return $rescheduledTime; return $rescheduledTime;
} }
......
...@@ -136,7 +136,7 @@ class TaskScheduler extends Singleton ...@@ -136,7 +136,7 @@ class TaskScheduler extends Singleton
$executionResults[] = array('task' => $taskName, 'output' => $message); $executionResults[] = array('task' => $taskName, 'output' => $message);
} }
if ($this->timetable->taskShouldBeRescheduled($task)) { if ($this->timetable->taskShouldBeRescheduled($taskName)) {
$this->timetable->rescheduleTask($task); $this->timetable->rescheduleTask($task);
} }
} }
......
...@@ -650,7 +650,7 @@ class GeoIPAutoUpdater extends ScheduledTask ...@@ -650,7 +650,7 @@ class GeoIPAutoUpdater extends ScheduledTask
private function isAtLeastOneGeoIpDbOutOfDate($rescheduledTime) private function isAtLeastOneGeoIpDbOutOfDate($rescheduledTime)
{ {
$previousScheduledRuntime = $this->getPreviousScheduledTime($rescheduledTime); $previousScheduledRuntime = $this->getPreviousScheduledTime($rescheduledTime)->setTime("00:00:00")->getTimestamp();
foreach (GeoIp::$dbNames as $type => $dbNames) { foreach (GeoIp::$dbNames as $type => $dbNames) {
$dbUrl = Option::get(self::$urlOptions[$type]); $dbUrl = Option::get(self::$urlOptions[$type]);
...@@ -658,7 +658,7 @@ class GeoIPAutoUpdater extends ScheduledTask ...@@ -658,7 +658,7 @@ class GeoIPAutoUpdater extends ScheduledTask
// if there is a URL for this DB type and the GeoIP DB file's last modified time is before // if there is a URL for this DB type and the GeoIP DB file's last modified time is before
// the time the updater should have been previously run, then **the file is out of date** // the time the updater should have been previously run, then **the file is out of date**
if ($dbUrl !== false if (!empty($dbUrl)
&& filemtime($dbPath) < $previousScheduledRuntime && filemtime($dbPath) < $previousScheduledRuntime
) { ) {
return true; return true;
...@@ -673,9 +673,9 @@ class GeoIPAutoUpdater extends ScheduledTask ...@@ -673,9 +673,9 @@ class GeoIPAutoUpdater extends ScheduledTask
$updaterPeriod = Option::get(self::SCHEDULE_PERIOD_OPTION_NAME); $updaterPeriod = Option::get(self::SCHEDULE_PERIOD_OPTION_NAME);
if ($updaterPeriod == 'week') { if ($updaterPeriod == 'week') {
return Date::factory($rescheduledTime)->subWeek(1)->getTimestamp(); return Date::factory($rescheduledTime)->subWeek(1);
} else if ($updaterPeriod == 'month') { } else if ($updaterPeriod == 'month') {
return Date::factory($rescheduledTime)->subMonth(1)->getTimestamp(); return Date::factory($rescheduledTime)->subMonth(1);
} else { } else {
Log::warning("Unknown GeoIP updater period found in database: %s", $updaterPeriod); Log::warning("Unknown GeoIP updater period found in database: %s", $updaterPeriod);
return 0; return 0;
......
...@@ -15,6 +15,7 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase ...@@ -15,6 +15,7 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
public static $_JANUARY_05_1971_09_00_00; public static $_JANUARY_05_1971_09_00_00;
public static $_JANUARY_11_1971_00_00_00; public static $_JANUARY_11_1971_00_00_00;
public static $_JANUARY_15_1971_00_00_00; public static $_JANUARY_15_1971_00_00_00;
public static $_JANUARY_08_1971_00_00_00;
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
...@@ -137,11 +138,11 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase ...@@ -137,11 +138,11 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
{ {
return array( return array(
array(1, self::$_JANUARY_11_1971_00_00_00), array(1, self::$_JANUARY_11_1971_00_00_00),
array(5, self::$_JANUARY_15_1971_00_00_00), array(5, self::$_JANUARY_08_1971_00_00_00),
array('monday', self::$_JANUARY_11_1971_00_00_00), array('monday', self::$_JANUARY_11_1971_00_00_00),
array('Monday', self::$_JANUARY_11_1971_00_00_00), array('Monday', self::$_JANUARY_11_1971_00_00_00),
array('FRIDAY', self::$_JANUARY_15_1971_00_00_00), array('FRIDAY', self::$_JANUARY_08_1971_00_00_00),
array('FrIdAy', self::$_JANUARY_15_1971_00_00_00) array('FrIdAy', self::$_JANUARY_08_1971_00_00_00)
); );
} }
...@@ -172,4 +173,5 @@ ScheduledTime_WeeklyTest::$_JANUARY_04_1971_00_00_00 = mktime(0, 00, 00, 1, 4, 1 ...@@ -172,4 +173,5 @@ ScheduledTime_WeeklyTest::$_JANUARY_04_1971_00_00_00 = mktime(0, 00, 00, 1, 4, 1
ScheduledTime_WeeklyTest::$_JANUARY_04_1971_09_00_00 = mktime(9, 00, 00, 1, 4, 1971); ScheduledTime_WeeklyTest::$_JANUARY_04_1971_09_00_00 = mktime(9, 00, 00, 1, 4, 1971);
ScheduledTime_WeeklyTest::$_JANUARY_05_1971_09_00_00 = mktime(9, 00, 00, 1, 5, 1971); ScheduledTime_WeeklyTest::$_JANUARY_05_1971_09_00_00 = mktime(9, 00, 00, 1, 5, 1971);
ScheduledTime_WeeklyTest::$_JANUARY_11_1971_00_00_00 = mktime(0, 00, 00, 1, 11, 1971); ScheduledTime_WeeklyTest::$_JANUARY_11_1971_00_00_00 = mktime(0, 00, 00, 1, 11, 1971);
ScheduledTime_WeeklyTest::$_JANUARY_15_1971_00_00_00 = mktime(0, 00, 00, 1, 15, 1971); ScheduledTime_WeeklyTest::$_JANUARY_15_1971_00_00_00 = mktime(0, 00, 00, 1, 15, 1971);
\ No newline at end of file ScheduledTime_WeeklyTest::$_JANUARY_08_1971_00_00_00 = mktime(0, 00, 00, 1, 8, 1971);
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter