From 8df1a02080c143102aaefe4fcbed0588815c32c9 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 7 Mar 2020 13:28:11 -0500 Subject: [PATCH] Use ?? operator instead of CRM_Utils_Array::value() when fetching ids --- CRM/Contribute/BAO/ManagePremiums.php | 2 +- CRM/Core/BAO/Note.php | 2 +- CRM/Core/BAO/OptionValue.php | 2 +- CRM/Core/BAO/Tag.php | 2 +- CRM/Event/BAO/ParticipantPayment.php | 2 +- CRM/Mailing/BAO/Mailing.php | 2 +- CRM/Mailing/BAO/MailingComponent.php | 2 +- CRM/Member/BAO/MembershipStatus.php | 2 +- CRM/Price/BAO/PriceFieldValue.php | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/BAO/ManagePremiums.php b/CRM/Contribute/BAO/ManagePremiums.php index e7d986678a..272222804d 100644 --- a/CRM/Contribute/BAO/ManagePremiums.php +++ b/CRM/Contribute/BAO/ManagePremiums.php @@ -70,7 +70,7 @@ class CRM_Contribute_BAO_ManagePremiums extends CRM_Contribute_BAO_Product { */ public static function add(&$params, $ids) { CRM_Core_Error::deprecatedFunctionWarning('CRM_Contribute_BAO_Product::create'); - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('premium', $ids)); + $id = $params['id'] ?? $ids['premium'] ?? NULL; if ($id) { $params['id'] = $id; } diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index 2930a65318..86a95fd080 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -150,7 +150,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { $note->contact_id = $params['entity_id']; } } - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); + $id = $params['id'] ?? $ids['id'] ?? NULL; if ($id) { $note->id = $id; } diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index 2aefe0e14c..4da2ece077 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -154,7 +154,7 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { * @throws \CRM_Core_Exception */ public static function add(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('optionValue', $ids)); + $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 diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index 57623f1d72..623dd412de 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -393,7 +393,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { * object on success, otherwise null */ public static function add(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('tag', $ids)); + $id = $params['id'] ?? $ids['tag'] ?? NULL; if (!$id && !self::dataExists($params)) { return NULL; } diff --git a/CRM/Event/BAO/ParticipantPayment.php b/CRM/Event/BAO/ParticipantPayment.php index 401fcd09da..106b2bbae3 100644 --- a/CRM/Event/BAO/ParticipantPayment.php +++ b/CRM/Event/BAO/ParticipantPayment.php @@ -31,7 +31,7 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment * the partcipant payment record */ public static function create(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); + $id = $params['id'] ?? $ids['id'] ?? NULL; if ($id) { CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $id, $params); } diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 8af7f776c0..57fca1a971 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1442,7 +1442,7 @@ ORDER BY civicrm_email.is_bulkmail DESC * @return CRM_Mailing_DAO_Mailing */ public static function add(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('mailing_id', $ids)); + $id = $params['id'] ?? $ids['mailing_id'] ?? NULL; if (empty($params['id']) && !empty($ids)) { \Civi::log('Parameter $ids is no longer used by Mailing::add. Use the api or just pass $params', ['civi.tag' => 'deprecated']); diff --git a/CRM/Mailing/BAO/MailingComponent.php b/CRM/Mailing/BAO/MailingComponent.php index 335370b61e..006bb3aec8 100644 --- a/CRM/Mailing/BAO/MailingComponent.php +++ b/CRM/Mailing/BAO/MailingComponent.php @@ -62,7 +62,7 @@ class CRM_Mailing_BAO_MailingComponent extends CRM_Mailing_DAO_MailingComponent * @return CRM_Mailing_BAO_MailingComponent */ public static function add(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); + $id = $params['id'] ?? $ids['id'] ?? NULL; $component = new CRM_Mailing_BAO_MailingComponent(); if ($id) { $component->id = $id; diff --git a/CRM/Member/BAO/MembershipStatus.php b/CRM/Member/BAO/MembershipStatus.php index d283926613..fc187f186b 100644 --- a/CRM/Member/BAO/MembershipStatus.php +++ b/CRM/Member/BAO/MembershipStatus.php @@ -105,7 +105,7 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { * @return object */ public static function add(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipStatus', $ids)); + $id = $params['id'] ?? $ids['membershipStatus'] ?? NULL; if (!$id) { CRM_Core_DAO::setCreateDefaults($params, self::getDefaults()); //copy name to label when not passed. diff --git a/CRM/Price/BAO/PriceFieldValue.php b/CRM/Price/BAO/PriceFieldValue.php index c3728227d1..a8cfdb9eff 100644 --- a/CRM/Price/BAO/PriceFieldValue.php +++ b/CRM/Price/BAO/PriceFieldValue.php @@ -73,7 +73,7 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { * @throws \CRM_Core_Exception */ public static function create(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); + $id = $params['id'] ?? $ids['id'] ?? NULL; if (!is_array($params) || empty($params)) { return NULL; } @@ -157,7 +157,7 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { * */ public static function getValues($fieldId, &$values, $orderBy = 'weight', $isActive = FALSE, $admin = FALSE) { - $sql = "SELECT cs.id FROM civicrm_price_set cs INNER JOIN civicrm_price_field cp ON cp.price_set_id = cs.id + $sql = "SELECT cs.id FROM civicrm_price_set cs INNER JOIN civicrm_price_field cp ON cp.price_set_id = cs.id WHERE cs.name IN ('default_contribution_amount', 'default_membership_type_amount') AND cp.id = {$fieldId} "; $setId = CRM_Core_DAO::singleValueQuery($sql); $fieldValueDAO = new CRM_Price_DAO_PriceFieldValue(); -- 2.25.1