From aaae95eaa55d9478984ae5c020dd6da52c102b9b Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Fri, 30 Jul 2021 13:56:02 -0400 Subject: [PATCH] fixes event#63: Don't crash scheduled reminders when participant has > 1 role ID --- CRM/Event/ActionMapping.php | 5 ++- tests/phpunit/CRM/Event/ActionMappingTest.php | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/CRM/Event/ActionMappingTest.php diff --git a/CRM/Event/ActionMapping.php b/CRM/Event/ActionMapping.php index 6a7f1ecda1..58569f75eb 100644 --- a/CRM/Event/ActionMapping.php +++ b/CRM/Event/ActionMapping.php @@ -149,8 +149,9 @@ class CRM_Event_ActionMapping extends \Civi\ActionSchedule\Mapping { if ($schedule->recipient_listing && $schedule->limit_to) { switch ($schedule->recipient) { case 'participant_role': - $query->where("e.role_id IN (#recipList)") - ->param('recipList', \CRM_Utils_Array::explodePadded($schedule->recipient_listing)); + $regex = "([[:cntrl:]]|^)" . implode('([[:cntrl:]]|$)|([[:cntrl:]]|^)', (array) $schedule->recipient_listing) . "([[:cntrl:]]|$)"; + $query->where("e.role_id REGEXP (@regex)") + ->param('regex', $regex); break; default: diff --git a/tests/phpunit/CRM/Event/ActionMappingTest.php b/tests/phpunit/CRM/Event/ActionMappingTest.php new file mode 100644 index 0000000000..eef9cc819d --- /dev/null +++ b/tests/phpunit/CRM/Event/ActionMappingTest.php @@ -0,0 +1,42 @@ +participantCreate(['role_id' => [1, 2]]); + $participant = $this->callAPISuccess('participant', 'getsingle', ['id' => $participantId]); + $eventId = $participant['event_id']; + $this->schedule->mapping_id = CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID; + $this->schedule->start_action_date = 'start_date'; + $this->schedule->entity_value = $eventId; + $this->schedule->limit_to = 1; + $this->schedule->recipient_listing = 1; + $this->startWeekBefore(); + $this->useHelloFirstName(); + $this->schedule->save(); + $this->callAPISuccess('job', 'send_reminder', []); + } + +} -- 2.25.1