Skip to content

Instantly share code, notes, and snippets.

@demeritcowboy
Created September 23, 2021 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demeritcowboy/c7928d4c7d0b8e9bf9c2420750f3cd50 to your computer and use it in GitHub Desktop.
Save demeritcowboy/c7928d4c7d0b8e9bf9c2420750f3cd50 to your computer and use it in GitHub Desktop.
Replace all the civi message templates with the on-disk version
<?php
/**
* IMPORTANT: Make a backup of the civicrm_msg_template table first.
* Run with `cv php:script ReplaceMessageTemplates.php`
*
* While there's a link on the message templates admin page to revert a workflow
* message template, what that does is replaces your current version with the
* default FROM THE DATABASE.
* That default is, in theory, the same as the latest version on disk in the
* xml/templates/message_templates folder, but for various reasons over time
* it may have gotten out of sync.
* This unconditionally replaces both that default in the database and the
* current version in the database with the latest file contents from on-disk.
*/
class ReplaceMessageTemplates extends \CRM_Upgrade_Incremental_MessageTemplates {
/**
* Override
*/
public function getTemplatesToUpdate() {
$templates = [];
$dao = CRM_Core_DAO::executeQuery('SELECT workflow_name FROM civicrm_msg_template WHERE workflow_name IS NOT NULL GROUP BY workflow_name');
while ($dao->fetch()) {
$templates[] = ['name' => $dao->workflow_name, 'type' => 'subject'];
$templates[] = ['name' => $dao->workflow_name, 'type' => 'text'];
$templates[] = ['name' => $dao->workflow_name, 'type' => 'html'];
}
return $templates;
}
}
(new ReplaceMessageTemplates('dontcare'))->updateTemplates();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment