Skip to content

Commit

Permalink
update all is_reserved templates each time
Browse files Browse the repository at this point in the history
  • Loading branch information
demeritcowboy committed Aug 22, 2022
1 parent 71f0493 commit 34d6aa2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CRM/Upgrade/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
25 changes: 25 additions & 0 deletions CRM/Upgrade/Incremental/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 34d6aa2

Please sign in to comment.