From 68b7f7ecd99f88e803e100700f4ae4b3c74a2c46 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Sun, 12 Nov 2023 11:15:47 +0530 Subject: [PATCH] Fix reminder error with absolute date --- CRM/Contribute/ActionMapping/ByPage.php | 7 ++++-- CRM/Contribute/ActionMapping/ByType.php | 8 ++++--- .../Contribute/ActionMapping/ByTypeTest.php | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CRM/Contribute/ActionMapping/ByPage.php b/CRM/Contribute/ActionMapping/ByPage.php index 5cf73dbbb1..7254291b80 100644 --- a/CRM/Contribute/ActionMapping/ByPage.php +++ b/CRM/Contribute/ActionMapping/ByPage.php @@ -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)) { diff --git a/CRM/Contribute/ActionMapping/ByType.php b/CRM/Contribute/ActionMapping/ByType.php index 39d8c51654..0434b8f25a 100644 --- a/CRM/Contribute/ActionMapping/ByType.php +++ b/CRM/Contribute/ActionMapping/ByType.php @@ -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)") diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index 5387f6c103..10d702c147 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -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. */ -- 2.25.1