/** * Check if the specified task should be executed according to the specified * frequency and its last run time. * @param $className string * @param $frequency XMLNode * @return string */ static function checkFrequency($className, $frequency) { $isValid = true; $taskDao = DAORegistry::getDAO('ScheduledTaskDAO'); /* @var $taskDao ScheduledTaskDAO */ $lastRunTime = $taskDao->getLastRunTime($className); // Check day of week $dayOfWeek = $frequency->getAttribute('dayofweek'); if (isset($dayOfWeek)) { $isValid = ScheduledTaskHelper::_isInRange($dayOfWeek, (int) date('w'), $lastRunTime, 'day', strtotime('-1 week')); } if ($isValid) { // Check month $month = $frequency->getAttribute('month'); if (isset($month)) { $isValid = ScheduledTaskHelper::_isInRange($month, (int) date('n'), $lastRunTime, 'month', strtotime('-1 year')); } } if ($isValid) { // Check day $day = $frequency->getAttribute('day'); if (isset($day)) { $isValid = ScheduledTaskHelper::_isInRange($day, (int) date('j'), $lastRunTime, 'day', strtotime('-1 month')); } } if ($isValid) { // Check hour $hour = $frequency->getAttribute('hour'); if (isset($hour)) { $isValid = ScheduledTaskHelper::_isInRange($hour, (int) date('G'), $lastRunTime, 'hour', strtotime('-1 day')); } } if ($isValid) { // Check minute $minute = $frequency->getAttribute('minute'); if (isset($minute)) { $isValid = ScheduledTaskHelper::_isInRange($minute, (int) date('i'), $lastRunTime, 'min', strtotime('-1 hour')); } } return $isValid; }