diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 7f4903ec44cb..92c842cded34 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -912,6 +912,10 @@ public function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVe } } } + // Now make sure *all* reserved ones got updated. Might be inefficient, but there's only about 30. + // Note this has to come after the template update above, otherwise that can't tell which ones the site + // has changed. + CRM_Upgrade_Incremental_MessageTemplates::updateReservedTemplates($latestVer); } } diff --git a/CRM/Upgrade/Incremental/MessageTemplates.php b/CRM/Upgrade/Incremental/MessageTemplates.php index e85585a5960a..d5d7c118ad2e 100644 --- a/CRM/Upgrade/Incremental/MessageTemplates.php +++ b/CRM/Upgrade/Incremental/MessageTemplates.php @@ -487,6 +487,31 @@ public function getUpgradeMessages() { return $messages; } + /** + * Update reserved message templates. + * @param string $version + */ + public static function updateReservedTemplates($version) { + if (version_compare($version, '5.26', '<')) { + // We can't do this before workflow_name was introduced. Strictly speaking we don't care until 5.54. + return; + } + $dao = CRM_Core_DAO::executeQuery("SELECT id, workflow_name FROM civicrm_msg_template WHERE is_reserved=1"); + while ($dao->fetch()) { + foreach (['html', 'text', 'subject'] as $type) { + $content = file_get_contents(\Civi::paths()->getPath('[civicrm.root]/xml/templates/message_templates/' . $dao->workflow_name . '_' . $type . '.tpl')); + if ($content) { + CRM_Core_DAO::executeQuery( + "UPDATE civicrm_msg_template SET msg_{$type} = %1 WHERE id = %2", [ + 1 => [$content, 'String'], + 2 => [$dao->id, 'Integer'], + ] + ); + } + } + } + } + /** * Update message templates. */