$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;
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() {
*/
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'),