From 41e4124fd1d12ed2c9ad39e85c13d1a039305588 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 1 Nov 2022 12:00:03 +1100 Subject: [PATCH] dev/core#3952 Add in Upgrade script to fix up print labels where " was not being properly escaped for json purposes on previous upgrade process --- CRM/Upgrade/Incremental/php/FiveFiftyFive.php | 15 +++++++++++ .../Incremental/php/FiveFiftyFiveTest.php | 25 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/phpunit/CRM/Upgrade/Incremental/php/FiveFiftyFiveTest.php diff --git a/CRM/Upgrade/Incremental/php/FiveFiftyFive.php b/CRM/Upgrade/Incremental/php/FiveFiftyFive.php index a98b6fd11c..90cb82b6c4 100644 --- a/CRM/Upgrade/Incremental/php/FiveFiftyFive.php +++ b/CRM/Upgrade/Incremental/php/FiveFiftyFive.php @@ -31,4 +31,19 @@ class CRM_Upgrade_Incremental_php_FiveFiftyFive extends CRM_Upgrade_Incremental_ $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); } + public function upgrade_5_55_0($rev): void { + $this->addTask(ts('Fix Event Badge Upgrade'), 'fix_event_badge_upgrade'); + $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + } + + public static function fix_event_badge_upgrade() { + $problematic_fields = CRM_Core_DAO::executeQuery('SELECT id, data FROM civicrm_print_label WHERE data like \'%crmDate:\"%B %E%f\"%\''); + while ($problematic_fields->fetch()) { + $data = $problematic_fields->data; + $data = str_replace('crmDate:"%B %E%f"', 'crmDate:\\\"%B %E%f\\\"', $data); + CRM_Core_DAO::executeQuery("UPDATE civicrm_print_label SET data = '{$data}' WHERE id = %1", [1 => [$problematic_fields->id, 'Positive']]); + } + return TRUE; + } + } diff --git a/tests/phpunit/CRM/Upgrade/Incremental/php/FiveFiftyFiveTest.php b/tests/phpunit/CRM/Upgrade/Incremental/php/FiveFiftyFiveTest.php new file mode 100644 index 0000000000..c093289dda --- /dev/null +++ b/tests/phpunit/CRM/Upgrade/Incremental/php/FiveFiftyFiveTest.php @@ -0,0 +1,25 @@ +assertEquals(1, CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_print_label WHERE data like '%" . 'crmDate:\"%B %E%f\"' . "%'")); + $originalFixed = CRM_Core_DAO::singleValueQuery("SELECT data FROM civicrm_print_label WHERE name = 'Annual_Conference_Hanging_Badge_fixed'"); + $originalBusted = CRM_Core_DAO::singleValueQuery("SELECT data FROM civicrm_print_label WHERE name = 'Annual_Conference_Hanging_Badge_busted'"); + $this->assertEquals(NULL, json_decode($originalBusted)); + $this->assertFalse(NULL === json_decode($originalFixed)); + CRM_Upgrade_Incremental_php_FiveFiftyFive::fix_event_badge_upgrade(); + $fixedBusted = CRM_Core_DAO::singleValueQuery('SELECT data FROM civicrm_print_label WHERE name = \'Annual_Conference_Hanging_Badge_busted\''); + $fixedFixed = CRM_Core_DAO::singleValueQuery("SELECT data FROM civicrm_print_label WHERE name = 'Annual_Conference_Hanging_Badge_fixed'"); + $this->assertEquals($originalFixed, $fixedFixed); + $this->assertFalse(NULL === json_decode($fixedBusted)); + } + +} -- 2.25.1