");
}
- /**
- * Get warnings for users if the replaced string is still present.
- *
- * This might be the case when used in an IF and for now we will recommend
- * manual intervention.
- *
- * @param string $workflowName
- * @param string $old
- * @param string $new
- *
- * @return string
- */
- public function getMessageTemplateWarning(string $workflowName, string $old, string $new) {
- if (CRM_Core_DAO::singleValueQuery("
- SELECT COUNT(*)
- FROM civicrm_msg_template
- WHERE workflow_name = '$workflowName'
- AND (
- msg_html LIKE '%$old%'
- OR msg_subject LIKE '%$old%'
- OR civicrm_msg_template.msg_text LIKE '%$old%'
- )
- ")) {
- return ts('Please review your %1 message template and remove references to the token %2 as it has been replaced by %3', [
- 1 => $workflowName,
- 2 => '{' . $old . '}',
- 3 => '{' . $new . '}',
- ]);
- }
- return '';
- }
-
/**
* Get the upgrade messages.
*/
* @param string $rev
* an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
*/
- public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
- $templateUpgrader = new CRM_Upgrade_Incremental_MessageTemplates($rev);
- $upgradeMessage = $templateUpgrader->getMessageTemplateWarning('contribution_invoice_receipt', '$display_name', 'contact.display_name');
- if (!empty($upgradeMessage)) {
- $postUpgradeMessage .= '<ul><li>' . htmlspecialchars($upgradeMessage) . '</li></ul>';
+ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev): void {
+ if ($rev === '5.41.alpha1') {
+ $postUpgradeMessage .= '<br /><br />' . ts('A token has been updated in the %1 template. Check the system checks page to see if any action is required.', [1 => 'invoice']);
}
- // Example: Generate a post-upgrade message.
- // if ($rev == '5.12.34') {
- // $postUpgradeMessage .= '<br /><br />' . ts("By default, CiviCRM now disables the ability to import directly from SQL. To use this feature, you must explicitly grant permission 'import SQL datasource'.");
- // }
}
/*
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+class CRM_Utils_Check_Component_Tokens extends CRM_Utils_Check_Component {
+
+ /**
+ * Check that deprecated and / or tokens no longer exist/
+ *
+ * @return CRM_Utils_Check_Message[]
+ */
+ public function checkTokens(): array {
+ $changes = CRM_Utils_Token::getTokenDeprecations();
+ $messages = $problems = [];
+ foreach ($changes['WorkFlowMessageTemplates'] as $workflowName => $workflowChanges) {
+ foreach ($workflowChanges as $old => $new) {
+ if (CRM_Core_DAO::singleValueQuery("
+ SELECT COUNT(*)
+ FROM civicrm_msg_template
+ WHERE workflow_name = '$workflowName'
+ AND (
+ msg_html LIKE '%$old%'
+ OR msg_subject LIKE '%$old%'
+ OR civicrm_msg_template.msg_text LIKE '%$old%'
+ )
+ ")) {
+ $problems[] = ts('Please review your %1 message template and remove references to the token %2 as it has been replaced by %3', [
+ 1 => $workflowName,
+ 2 => '{' . $old . '}',
+ 3 => '{' . $new . '}',
+ ]);
+ }
+ }
+ }
+ if (!empty($problems)) {
+ $messages[] = new CRM_Utils_Check_Message(
+ __FUNCTION__ . md5(implode(',', $problems)),
+ '<p>' .
+ ts('You are using tokens that have been removed or deprecated.') .
+ '</p>' .
+ '<ul><li>' .
+ implode('</li><li>', $problems) .
+ '</li></ul></p>',
+ ts('Outdated tokens in use'),
+ \Psr\Log\LogLevel::WARNING
+ );
+ }
+ return $messages;
+ }
+
+}
return $value;
}
+ /**
+ * Get token deprecation information.
+ *
+ * @return array
+ */
+ public static function getTokenDeprecations(): array {
+ return [
+ 'WorkFlowMessageTemplates' => [
+ 'contribution_invoice_receipt' => [
+ '$display_name' => 'contact.display_name',
+ ],
+ ],
+ ];
+ }
+
}
'workflow_name', '=', 'contribution_invoice_receipt'
)->execute();
$upgrader = new CRM_Upgrade_Incremental_MessageTemplates('5.41.0');
- $messages = $upgrader->getMessageTemplateWarning('contribution_invoice_receipt', '$display_name', 'contact.display_name');
- $this->assertEquals('Please review your contribution_invoice_receipt message template and remove references to the token {$display_name} as it has been replaced by {contact.display_name}', $messages);
+ $check = new CRM_Utils_Check_Component_Tokens();
+ $message = $check->checkTokens()[0];
+ $this->assertEquals('<p>You are using tokens that have been removed or deprecated.</p><ul><li>Please review your contribution_invoice_receipt message template and remove references to the token {$display_name} as it has been replaced by {contact.display_name}</li></ul></p>', $message->getMessage());
$upgrader->replaceTokenInTemplate('contribution_invoice_receipt', '$display_name', 'contact.display_name');
$templates = MessageTemplate::get()->addSelect('msg_html')
->addWhere(
foreach ($templates as $template) {
$this->assertEquals('{contact.display_name}', $template['msg_html']);
}
- $messages = $upgrader->getMessageTemplateWarning('contribution_invoice_receipt', '$display_name', 'contact.display_name');
- $this->assertEquals('', $messages);
+ $messages = $check->checkTokens();
+ $this->assertEmpty($messages);
$this->revertTemplateToReservedTemplate('contribution_invoice_receipt');
}