From 8ff591cb26806a044fc8bdab0d521b8f9b3593b3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 18 Sep 2021 08:28:47 +1200 Subject: [PATCH] Remove duplicate print label tokens There are literally 2 tokens for the same option in the drop down.. remove the non-standard one --- CRM/Core/SelectValues.php | 3 --- CRM/Upgrade/Incremental/Base.php | 18 +++++++++++++++++- CRM/Upgrade/Incremental/MessageTemplates.php | 15 +++++++++++++++ CRM/Upgrade/Incremental/php/FiveFortyThree.php | 9 +++++++++ .../phpunit/CRM/Event/Form/Task/BadgeTest.php | 3 --- .../phpunit/CRM/Utils/TokenConsistencyTest.php | 3 --- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index c2c2afba9a..ead38069eb 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -595,9 +595,6 @@ class CRM_Core_SelectValues { '{participant.participant_registered_by_id}' => 'Registered By Participant ID', '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID', '{participant.participant_role}' => 'Participant Role (label)', - '{participant.event_title}' => 'Event Title', - '{participant.event_start_date}' => 'Event Start Date', - '{participant.event_end_date}' => 'Event End Date', '{participant.fee_label}' => 'Fee Label', '{participant.default_role_id}' => 'Default Role', '{participant.template_title}' => 'Event Template Title', diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 8e2e8641f7..355dbcb3de 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -269,7 +269,7 @@ class CRM_Upgrade_Incremental_Base { } /** - * Updated a message token within a template. + * Updated a message token within a scheduled reminder. * * @param CRM_Queue_TaskContext $ctx * @param string $old @@ -284,6 +284,22 @@ class CRM_Upgrade_Incremental_Base { return TRUE; } + /** + * Updated a message token within a template. + * + * @param CRM_Queue_TaskContext $ctx + * @param string $old + * @param string $new + * @param $version + * + * @return bool + */ + public static function updatePrintLabelToken($ctx, string $old, string $new, $version):bool { + $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version); + $messageObj->replaceTokenInPrintLabel($old, $new); + return TRUE; + } + /** * Re-save any valid values from contribute settings into the normal setting * format. diff --git a/CRM/Upgrade/Incremental/MessageTemplates.php b/CRM/Upgrade/Incremental/MessageTemplates.php index 52a69315b3..ff81310c25 100644 --- a/CRM/Upgrade/Incremental/MessageTemplates.php +++ b/CRM/Upgrade/Incremental/MessageTemplates.php @@ -313,6 +313,21 @@ class CRM_Upgrade_Incremental_MessageTemplates { "); } + /** + * Replace a token with the new preferred option in a print label. + * + * @param string $old + * @param string $new + */ + public function replaceTokenInPrintLabel(string $old, string $new): void { + $oldToken = '{' . $old . '}'; + $newToken = '{' . $new . '}'; + CRM_Core_DAO::executeQuery("UPDATE civicrm_action_schedule + SET + data = REPLACE(data, '$oldToken', '$newToken') + "); + } + /** * Get the upgrade messages. */ diff --git a/CRM/Upgrade/Incremental/php/FiveFortyThree.php b/CRM/Upgrade/Incremental/php/FiveFortyThree.php index 2dfd87c610..624174ff0e 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyThree.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyThree.php @@ -74,6 +74,15 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental $this->addTask('Replace membership type token in action schedule', 'updateActionScheduleToken', 'membership.type', 'membership.membership_type_id:label', $rev ); + $this->addTask('Replace duplicate event title token in event badges', + 'updatePrintLabelToken', 'participant.event_title', 'event.title', $rev + ); + $this->addTask('Replace duplicate event start date token in event badges', + 'updatePrintLabelToken', 'participant.event_start_date', 'event.start_date', $rev + ); + $this->addTask('Replace duplicate event end date token in event badges', + 'updatePrintLabelToken', 'participant.event_end_date', 'event.end_date', $rev + ); } /** diff --git a/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php b/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php index 3da64f0b54..d5b68ad348 100644 --- a/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php +++ b/tests/phpunit/CRM/Event/Form/Task/BadgeTest.php @@ -93,9 +93,6 @@ class CRM_Event_Form_Task_BadgeTest extends CiviUnitTestCase { '{participant.participant_registered_by_id}' => NULL, '{participant.transferred_to_contact_id}' => NULL, '{participant.participant_role}' => 'Attendee', - '{participant.event_title}' => 'Annual CiviCRM meet', - '{participant.event_start_date}' => 'October 21st', - '{participant.event_end_date}' => 'October 23rd', '{participant.fee_label}' => NULL, '{participant.default_role_id}' => 1, '{participant.template_title}' => NULL, diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 6e7e5cfc0e..91445ed6ed 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -492,9 +492,6 @@ December 21st, 2007 '{participant.participant_registered_by_id}' => 'Registered By Participant ID', '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID', '{participant.participant_role}' => 'Participant Role (label)', - '{participant.event_title}' => 'Event Title', - '{participant.event_start_date}' => 'Event Start Date', - '{participant.event_end_date}' => 'Event End Date', '{participant.fee_label}' => 'Fee Label', '{participant.default_role_id}' => 'Default Role', '{participant.template_title}' => 'Event Template Title', -- 2.25.1