From 70d43afbdb5ac3c61dbda76fad5e7b9be0ad1efb Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 10 Jan 2020 02:00:33 +1300 Subject: [PATCH] [REF] Remove ids and fully deprecate passing it to Contribution::create ids is no longer preferrred & is functionally equivalent --- CRM/Contribute/BAO/Contribution.php | 14 ++++++++++---- CRM/Contribute/Import/Parser/Contribution.php | 3 ++- CRM/Event/Form/Participant.php | 16 ++++++---------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index befc6c0b89..204647ee4b 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -90,6 +90,9 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { if (empty($params)) { return NULL; } + if (!empty($ids)) { + CRM_Core_Error::deprecatedFunctionWarning('ids should not be passed into Contribution.add'); + } //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params)); $action = $contributionID ? 'edit' : 'create'; @@ -493,7 +496,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { * @throws \CiviCRM_API3_Exception */ public static function create(&$params, $ids = []) { - $dateFields = [ 'receive_date', 'cancel_date', @@ -510,7 +512,11 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $transaction = new CRM_Core_Transaction(); try { - $contribution = self::add($params, $ids); + if (!isset($params['id']) && isset($ids['contribution'])) { + CRM_Core_Error::deprecatedFunctionWarning('ids should not be used for contribution create'); + $params['id'] = $ids['contribution']; + } + $contribution = self::add($params); } catch (CRM_Core_Exception $e) { $transaction->rollback(); @@ -2376,8 +2382,8 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ $contributionParams[$field] = $params[$field]; } - $ids = ['contribution' => $contributionId]; - $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); + $contributionParams['id'] = $contributionId; + $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams); } return $updateResult; diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index e9249ed112..5bc8cf306e 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -321,7 +321,8 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Contribute_Import_Pa } } - $newContribution = CRM_Contribute_BAO_Contribution::create($formatted, $ids); + $formatted['id'] = $ids['contribution']; + $newContribution = CRM_Contribute_BAO_Contribution::create($formatted); $this->_newContributions[] = $newContribution->id; //return soft valid since we need to show how soft credits were added diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index d0ac09656a..2cb04bebaa 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1353,10 +1353,10 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment if (!empty($params['record_contribution'])) { if (!empty($params['id'])) { if ($this->_onlinePendingContributionId) { - $ids['contribution'] = $this->_onlinePendingContributionId; + $contributionParams['id'] = $this->_onlinePendingContributionId; } else { - $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', + $contributionParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['id'], 'contribution_id', 'participant_id' @@ -1428,7 +1428,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment // if multiple participants are link, consider contribution total amount as the amount Owed if ($this->_id && CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) { $amountOwed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', - $ids['contribution'], + $contributionParams['id'], 'total_amount' ); } @@ -1447,21 +1447,17 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } if ($this->_single) { - if (empty($ids)) { - $ids = []; - } - $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); + $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams); } else { - $ids = []; foreach ($this->_contactIds as $contactID) { $contributionParams['contact_id'] = $contactID; - $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); + $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams); } } // Insert payment record for this participant - if (empty($ids['contribution'])) { + if (empty($contributionParams['id'])) { foreach ($this->_contactIds as $num => $contactID) { $participantPaymentParams = [ 'participant_id' => $participants[$num]->id, -- 2.25.1