From 0a03c29b91e7846c2ba363ee742e60887faaeb60 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 5 Dec 2023 13:03:38 +1300 Subject: [PATCH] Partial standardisation of MembershipType::Add --- CRM/Member/BAO/MembershipType.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index aab5faf389..0ec210ec08 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -54,11 +54,8 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType implem * @return \CRM_Member_DAO_MembershipType * @throws \CRM_Core_Exception */ - public static function add(&$params) { - $hook = empty($params['id']) ? 'create' : 'edit'; + public static function add($params) { $membershipTypeID = $params['id'] ?? NULL; - CRM_Utils_Hook::pre($hook, 'MembershipType', $membershipTypeID, $params); - if (!$membershipTypeID && !isset($params['domain_id'])) { $params['domain_id'] = CRM_Core_Config::domainID(); } @@ -68,10 +65,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType implem if ($membershipTypeID) { $previousID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $membershipTypeID, 'member_of_contact_id'); } - - $membershipType = new CRM_Member_DAO_MembershipType(); - $membershipType->copyValues($params); - $membershipType->save(); + $membershipType = self::writeRecord($params); if ($membershipTypeID) { // on update we may need to retrieve some details for the price field function - otherwise we get e-notices on attempts to retrieve @@ -83,9 +77,6 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType implem if ($membershipTypeID) { self::updateAllPriceFieldValue($membershipTypeID, $params); } - - CRM_Utils_Hook::post($hook, 'MembershipType', $membershipType->id, $membershipType); - self::flush(); return $membershipType; } -- 2.25.1