CRM-17028: Yearly and Monthly Repeat Reminders send on every cron for 24 hours
authoryashodha <yashodha.chaku@webaccessglobal.com>
Tue, 27 Oct 2015 09:46:30 +0000 (15:16 +0530)
committeryashodha <yashodha.chaku@webaccessglobal.com>
Tue, 27 Oct 2015 09:46:30 +0000 (15:16 +0530)
----------------------------------------
* CRM-17028: Yearly and Monthly Repeat Reminders send on every cron for 24 hours
  https://issues.civicrm.org/jira/browse/CRM-17028

CRM/Core/BAO/ActionSchedule.php

index 667f3b4d32d133bd60f2ffd1968d6ee461aa4cb9..6c1c763973814f031e16f93b7d98a88b67a3ae06 100755 (executable)
@@ -1337,25 +1337,25 @@ GROUP BY c.id
         $repeatEvent = ($actionSchedule->end_action == 'before' ? 'DATE_SUB' : 'DATE_ADD') . "({$dateField}, INTERVAL {$actionSchedule->end_frequency_interval} {$actionSchedule->end_frequency_unit})";
 
         if ($actionSchedule->repetition_frequency_unit == 'day') {
-          $hrs = 24 * $actionSchedule->repetition_frequency_interval;
+          $interval = "{$actionSchedule->repetition_frequency_interval} DAY";
         }
         elseif ($actionSchedule->repetition_frequency_unit == 'week') {
-          $hrs = 24 * $actionSchedule->repetition_frequency_interval * 7;
+          $interval = "{$actionSchedule->repetition_frequency_interval} WEEK";
         }
         elseif ($actionSchedule->repetition_frequency_unit == 'month') {
-          $hrs = "24*(DATEDIFF(DATE_ADD(latest_log_time, INTERVAL 1 MONTH ), latest_log_time))";
+          $interval = "{$actionSchedule->repetition_frequency_interval} MONTH";
         }
         elseif ($actionSchedule->repetition_frequency_unit == 'year') {
-          $hrs = "24*(DATEDIFF(DATE_ADD(latest_log_time, INTERVAL 1 YEAR ), latest_log_time))";
+          $interval = "{$actionSchedule->repetition_frequency_interval} YEAR";
         }
         else {
-          $hrs = $actionSchedule->repetition_frequency_interval;
+          $interval = "{$actionSchedule->repetition_frequency_interval} HOUR";
         }
 
         // (now <= repeat_end_time )
         $repeatEventClause = "'{$now}' <= {$repeatEvent}";
         // diff(now && logged_date_time) >= repeat_interval
-        $havingClause = "HAVING TIMEDIFF({$now}, latest_log_time) >= TIME('{$hrs}:00:00')";
+        $havingClause = "HAVING TIMESTAMPDIFF(HOUR, latest_log_time, CAST({$now} AS datetime)) >= TIMESTAMPDIFF(HOUR, latest_log_time, DATE_ADD(latest_log_time, INTERVAL $interval))";
         $groupByClause = 'GROUP BY reminder.contact_id, reminder.entity_id, reminder.entity_table';
         $selectClause .= ', MAX(reminder.action_date_time) as latest_log_time';
         //CRM-15376 - do not send our reminders if original criteria no longer applies