From 53c38f51462da5a5af6c5a27f10437a6a24d60a4 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 12 Nov 2020 10:20:54 +1100 Subject: [PATCH] dev/core#2153 #REF Remove outdated updateCustomValues function Move function call back to where it was under cividesk Fix delete and ensure updateValue is only called on update --- CRM/Core/BAO/CustomOption.php | 75 +---------------------------------- CRM/Custom/Form/Option.php | 5 ++- 2 files changed, 4 insertions(+), 76 deletions(-) diff --git a/CRM/Core/BAO/CustomOption.php b/CRM/Core/BAO/CustomOption.php index cb20ec185b..960cdf4d22 100644 --- a/CRM/Core/BAO/CustomOption.php +++ b/CRM/Core/BAO/CustomOption.php @@ -198,7 +198,7 @@ AND g.id = v.option_group_id"; 'value' => $value, ]; // delete this value from the tables - self::updateCustomValues($params); + self::updateValue($optionId, $value); // also delete this option value $query = " @@ -210,79 +210,6 @@ WHERE id = %1"; } } - /** - * @param array $params - * - * @throws Exception - */ - public static function updateCustomValues($params) { - $optionDAO = new CRM_Core_DAO_OptionValue(); - $optionDAO->id = $params['optionId']; - $optionDAO->find(TRUE); - $oldValue = $optionDAO->value; - - // get the table, column, html_type and data type for this field - $query = " -SELECT g.table_name as tableName , - f.column_name as columnName, - f.data_type as dataType, - f.html_type as htmlType -FROM civicrm_custom_group g, - civicrm_custom_field f -WHERE f.custom_group_id = g.id - AND f.id = %1"; - $queryParams = [1 => [$params['fieldId'], 'Integer']]; - $dao = CRM_Core_DAO::executeQuery($query, $queryParams); - if ($dao->fetch()) { - if ($dao->dataType == 'Money') { - $params['value'] = CRM_Utils_Rule::cleanMoney($params['value']); - } - switch ($dao->htmlType) { - case 'Autocomplete-Select': - case 'Select': - case 'Radio': - $query = " -UPDATE {$dao->tableName} -SET {$dao->columnName} = %1 -WHERE id = %2"; - if ($dao->dataType == 'Auto-complete') { - $dataType = "String"; - } - else { - $dataType = $dao->dataType; - } - $queryParams = [ - 1 => [ - $params['value'], - $dataType, - ], - 2 => [ - $params['optionId'], - 'Integer', - ], - ]; - break; - - case 'Multi-Select': - case 'CheckBox': - $oldString = CRM_Core_DAO::VALUE_SEPARATOR . $oldValue . CRM_Core_DAO::VALUE_SEPARATOR; - $newString = CRM_Core_DAO::VALUE_SEPARATOR . $params['value'] . CRM_Core_DAO::VALUE_SEPARATOR; - $query = " -UPDATE {$dao->tableName} -SET {$dao->columnName} = REPLACE( {$dao->columnName}, %1, %2 )"; - $queryParams = [ - 1 => [$oldString, 'String'], - 2 => [$newString, 'String'], - ]; - break; - - default: - throw new CRM_Core_Exception('Invalid HTML Type'); - } - $dao = CRM_Core_DAO::executeQuery($query, $queryParams); - } - } - /** * When changing the value of an option this is called to update all corresponding custom data * diff --git a/CRM/Custom/Form/Option.php b/CRM/Custom/Form/Option.php index 60c941c3db..e392a9af7d 100644 --- a/CRM/Custom/Form/Option.php +++ b/CRM/Custom/Form/Option.php @@ -397,7 +397,6 @@ SELECT count(*) $oldWeight = NULL; if ($this->_id) { $customOption->id = $this->_id; - CRM_Core_BAO_CustomOption::updateCustomValues($params); $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id'); } else { @@ -484,7 +483,9 @@ SELECT count(*) } } - CRM_Core_BAO_CustomOption::updateValue($customOption->id, $customOption->value); + if ($this->_id) { + CRM_Core_BAO_CustomOption::updateValue($customOption->id, $customOption->value); + } $customOption->save(); $msg = ts('Your multiple choice option \'%1\' has been saved', [1 => $customOption->label]); -- 2.25.1