From 0d6fa54d4a0b35d0334599fd792bef3a758eb691 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 19 Oct 2021 09:41:59 +1300 Subject: [PATCH] Replace call to getTokenDetails with simple contact.get --- CRM/Event/BAO/Participant.php | 8 +++++- CRM/Event/Form/SelfSvcTransfer.php | 16 +++--------- .../ParticipantTransferred.php | 25 +++++++++++++++++++ CRM/Upgrade/Incremental/MessageTemplates.php | 9 +++++++ .../CRM/Event/Form/SelfSvcTransferTest.php | 3 +++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 2 +- .../participant_transferred_html.tpl | 2 +- .../participant_transferred_text.tpl | 6 ++--- 8 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 CRM/Event/WorkflowMessage/ParticipantTransferred.php diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index f32cef2b59..24bd3e3aaf 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1406,12 +1406,18 @@ UPDATE civicrm_participant $participantValues, $eventDetails, $contactDetails, - &$domainValues, + $domainValues, $mailType ) { //send emails. $mailSent = FALSE; + if (!$contactDetails) { + $contactDetails = civicrm_api3('Contact', 'getsingle', [ + 'id' => $participantValues['contact_id'], + 'return' => ['email', 'display_name'], + ]); + } //don't send confirmation mail to additional //since only primary able to confirm registration. if (!empty($participantValues['registered_by_id']) && diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index 8d6a3488ec..c26f468a30 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -458,23 +458,13 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { //get the location info $locParams = ['entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event']; $eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); - //get contact details - $contactIds[$this->_from_contact_id] = $this->_from_contact_id; - list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, - FALSE, FALSE, NULL, [], - 'CRM_Event_BAO_Participant' - ); - foreach ($currentContactDetails as $contactId => $contactValues) { - $contactDetails[$this->_from_contact_id] = $contactValues; - } //send a 'cancelled' email to user, and cc the event's cc_confirm email - $mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_from_participant_id, + CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_from_participant_id, $participantDetails[$this->_from_participant_id], $eventDetails[$this->_event_id], - $contactDetails[$this->_from_contact_id], + NULL, $domainValues, - "Transferred", - "" + 'Transferred' ); $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contact_name]); $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', [1 => $this->_contact_email]); diff --git a/CRM/Event/WorkflowMessage/ParticipantTransferred.php b/CRM/Event/WorkflowMessage/ParticipantTransferred.php new file mode 100644 index 0000000000..5a43314431 --- /dev/null +++ b/CRM/Event/WorkflowMessage/ParticipantTransferred.php @@ -0,0 +1,25 @@ + 'pledge_reminder', 'type' => 'html'], ], ], + [ + 'version' => '5.44.alpha1', + 'upgrade_descriptor' => ts('Use domain and contact tokens instead of smarty values'), + 'label' => ts('Pledge Transferred'), + 'templates' => [ + ['name' => 'participant_transferred', 'type' => 'text'], + ['name' => 'participant_transferred', 'type' => 'html'], + ], + ], ]; } diff --git a/tests/phpunit/CRM/Event/Form/SelfSvcTransferTest.php b/tests/phpunit/CRM/Event/Form/SelfSvcTransferTest.php index 5901112a76..687582b094 100644 --- a/tests/phpunit/CRM/Event/Form/SelfSvcTransferTest.php +++ b/tests/phpunit/CRM/Event/Form/SelfSvcTransferTest.php @@ -17,6 +17,7 @@ class CRM_Event_Form_SelfSvcTransferTest extends CiviUnitTestCase { public function testCancel(): void { $_REQUEST['pid'] = $this->participantCreate(['status_id' => 'Registered']); $_REQUEST['is_backoffice'] = 1; + $this->addLocationBlockToDomain(); $this->individualCreate(['email' => 'new@example.org']); $mut = new CiviMailUtils($this); /* @var CRM_Event_Form_SelfSvcTransfer $form*/ @@ -29,6 +30,8 @@ class CRM_Event_Form_SelfSvcTransferTest extends CiviUnitTestCase { $this->assertStringContainsString('Registration Confirmation - Annual CiviCRM meet - Mr. Anthony', $emails[0]); $this->assertStringContainsString('

Dear Anthony,

Your Event Registration has been Transferred to Anthony Anderson.

', $emails[1]); $this->assertStringContainsString('anthony_anderson@civicrm.org', $emails[1]); + $this->assertStringContainsString('123', $emails[1]); + $this->assertStringContainsString('fixme.domainemail@example.org', $emails[1]); } } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 7336aaf2ae..563c97da8e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -858,7 +858,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { */ public function participantCreate(array $params = []) { if (empty($params['contact_id'])) { - $params['contact_id'] = $this->individualCreate(); + $this->ids['Contact']['participant'] = $params['contact_id'] = $this->individualCreate(); } if (empty($params['event_id'])) { $event = $this->eventCreate(); diff --git a/xml/templates/message_templates/participant_transferred_html.tpl b/xml/templates/message_templates/participant_transferred_html.tpl index fa066e1b8e..a5e2b927a7 100644 --- a/xml/templates/message_templates/participant_transferred_html.tpl +++ b/xml/templates/message_templates/participant_transferred_html.tpl @@ -117,7 +117,7 @@ -

{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions.{/ts}

+

{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions.{/ts}

diff --git a/xml/templates/message_templates/participant_transferred_text.tpl b/xml/templates/message_templates/participant_transferred_text.tpl index dc2288b56d..5c62b00570 100644 --- a/xml/templates/message_templates/participant_transferred_text.tpl +++ b/xml/templates/message_templates/participant_transferred_text.tpl @@ -29,17 +29,17 @@ {ts}Email{/ts}: {$eventEmail.email}{/if}{/foreach} {/if} -{if $contact.email} +{if '{contact.email}'} =========================================================== {ts}Registered Email{/ts} =========================================================== -{$contact.email} +{contact.email} {/if} {if $register_date} {ts}Registration Date{/ts}: {$participant.register_date|crmDate} {/if} -{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions.{/ts} +{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions.{/ts} -- 2.25.1