From d8efe40496d245a295e63a099d016ddaef5a73bf Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 27 Mar 2020 11:06:17 +1300 Subject: [PATCH] Deprecate use of in OptionGroup::add() function We agreed some time back not to use as part of add, create signatures --- CRM/Core/BAO/OptionValue.php | 14 ++++++++------ CRM/Extension/Manager/Report.php | 3 +-- CRM/Extension/Manager/Search.php | 3 +-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index 4da2ece077..3f4031b98d 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -31,17 +31,14 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { * @param array $params * Input parameters. * - * @return object + * @return CRM_Core_DAO_OptionValue + * @throws \CRM_Core_Exception */ public static function create($params) { if (empty($params['id'])) { self::setDefaults($params); } - $ids = []; - if (!empty($params['id'])) { - $ids = ['optionValue' => $params['id']]; - } - return CRM_Core_BAO_OptionValue::add($params, $ids); + return CRM_Core_BAO_OptionValue::add($params); } /** @@ -151,9 +148,14 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { * deprecated Reference array contains the id. * * @return \CRM_Core_DAO_OptionValue + * * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public static function add(&$params, $ids = []) { + if (!empty($ids['optionValue']) && empty($params['id'])) { + 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 diff --git a/CRM/Extension/Manager/Report.php b/CRM/Extension/Manager/Report.php index 0b164791cf..bd8b5d67a7 100644 --- a/CRM/Extension/Manager/Report.php +++ b/CRM/Extension/Manager/Report.php @@ -53,7 +53,6 @@ class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', ['option_group_id' => $this->groupId] ); - $ids = []; $params = [ 'label' => $info->label . ' (' . $info->key . ')', 'value' => $info->typeInfo['reportUrl'], @@ -65,7 +64,7 @@ class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { 'is_active' => 1, ]; - $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); + $optionValue = CRM_Core_BAO_OptionValue::add($params); } /** diff --git a/CRM/Extension/Manager/Search.php b/CRM/Extension/Manager/Search.php index a5da9e47c2..d79e2472ae 100644 --- a/CRM/Extension/Manager/Search.php +++ b/CRM/Extension/Manager/Search.php @@ -55,8 +55,7 @@ class CRM_Extension_Manager_Search extends CRM_Extension_Manager_Base { 'is_active' => 1, ]; - $ids = []; - $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); + $optionValue = CRM_Core_BAO_OptionValue::add($params); return $optionValue ? TRUE : FALSE; } -- 2.25.1