From b2222b9fbd48db96b2e38ad8b800e64f66b4727d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 20 Oct 2015 17:24:11 -0400 Subject: [PATCH] CRM-11782 - Get rid of VALUE_SEPARATOR character in saved search form values --- CRM/Upgrade/Incremental/php/FourSeven.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index 9565373de5..1b986b1b57 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -124,6 +124,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base public function upgrade_4_7_alpha4($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); $this->addTask(ts('Remove %1', array(1 => 'Moneris')), 'removePaymentProcessorType', 'Moneris'); + $this->addTask('Update Smart Groups', 'fixContactTypeInSmartGroups'); } /** @@ -309,4 +310,29 @@ FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; return TRUE; } + /** + * CRM-11782 - Get rid of VALUE_SEPARATOR character in saved search form values + * + * @param \CRM_Queue_TaskContext $ctx + * + * @return bool + */ + public function fixContactTypeInSmartGroups(CRM_Queue_TaskContext $ctx) { + $sep = CRM_Core_DAO::VALUE_SEPARATOR; + $dao = CRM_Core_DAO::executeQuery("SELECT id, form_values FROM civicrm_saved_search WHERE form_values LIKE '%$sep%'"); + while ($dao->fetch()) { + $formValues = unserialize($dao->form_values); + if (isset($formValues['contact_type']) && is_array($formValues['contact_type'])) { + $newVals = array(); + foreach ($formValues['contact_type'] as $key => $val) { + $newVals[str_replace($sep, '__', $key)] = is_string($val) ? str_replace($sep, '__', $val) : $val; + } + $formValues['contact_type'] = $newVals; + } + CRM_Core_DAO::executeQuery("UPDATE civicrm_saved_search SET form_values = %1 WHERE id = {$dao->id}", array(1 => array(serialize($formValues), 'String'))); + } + + return TRUE; + } + } -- 2.25.1