CRM-16500 - Added more options to job frequency to make it more useable
authorBrianDombrowski <bdombro@gmail.com>
Wed, 13 May 2015 15:41:13 +0000 (11:41 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 Jul 2015 13:28:17 +0000 (09:28 -0400)
----------------------------------------
* CRM-16500: Add more common options to scheduled job frequency
  https://issues.civicrm.org/jira/browse/CRM-16500

CRM/Core/ScheduledJob.php
CRM/Core/SelectValues.php

index 23038e48a6d05f659f05eeea707e3209e8c98cc8..434b8613e9a7198a8832e5d1c49442e800992e0f 100644 (file)
@@ -107,6 +107,36 @@ class CRM_Core_ScheduledJob {
       case 'Daily':
         $format = 'Ymd';
         break;
+
+      case 'Mondays':
+        $now = CRM_Utils_Date::currentDBDate();
+        $dayAgo = strtotime('-1 day', strtotime($now));
+        $lastRun = strtotime($this->last_run);
+        $nowDayOfWeek = date('l',strtotime($now));
+        if ($lastRun < $dayAgo and $nowDayOfWeek=='Monday') {
+          return TRUE;
+        }
+
+      case '1stOfMth':
+        $now = CRM_Utils_Date::currentDBDate();
+        $dayAgo = strtotime('-1 day', strtotime($now));
+        $lastRun = strtotime($this->last_run);
+        $nowDayOfMonth = date('j',strtotime($now));
+        if ($lastRun < $dayAgo and $nowDayOfMonth=='1') {
+          return TRUE;
+        }
+
+      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');
+        if ($lastRun < $dayAgo and $nowDayOfMonth=='13' and in_array($nowMonth,$qtrMonths)) {
+          return TRUE;
+        }
+
     }
 
     $now = CRM_Utils_Date::currentDBDate();
index 0f77050577bfcaa81c015207ce4d2b0e7ca26587..6c2a9fb5380b6b31f038754d1667856b2660497a 100644 (file)
@@ -873,6 +873,9 @@ 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'),
       'Daily' => ts('Daily'),
       'Hourly' => ts('Hourly'),
       'Always' => ts('Every time cron job is run'),