From 0298dd5561191de8745be058d0c46d8dd21e431d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 25 Apr 2020 09:22:21 -0400 Subject: [PATCH] OptionValue - Use DB defaults instead of setting them in BAO::add Of the 4 defaults being set in the DAO, 3 already had db defaults; I added DEFAULT NULL for the last. --- CRM/Core/BAO/OptionValue.php | 14 ++------------ CRM/Core/DAO/OptionValue.php | 3 ++- CRM/Upgrade/Incremental/sql/5.26.alpha1.mysql.tpl | 2 ++ xml/schema/Core/OptionValue.xml | 1 + 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index 0cbb6177ee41..8b8f6693895f 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -149,19 +149,9 @@ public static function add(&$params, $ids = []) { CRM_Core_Error::deprecatedFunctionWarning('$params[\'id\'] should be set, $ids is deprecated'); } $id = $params['id'] ?? $ids['optionValue'] ?? NULL; - // CRM-10921: do not reset attributes to default if this is an update - //@todo consider if defaults are being set in the right place. 'dumb' defaults like - // these would be usefully set @ the api layer so they are visible to api users - // complex defaults like the domain id below would make sense in the setDefauls function - // but unclear what other ways this function is being used - if (!$id) { - $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); - $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); - $params['is_optgroup'] = CRM_Utils_Array::value('is_optgroup', $params, FALSE); - $params['filter'] = CRM_Utils_Array::value('filter', $params, FALSE); - } + // Update custom field data to reflect the new value - elseif (isset($params['value'])) { + if ($id && isset($params['value'])) { CRM_Core_BAO_CustomOption::updateValue($id, $params['value']); } diff --git a/CRM/Core/DAO/OptionValue.php b/CRM/Core/DAO/OptionValue.php index fe2c9c4fc89c..279f18540ea5 100644 --- a/CRM/Core/DAO/OptionValue.php +++ b/CRM/Core/DAO/OptionValue.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/OptionValue.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:c58b4d38fe97741293f8bc5ae5b64e98) + * (GenCodeChecksum:7aa11987c26800632c3798b4cfce95c1) */ /** @@ -281,6 +281,7 @@ public static function &fields() { 'title' => ts('Filter'), 'description' => ts('Bitwise logic can be used to create subsets of options within an option_group for different uses.'), 'where' => 'civicrm_option_value.filter', + 'default' => 'NULL', 'table_name' => 'civicrm_option_value', 'entity' => 'OptionValue', 'bao' => 'CRM_Core_BAO_OptionValue', diff --git a/CRM/Upgrade/Incremental/sql/5.26.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.26.alpha1.mysql.tpl index 9a3558985d85..0307d4263c8c 100644 --- a/CRM/Upgrade/Incremental/sql/5.26.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.26.alpha1.mysql.tpl @@ -1,5 +1,7 @@ {* file to handle db changes in 5.26.alpha1 during upgrade *} +ALTER TABLE civicrm_option_value MODIFY COLUMN `filter` int unsigned DEFAULT NULL COMMENT 'Bitwise logic can be used to create subsets of options within an option_group for different uses.'; + UPDATE civicrm_contact SET is_deceased = 0 WHERE is_deceased IS NULL; ALTER TABLE civicrm_contact MODIFY COLUMN is_deceased TINYINT NOT NULL DEFAULT 0; diff --git a/xml/schema/Core/OptionValue.xml b/xml/schema/Core/OptionValue.xml index c8b7b3a2a494..f3a767d0645a 100644 --- a/xml/schema/Core/OptionValue.xml +++ b/xml/schema/Core/OptionValue.xml @@ -82,6 +82,7 @@ filter int unsigned + NULL Bitwise logic can be used to create subsets of options within an option_group for different uses. 1.5