CIVICRM-1223 adopt to the latest When package and handle error when generate recursion
authorPengyi Zhang <pengyi@agileware.com.au>
Wed, 14 Aug 2019 23:32:37 +0000 (09:32 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 3 Oct 2019 08:07:32 +0000 (18:07 +1000)
CRM/Core/BAO/RecurringEntity.php

index daf86a7806e71b1ae71a00c3d7adb7e7cc5b8cc1..57af4051b441a1323cc2868dc90e905c69de340d 100644 (file)
@@ -31,7 +31,7 @@
  * @copyright CiviCRM LLC (c) 2004-2019
  */
 
-require_once 'packages/When/When.php';
+use When\When;
 
 /**
  * Class CRM_Core_BAO_RecurringEntity.
@@ -334,7 +334,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
     $this->generateRecursion();
 
     $recursionDates = [];
-    if (is_a($this->recursion, 'When')) {
+    if (is_a($this->recursion, 'When\When')) {
       $initialCount = CRM_Utils_Array::value('start_action_offset', $this->schedule);
 
       $exRangeStart = $exRangeEnd = NULL;
@@ -344,7 +344,14 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       }
 
       $count = 1;
-      while ($result = $this->recursion->next()) {
+      try {
+        $this->recursion->generateOccurrences();
+      }
+      catch (Exception $e) {
+        CRM_Core_Error::statusBounce($e->getMessage());
+        return $recursionDates;
+      }
+      foreach ($this->recursion->occurrences as $result) {
         $skip = FALSE;
         if ($result == $this->recursion_start_date) {
           // skip the recursion-start-date from the list we going to generate
@@ -1010,7 +1017,8 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
           $repetition_frequency_unit = "dai";
         }
         $repetition_frequency_unit = $repetition_frequency_unit . 'ly';
-        $r->recur($start, $repetition_frequency_unit);
+        $r->startDate($start)
+          ->freq($repetition_frequency_unit);
       }
 
       if ($scheduleReminderDetails['repetition_frequency_interval']) {