Add upgrade to token style
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 24 Sep 2021 21:20:15 +0000 (09:20 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 24 Sep 2021 21:20:15 +0000 (09:20 +1200)
CRM/Upgrade/Incremental/Base.php
CRM/Upgrade/Incremental/MessageTemplates.php
CRM/Upgrade/Incremental/php/FiveFortyThree.php

index 355dbcb3def33df199928dcf0e823adc7d22b0e9..79a5c006b4ac2415c1dff849d548ef41c2ce4265 100644 (file)
@@ -264,7 +264,12 @@ class CRM_Upgrade_Incremental_Base {
    */
   public static function updateMessageToken($ctx, string $workflowName, string $old, string $new, $version):bool {
     $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version);
-    $messageObj->replaceTokenInTemplate($workflowName, $old, $new);
+    if (!empty($workflowName)) {
+      $messageObj->replaceTokenInTemplate($workflowName, $old, $new);
+    }
+    else {
+      $messageObj->replaceTokenInMessageTemplates($old, $new);
+    }
     return TRUE;
   }
 
index 2c044e32cb51df451d35e95dea22f5a569a3c323..28721212b9f08d5622e8d67faa7426ac1579a964 100644 (file)
@@ -299,6 +299,24 @@ class CRM_Upgrade_Incremental_MessageTemplates {
     ");
   }
 
+  /**
+   * Replace a token with the new preferred option in non-workflow templates.
+   *
+   * @param string $old
+   * @param string $new
+   */
+  public function replaceTokenInMessageTemplates(string $old, string $new): void {
+    $oldToken = '{' . $old . '}';
+    $newToken = '{' . $new . '}';
+    CRM_Core_DAO::executeQuery("UPDATE civicrm_msg_template
+      SET
+        msg_text = REPLACE(msg_text, '$oldToken', '$newToken'),
+        msg_subject = REPLACE(msg_subject, '$oldToken', '$newToken'),
+        msg_html = REPLACE(msg_html, '$oldToken', '$newToken')
+      WHERE workflow_name IS NULL
+    ");
+  }
+
   /**
    * Replace a token with the new preferred option.
    *
index 7d022f943738f17ec758c95f44a758d56056b1e0..6719bfac4d49b7708f3116021e240bea34a752bd 100644 (file)
@@ -107,7 +107,12 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental
     $this->addTask('Update participant registered by id token in event badges',
       'updatePrintLabelToken', 'participant.participant_registered_by_id', 'participant.registered_by_id', $rev
     );
-
+    $this->addTask('Update contribution status token in saved message templates',
+      'updateMessageToken', '', 'contribution.contribution_status', 'contribution.contribution_status_id:label', $rev
+    );
+    $this->addTask('Update campaign token in saved message templates',
+      'updateMessageToken', '', 'contribution.campaign', 'contribution.campaign_id:label', $rev
+    );
   }
 
   /**