Fix reminder error with absolute date
authorJitendra Purohit <purohitjitend@gmail.com>
Sun, 12 Nov 2023 05:45:47 +0000 (11:15 +0530)
committerJitendra Purohit <purohitjitend@gmail.com>
Sun, 12 Nov 2023 05:45:47 +0000 (11:15 +0530)
CRM/Contribute/ActionMapping/ByPage.php
CRM/Contribute/ActionMapping/ByType.php
tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php

index 5cf73dbbb1c0be124f7cff888e3c65adbfd4973d..7254291b8073eaeebaa67518992ac2d930f93bb5 100644 (file)
@@ -78,10 +78,13 @@ class CRM_Contribute_ActionMapping_ByPage extends CRM_Contribute_ActionMapping {
     $query['casContactTableAlias'] = NULL;
 
     // $schedule->start_action_date is user-supplied data. validate.
-    if (!array_key_exists($schedule->start_action_date, $this->getDateFields())) {
+    if (empty($schedule->absolute_date) && !array_key_exists($schedule->start_action_date, $this->getDateFields())) {
       throw new CRM_Core_Exception("Invalid date field");
     }
-    $query['casDateField'] = $schedule->start_action_date;
+    $query['casDateField'] = $schedule->start_action_date ?? '';
+    if (empty($query['casDateField']) && $schedule->absolute_date) {
+      $query['casDateField'] = "'" . CRM_Utils_Type::escape($schedule->absolute_date, 'String') . "'";
+    }
 
     // build where clause
     if (!empty($selectedValues)) {
index 39d8c516548d41f669d3c8cac1ef1737f23ebc78..0434b8f25a447e8a3e1f17f2750c2c2437b2078e 100644 (file)
@@ -119,11 +119,13 @@ class CRM_Contribute_ActionMapping_ByType extends CRM_Contribute_ActionMapping {
     $query['casContactTableAlias'] = NULL;
 
     // $schedule->start_action_date is user-supplied data. validate.
-    if (!array_key_exists($schedule->start_action_date, $this->getDateFields())) {
+    if (empty($schedule->absolute_date) && !array_key_exists($schedule->start_action_date, $this->getDateFields())) {
       throw new CRM_Core_Exception("Invalid date field");
     }
-    $query['casDateField'] = $schedule->start_action_date;
-
+    $query['casDateField'] = $schedule->start_action_date ?? '';
+    if (empty($query['casDateField']) && $schedule->absolute_date) {
+      $query['casDateField'] = "'" . CRM_Utils_Type::escape($schedule->absolute_date, 'String') . "'";
+    }
     // build where clause
     if (!empty($selectedValues)) {
       $query->where("e.financial_type_id IN (@selectedValues)")
index 5387f6c103dee9f17b578805ae03697ea13bb661..10d702c147502a29ded85b0c99a5a9bf053dc7e7 100644 (file)
@@ -162,6 +162,18 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTest {
       ],
     ];
 
+    $cs[] = [
+      '2015-02-02 00:00:00',
+      'addAliceDues addBobDonation scheduleForDonationWithAbsoluteDate useHelloFirstName',
+      [
+        [
+          'time' => '2015-02-02 00:00:00',
+          'to' => ['bob@example.org'],
+          'subject' => '/Hello, Bob.*via subject/',
+        ],
+      ],
+    ];
+
     $cs[] = [
       '2015-02-03 00:00:00',
       'addAliceDues addBobDonation scheduleForSoftCreditor startWeekAfter useHelloFirstName',
@@ -248,6 +260,16 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTest {
     $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL);
   }
 
+  /**
+   * Schedule message delivery for contribution with an absolute date.
+   */
+  public function scheduleForDonationWithAbsoluteDate(): void {
+    $this->schedule->mapping_id = 'contribtype';
+    $this->schedule->absolute_date = date('Y-m-d', strtotime($this->targetDate));
+    $this->schedule->entity_value = CRM_Utils_Array::implodePadded([2]);
+    $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL);
+  }
+
   /**
    * Schedule message delivery for any contribution, regardless of type.
    */