Skip to content

Commit

Permalink
Fix reminder error with absolute date
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendrapurohit committed Nov 12, 2023
1 parent e2976d9 commit 68b7f7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
7 changes: 5 additions & 2 deletions CRM/Contribute/ActionMapping/ByPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ public function createQuery($schedule, $phase, $defaultParams): CRM_Utils_SQL_Se
$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)) {
Expand Down
8 changes: 5 additions & 3 deletions CRM/Contribute/ActionMapping/ByType.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ public function createQuery($schedule, $phase, $defaultParams): CRM_Utils_SQL_Se
$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)")
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public function createTestCases(): array {
],
];

$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',
Expand Down Expand Up @@ -248,6 +260,16 @@ public function scheduleForDonation(): void {
$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.
*/
Expand Down

0 comments on commit 68b7f7e

Please sign in to comment.