[REF] Remove ids and fully deprecate passing it to Contribution::create
authoreileen <emcnaughton@wikimedia.org>
Thu, 9 Jan 2020 13:00:33 +0000 (02:00 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 10 Jan 2020 00:42:51 +0000 (13:42 +1300)
ids is no longer preferrred & is functionally equivalent

CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Import/Parser/Contribution.php
CRM/Event/Form/Participant.php

index befc6c0b8930363a2f3693aee0758952533379bd..204647ee4b14cc7db93dbbec46659f684cb10950 100644 (file)
@@ -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;
index e9249ed11207799a65631ce09cc5c3a553dd5ced..5bc8cf306e04c8afa2fd1e7b3b33e2bcde12246f 100644 (file)
@@ -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
index d0ac09656abf88e56e921bde02116cbf5fa28285..2cb04bebaaf18c8ae12a9a4fbf42c3bda38bf9d4 100644 (file)
@@ -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,