diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 7f4903ec44cb..86fc62c62d03 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -581,6 +581,13 @@ public static function buildQueue($currentVer, $latestVer, $postUpgradeMessageFi $queue->createItem($task, ['weight' => 0]); } + $task = new CRM_Queue_Task( + ['CRM_Upgrade_Incremental_MessageTemplates', 'updateReservedTemplates'], + [$latestVer], + "Update all reserved message templates" + ); + $queue->createItem($task, ['weight' => 990]); + $task = new CRM_Queue_Task( ['CRM_Upgrade_Form', 'doCoreFinish'], [$rev, $latestVer, $latestVer, $postUpgradeMessageFile], diff --git a/CRM/Upgrade/Incremental/MessageTemplates.php b/CRM/Upgrade/Incremental/MessageTemplates.php index e85585a5960a..5ce3491e4712 100644 --- a/CRM/Upgrade/Incremental/MessageTemplates.php +++ b/CRM/Upgrade/Incremental/MessageTemplates.php @@ -487,6 +487,38 @@ public function getUpgradeMessages() { return $messages; } + /** + * Make sure *all* reserved ones got updated. Might be inefficient because we either already updated or + * there were no changes to a given template, but there's only about 30. + * Note this has to come after the is_default in-use templates are checked to see if they're different + * from the is_reserved version, otherwise that check can't tell which ones the site has changed. + * + * @param CRM_Queue_TaskContext $ctx + * @param string $version + * @return bool + */ + public static function updateReservedTemplates(CRM_Queue_TaskContext $ctx, $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 TRUE; + } + $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'], + ] + ); + } + } + } + return TRUE; + } + /** * Update message templates. */