*/
public function getUpgradeMessages() {
$updates = $this->getTemplatesToUpdate();
+
+ // workflow_name is not available pre-5.26, so we won't check if templates are changed or not pre-5.26
+ try {
+ $uneditedTemplates = $this->getUneditedTemplates();
+ }
+ catch (Exception $e) {
+ $uneditedTemplates = [];
+ }
+
$messages = [];
$templateLabel = '';
foreach ($updates as $key => $value) {
$templateLabel = $value['label'];
}
}
- $messages[$templateLabel] = $value['upgrade_descriptor'];
+ if (!(array_key_exists($key, $uneditedTemplates))) {
+ $messages[$templateLabel] = $value['upgrade_descriptor'];
+ }
}
return $messages;
}
* Get all the is_default templates that are the unchanged from their is_reserved counterpart, which
* at the time this runs was the version shipped with core when it was last changed.
*
- * @todo have pulled this out since want to re-use it to get the preUpgrade message right. Currently
- * it always tells you all the ones in the hardcoded per-version list have been customized.
+ * This cannot be used before 5.26, as workflow_name was only added in 5.26.
*
* @return array
*/
$templates = [];
foreach (['html', 'text', 'subject'] as $type) {
$dao = CRM_Core_DAO::executeQuery("
- SELECT default_template.id, default_template.workflow_id FROM civicrm_msg_template reserved
+ SELECT default_template.id, default_template.workflow_id, default_template.workflow_name FROM civicrm_msg_template reserved
LEFT JOIN civicrm_msg_template default_template
ON reserved.workflow_id = default_template.workflow_id
WHERE reserved.is_reserved = 1 AND default_template.is_default = 1 AND reserved.id <> default_template.id
");
while ($dao->fetch()) {
// Note the same id can appear multiple times, e.g. you might change the html but not the subject.
- $templates[] = [
+ $templates[$dao->workflow_name . '_' . $type] = [
'id' => $dao->id,
'type' => $type,
'workflow_id' => $dao->workflow_id,
+ 'workflow_name' => $dao->workflow_name,
];
}
}
* Test function for messages on upgrade.
*/
public function testMessageTemplateGetUpgradeMessages() {
+ \Civi\Api4\MessageTemplate::update(FALSE)
+ ->addValue('msg_text', 'Edited text')
+ ->addWhere('workflow_name', '=', 'contribution_online_receipt')
+ ->addWhere('is_default', '=', TRUE)
+ ->execute();
$messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1');
$messages = $messageTemplateObject->getUpgradeMessages();
$this->assertEquals([
- 'Memberships - Receipt (on-line)' => 'Use email greeting at top where available',
'Contributions - Receipt (on-line)' => 'Use email greeting at top where available',
- 'Events - Registration Confirmation and Receipt (on-line)' => 'Use email greeting at top where available',
], $messages);
}