Update Group Subscribe message to use frontend_title
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 24 Jul 2023 02:26:35 +0000 (14:26 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 26 Jul 2023 00:03:21 +0000 (12:03 +1200)
CRM/Mailing/Event/BAO/MailingEventSubscribe.php
CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl
CRM/Utils/Token.php
Civi/Test/ContactTestTrait.php
sql/civicrm_data/civicrm_mailing_component.sqldata.php
sql/civicrm_generated.mysql
tests/phpunit/api/v3/MailingGroupTest.php

index 30af618b88f085d0485708f61dd0d88f4070af08..5fbcf34872f607988133d18601a39328d9f67b58 100644 (file)
@@ -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 &amp; entities in text mode, so that the links work
     $text = str_replace('&amp;', '&', $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');
index ec037c2896a8b57c6672b1f481b5c80763bb9a59..2ac634fee903317a188810a0134facd16cd4ab4a 100644 (file)
@@ -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;
index 77ad4c9c87ba934a237272826024b9c2bf9f1a01..f2ef5ce9957473a8dfccb1288e8a868b8aadd4b6 100644 (file)
@@ -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);
     }
index 3d752d8e3aefdfdbfd5f3631f2f936ccfad4433b..4f0410bea5842ca4d69da5ca6fb6c00873848832 100644 (file)
@@ -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',
index 4ba0f76a2bed34125632d981dd3966dc1f74380e..7c9d2ee5ddf7b08deb1c7d04231c88d951ff6032 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-$subgroup = '{subscribe.group}';
+$subgroup = '{group.frontend_title}';
 $suburl = '{subscribe.url}';
 $welgroup = '{group.frontend_title}';
 $unsubgroup = '{unsubscribe.group}';
index 09816c098665fe56eb9bb609588b85806861f730..71b75e46f1ad9be38113b7584a44f9cf1f4cbcb7 100644 (file)
@@ -4513,7 +4513,7 @@ LOCK TABLES `civicrm_mailing_component` WRITE;
 INSERT INTO `civicrm_mailing_component` (`id`, `name`, `component_type`, `subject`, `body_html`, `body_text`, `is_default`, `is_active`) VALUES
  (1,'Mailing Header','Header','Descriptive Title for this Header','Sample Header for HTML formatted content.','Sample Header for TEXT formatted content.',1,1),
  (2,'Mailing Footer','Footer','Descriptive Title for this Footer.','Sample Footer for HTML formatted content<br/><a href=\"{action.optOutUrl}\">Unsubscribe</a>  <br/> {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 <a href=\"{subscribe.url}\">here</a>.','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 <a href=\"{subscribe.url}\">here</a>.','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 <a href=\"{action.resubscribeUrl}\">here</a>.','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 <a href=\"{action.unsubscribeUrl}\">here</a>.','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),
index 7026e5822a9ca5a53898ded2180973c1885dd0d7..91cb013385a42f38de8405b4f5f2c0e4eaff5a84 100644 (file)
@@ -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']);
   }
 
   /**