Skip to content

Commit

Permalink
Merge pull request #15844 from mlutfy/fixMsgTpl
Browse files Browse the repository at this point in the history
marketing/civicrm-website#163 Mitigate potential upgrade errors on missing msg_templates
  • Loading branch information
eileenmcnaughton authored Nov 14, 2019
2 parents e5ebe87 + e36d905 commit f3064b2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions CRM/Upgrade/Incremental/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ public function updateTemplates() {
$content = file_get_contents(\Civi::paths()->getPath('[civicrm.root]/xml/templates/message_templates/' . $template['name'] . '_' . $template['type'] . '.tpl'));
$templatesToUpdate = [];
if (!empty($workFlowID)) {
$templatesToUpdate[] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_msg_template WHERE workflow_id = $workFlowID AND is_reserved = 1");
// This could be empty if the template was deleted. It should not happen,
// but has been seen in the wild (ex: marketing/civicrm-website#163).
$id = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_msg_template WHERE workflow_id = $workFlowID AND is_reserved = 1");
if ($id) {
$templatesToUpdate[] = $id;
}
$defaultTemplateID = CRM_Core_DAO::singleValueQuery("
SELECT default_template.id FROM civicrm_msg_template reserved
LEFT JOIN civicrm_msg_template default_template
Expand All @@ -280,11 +285,13 @@ public function updateTemplates() {
$templatesToUpdate[] = $defaultTemplateID;
}

CRM_Core_DAO::executeQuery("
UPDATE civicrm_msg_template SET msg_{$template['type']} = %1 WHERE id IN (" . implode(',', $templatesToUpdate) . ")", [
1 => [$content, 'String'],
]
);
if (!empty($templatesToUpdate)) {
CRM_Core_DAO::executeQuery("
UPDATE civicrm_msg_template SET msg_{$template['type']} = %1 WHERE id IN (" . implode(',', $templatesToUpdate) . ")", [
1 => [$content, 'String'],
]
);
}
}
}
}
Expand Down

0 comments on commit f3064b2

Please sign in to comment.