From: David Reedy Jr Date: Mon, 28 Dec 2015 18:22:20 +0000 (-0600) Subject: CRM-17669 Add new run frequencies to scheduled... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=bda41fcbeaf535ff04d7e5cfc7145e83f50c17b2;p=civicrm-core.git CRM-17669 Add new run frequencies to scheduled... jobs. Also removes run frequencies added in CRM-16500 as they are no longer needed. --- diff --git a/CRM/Core/ScheduledJob.php b/CRM/Core/ScheduledJob.php index 95d0a2c298..6a616d21f1 100644 --- a/CRM/Core/ScheduledJob.php +++ b/CRM/Core/ScheduledJob.php @@ -86,10 +86,33 @@ class CRM_Core_ScheduledJob { $dao->save(); } + /** + * @return void + */ + public function clearNextScheduledRun() { + CRM_Core_DAO::executeQuery('UPDATE civicrm_job SET next_scheduled_run = NULL WHERE id = %1', + array( + '1' => array($this->id, 'Integer'), + )); + } + /** * @return bool */ public function needsRunning() { + + // CRM-17686 + // check if the job has a specific scheduled date/time + if (!empty($this->next_scheduled_run)) { + if (strtotime($this->next_scheduled_run) <= time()) { + $this->clearNextScheduledRun(); + return TRUE; + } + else { + return FALSE; + } + } + // run if it was never run if (empty($this->last_run)) { return TRUE; @@ -100,43 +123,37 @@ class CRM_Core_ScheduledJob { case 'Always': return TRUE; - case 'Hourly': - $format = 'YmdH'; + // CRM-17669 + case 'Yearly': + $offset = '+1 year'; + break; + + case 'Quarter': + $offset = '+3 months'; + break; + + case 'Monthly': + $offset = '+1 month'; + break; + + case 'Weekly': + $offset = '+1 week'; break; case 'Daily': - $format = 'Ymd'; + $offset = '+1 day'; break; - case 'Mondays': - $now = CRM_Utils_Date::currentDBDate(); - $dayAgo = strtotime('-1 day', strtotime($now)); - $lastRun = strtotime($this->last_run); - $nowDayOfWeek = date('l', strtotime($now)); - return ($lastRun < $dayAgo && $nowDayOfWeek == 'Monday'); - - case '1stOfMth': - $now = CRM_Utils_Date::currentDBDate(); - $dayAgo = strtotime('-1 day', strtotime($now)); - $lastRun = strtotime($this->last_run); - $nowDayOfMonth = date('j', strtotime($now)); - return ($lastRun < $dayAgo && $nowDayOfMonth == '1'); - - case '1stOfQtr': - $now = CRM_Utils_Date::currentDBDate(); - $dayAgo = strtotime('-1 day', strtotime($now)); - $lastRun = strtotime($this->last_run); - $nowDayOfMonth = date('j', strtotime($now)); - $nowMonth = date('n', strtotime($now)); - $qtrMonths = array('1', '4', '7', '10'); - return ($lastRun < $dayAgo && $nowDayOfMonth == '13' && in_array($nowMonth, $qtrMonths)); + case 'Hourly': + $offset = '+1 hour'; + break; } - $now = CRM_Utils_Date::currentDBDate(); - $lastTime = date($format, strtotime($this->last_run)); - $thisTime = date($format, strtotime($now)); + $now = strtotime(CRM_Utils_Date::currentDBDate()); + $lastTime = strtotime($this->last_run); + $nextTime = strtotime($offset, $lastTime); - return ($lastTime <> $thisTime); + return ($now >= $nextTime); } public function __destruct() { diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 43dd0dceed..c54b58ea88 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -893,9 +893,12 @@ class CRM_Core_SelectValues { */ public static function getJobFrequency() { return array( - '1stOfQtr' => ts('1st day of every quarter'), - '1stOfMth' => ts('1st day of every month'), - 'Mondays' => ts('Monday of every week'), + // CRM-17669 + 'Yearly' => ts('Yearly'), + 'Quarter' => ts('Quarterly'), + 'Monthly' => ts('Monthly'), + 'Weekly' => ts('Weekly'), + 'Daily' => ts('Daily'), 'Hourly' => ts('Hourly'), 'Always' => ts('Every time cron job is run'),