From: Eileen McNaughton <emcnaughton@wikimedia.org> Date: Fri, 24 Sep 2021 21:20:15 +0000 (+1200) Subject: Add upgrade to token style X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fa54791810094c742071d829dc685a38be257505;p=civicrm-core.git Add upgrade to token style --- diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 355dbcb3de..79a5c006b4 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -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; } diff --git a/CRM/Upgrade/Incremental/MessageTemplates.php b/CRM/Upgrade/Incremental/MessageTemplates.php index 2c044e32cb..28721212b9 100644 --- a/CRM/Upgrade/Incremental/MessageTemplates.php +++ b/CRM/Upgrade/Incremental/MessageTemplates.php @@ -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. * diff --git a/CRM/Upgrade/Incremental/php/FiveFortyThree.php b/CRM/Upgrade/Incremental/php/FiveFortyThree.php index 7d022f9437..6719bfac4d 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyThree.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyThree.php @@ -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 + ); } /**