From 0395b6a5afab1f5c705c5b910bf804db5c55c70c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 24 Jul 2023 14:26:35 +1200 Subject: [PATCH] Update Group Subscribe message to use frontend_title --- CRM/Mailing/Event/BAO/MailingEventSubscribe.php | 12 ++++-------- CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl | 6 ++++++ CRM/Utils/Token.php | 3 +++ Civi/Test/ContactTestTrait.php | 1 + .../civicrm_mailing_component.sqldata.php | 2 +- sql/civicrm_generated.mysql | 2 +- tests/phpunit/api/v3/MailingGroupTest.php | 2 ++ 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CRM/Mailing/Event/BAO/MailingEventSubscribe.php b/CRM/Mailing/Event/BAO/MailingEventSubscribe.php index 30af618b88..5fbcf34872 100644 --- a/CRM/Mailing/Event/BAO/MailingEventSubscribe.php +++ b/CRM/Mailing/Event/BAO/MailingEventSubscribe.php @@ -189,10 +189,6 @@ SELECT civicrm_email.id as email_id ] ) . "@$emailDomain"; - $group = new CRM_Contact_BAO_Group(); - $group->id = $this->group_id; - $group->find(TRUE); - $component = new CRM_Mailing_BAO_MailingComponent(); $component->is_default = 1; $component->is_active = 1; @@ -227,8 +223,8 @@ SELECT civicrm_email.id as email_id $bao->body_html = $html; $templates = $bao->getTemplates(); - $html = CRM_Utils_Token::replaceSubscribeTokens($templates['html'], $group->title, $url, TRUE); - $text = CRM_Utils_Token::replaceSubscribeTokens($templates['text'], $group->title, $url, FALSE); + $html = str_replace('{subscribe.url}', $url, $templates['html']); + $text = str_replace('{subscribe.url}', $url, $templates['text']); // render the & entities in text mode, so that the links work $text = str_replace('&', '&', $text); @@ -236,12 +232,12 @@ SELECT civicrm_email.id as email_id $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ 'controller' => __CLASS__, 'smarty' => FALSE, - 'schema' => ['contactId'], + 'schema' => ['contactId', 'groupId'], ]); $tokenProcessor->addMessage('body_html', $html, 'text/html'); $tokenProcessor->addMessage('body_text', $text, 'text/plain'); - $tokenProcessor->addRow(['contactId' => $this->contact_id]); + $tokenProcessor->addRow(['contactId' => $this->contact_id, 'groupId' => $this->group_id]); $tokenProcessor->evaluate(); $html = $tokenProcessor->getRow(0)->render('body_html'); $text = $tokenProcessor->getRow(0)->render('body_text'); diff --git a/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl index ec037c2896..2ac634fee9 100644 --- a/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl @@ -35,6 +35,12 @@ SET body_html = REPLACE(body_html, '{welcome.group}', '{group.frontend_title}'), body_text = REPLACE(body_text, '{welcome.group}', '{group.frontend_title}'), subject = REPLACE(subject, '{welcome.group}', '{group.frontend_title}') WHERE component_type = 'Welcome'; + +UPDATE civicrm_mailing_component +SET body_html = REPLACE(body_html, '{subscribe.group}', '{group.frontend_title}'), +body_text = REPLACE(body_text, '{subscribe.group}', '{group.frontend_title}'), +subject = REPLACE(subject, '{subscribe.group}', '{group.frontend_title}') +WHERE component_type = 'Subscribe'; {/literal} UPDATE `civicrm_location_type` SET `is_reserved` = 0 WHERE `is_reserved` IS NULL; diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 77ad4c9c87..f2ef5ce995 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -860,6 +860,8 @@ class CRM_Utils_Token { /** * Replace subscription-confirmation-request tokens * + * @deprecated + * * @param string $str * The string with tokens to be replaced. * @param string $group @@ -872,6 +874,7 @@ class CRM_Utils_Token { * The processed string */ public static function &replaceSubscribeTokens($str, $group, $url, $html) { + CRM_Core_Error::deprecatedFunctionWarning('use token processor'); if (self::token_match('subscribe', 'group', $str)) { self::token_replace('subscribe', 'group', $group, $str); } diff --git a/Civi/Test/ContactTestTrait.php b/Civi/Test/ContactTestTrait.php index 3d752d8e3a..4f0410bea5 100644 --- a/Civi/Test/ContactTestTrait.php +++ b/Civi/Test/ContactTestTrait.php @@ -213,6 +213,7 @@ trait ContactTestTrait { 'name' => 'Test Group 1', 'domain_id' => 1, 'title' => 'New Test Group Created', + 'frontend_title' => 'Public group name', 'description' => 'New Test Group Created', 'is_active' => 1, 'visibility' => 'Public Pages', diff --git a/sql/civicrm_data/civicrm_mailing_component.sqldata.php b/sql/civicrm_data/civicrm_mailing_component.sqldata.php index 4ba0f76a2b..7c9d2ee5dd 100644 --- a/sql/civicrm_data/civicrm_mailing_component.sqldata.php +++ b/sql/civicrm_data/civicrm_mailing_component.sqldata.php @@ -1,6 +1,6 @@ Unsubscribe
{domain.address}','to unsubscribe: {action.optOutUrl}\n{domain.address}',1,1), - (3,'Subscribe Message','Subscribe','Subscription Confirmation Request','You have a pending subscription to the {subscribe.group} mailing list. To confirm this subscription, reply to this email or click here.','You have a pending subscription to the {subscribe.group} mailing list. To confirm this subscription, reply to this email or click on this link: {subscribe.url}',1,1), + (3,'Subscribe Message','Subscribe','Subscription Confirmation Request','You have a pending subscription to the {group.frontend_title} mailing list. To confirm this subscription, reply to this email or click here.','You have a pending subscription to the {group.frontend_title} mailing list. To confirm this subscription, reply to this email or click on this link: {subscribe.url}',1,1), (4,'Welcome Message','Welcome','Your Subscription has been Activated','Welcome. Your subscription to the {group.frontend_title} mailing list has been activated.','Welcome. Your subscription to the {group.frontend_title} mailing list has been activated.',1,1), (5,'Unsubscribe Message','Unsubscribe','Un-subscribe Confirmation','You have been un-subscribed from the following groups: {unsubscribe.group}. You can re-subscribe by mailing {action.resubscribe} or clicking here.','You have been un-subscribed from the following groups: {unsubscribe.group}. You can re-subscribe by mailing {action.resubscribe} or clicking {action.resubscribeUrl}',1,1), (6,'Resubscribe Message','Resubscribe','Re-subscribe Confirmation','You have been re-subscribed to the following groups: {resubscribe.group}. You can un-subscribe by mailing {action.unsubscribe} or clicking here.','You have been re-subscribed to the following groups: {resubscribe.group}. You can un-subscribe by mailing {action.unsubscribe} or clicking {action.unsubscribeUrl}',1,1), diff --git a/tests/phpunit/api/v3/MailingGroupTest.php b/tests/phpunit/api/v3/MailingGroupTest.php index 7026e5822a..91cb013385 100644 --- a/tests/phpunit/api/v3/MailingGroupTest.php +++ b/tests/phpunit/api/v3/MailingGroupTest.php @@ -26,6 +26,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { * Test civicrm_mailing_group_event_subscribe with given contact ID. */ public function testMailerGroupSubscribeGivenContactID(): void { + $mailUtil = new CiviMailUtils($this); $email = 'test@example.org'; $params = [ 'first_name' => 'Test', @@ -44,6 +45,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { ]; $result = $this->callAPISuccess('MailingEventSubscribe', 'create', $params); $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); + $mailUtil->checkAllMailLog(['You have a pending subscription to the Public group name mailing list']); } /** -- 2.25.1