Remove loadAll parameter from loadRelatedObjects
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 3 Aug 2022 23:57:12 +0000 (11:57 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 3 Aug 2022 23:59:33 +0000 (11:59 +1200)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/Task/Invoice.php
tests/phpunit/CRM/Core/Payment/BaseIPNTest.php

index 183eba33c6e7d5f8c605953ca8f549568db227a8..ccd3b85223da4ff3d6dc3b844fa750e0c15e110a 100644 (file)
@@ -2311,13 +2311,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
    *   Input as delivered from Payment Processor.
    * @param array $ids
    *   Ids as Loaded by Payment Processor.
-   * @param bool $loadAll
-   *   Load all related objects - even where id not passed in? (allows API to call this).
    *
    * @return bool
    * @throws CRM_Core_Exception
    */
-  public function loadRelatedObjects($input, &$ids, $loadAll = FALSE) {
+  public function loadRelatedObjects($input, &$ids) {
     // @todo deprecate this function - the steps should be
     // 1) add additional functions like 'getRelatedMemberships'
     // 2) switch all calls that refer to ->_relatedObjects to
@@ -2326,12 +2324,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     // 4) make ->_relatedObjects protected
     // 5) hone up the individual functions to not use rely on this having been called
     // 6) deprecate like mad
-    if ($loadAll) {
-      $ids = array_merge(self::getComponentDetails($this->id), $ids);
-      if (empty($ids['contact']) && isset($this->contact_id)) {
-        $ids['contact'] = $this->contact_id;
-      }
-    }
     if (empty($this->_component)) {
       if (!empty($ids['event'])) {
         $this->_component = 'event';
@@ -2467,7 +2459,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
    * @throws Exception
    */
   public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText = TRUE) {
-    $this->loadRelatedObjects($input, $ids, TRUE);
+    $ids = array_merge(self::getComponentDetails($this->id), $ids);
+    if (empty($ids['contact']) && isset($this->contact_id)) {
+      $ids['contact'] = $this->contact_id;
+    }
+    $this->loadRelatedObjects($input, $ids);
 
     if (empty($this->_component)) {
       $this->_component = $input['component'] ?? NULL;
index 04f10ca6891506b963def0f92db5b979be5b720e..0451bd6c8936da700d7e4097230e8af437893a67 100644 (file)
@@ -221,7 +221,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
     $pendingStatusId = CRM_Utils_Array::key('Pending', $contributionStatusID);
     $pdfFormat = CRM_Core_BAO_PdfFormat::getByName('default_invoice_pdf_format');
 
-    foreach ($invoiceElements['details'] as $contribID => $detail) {
+    foreach ($invoiceElements['details'] as $contributionID => $detail) {
       $input = $ids = [];
       if (in_array($detail['contact'], $invoiceElements['excludeContactIds'])) {
         continue;
@@ -230,7 +230,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       $input['component'] = $detail['component'];
 
       $ids['contact'] = $detail['contact'];
-      $ids['contribution'] = $contribID;
+      $ids['contribution'] = $contributionID;
       $ids['contributionRecur'] = NULL;
       $ids['contributionPage'] = NULL;
       $ids['membership'] = $detail['membership'] ?? NULL;
@@ -238,12 +238,13 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       $ids['event'] = $detail['event'] ?? NULL;
 
       $contribution = new CRM_Contribute_BAO_Contribution();
-      $contribution->id = $contribID;
+      $contribution->id = $contributionID;
       $contribution->fetch();
       // @todo this is only used now to load the event title, it causes an enotice
       // and calls deprecated code. If we decide a contribution title is a
       // 'real thing' then we should create a token.
-      $contribution->loadRelatedObjects($input, $ids, TRUE);
+      $ids = array_merge(CRM_Contribute_BAO_Contribution::getComponentDetails($contributionID), $ids);
+      $contribution->loadRelatedObjects($input, $ids);
 
       $input['amount'] = $contribution->total_amount;
       $input['invoice_id'] = $contribution->invoice_id;
@@ -278,13 +279,13 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       $dueDatePeriodSetting = Civi::settings()->get('invoice_due_date_period');
       $dueDate = date('F j, Y', strtotime($contributionReceiveDate . "+" . $dueDateSetting . "" . $dueDatePeriodSetting));
 
-      $amountPaid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribID, TRUE);
+      $amountPaid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionID, TRUE);
       $amountDue = ($input['amount'] - $amountPaid);
 
       // retrieving the subtotal and sum of same tax_rate
       $dataArray = [];
       $subTotal = 0;
-      $lineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribID);
+      $lineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionID);
       foreach ($lineItem as $taxRate) {
         if (isset($dataArray[(string) $taxRate['tax_rate']])) {
           $dataArray[(string) $taxRate['tax_rate']] = $dataArray[(string) $taxRate['tax_rate']] + CRM_Utils_Array::value('tax_amount', $taxRate);
index 4c196d5c723f4942a3315105bf713d4696f5fe88..ea963d511511f45ddf1eb4b72276bb7d46559daf 100644 (file)
@@ -114,11 +114,11 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
     $contribution = new CRM_Contribute_BAO_Contribution();
     $contribution->id = $this->_contributionId;
     $contribution->find(TRUE);
-    $contribution->loadRelatedObjects($this->input, $this->ids, TRUE);
+    $ids = array_merge(CRM_Contribute_BAO_Contribution::getComponentDetails($this->_contributionId), $this->ids);
+    $contribution->loadRelatedObjects($this->input, $ids);
     $this->assertNotEmpty($contribution->_relatedObjects['membership']);
     $this->assertArrayHasKey($this->_membershipId . '_' . $this->_membershipTypeID, $contribution->_relatedObjects['membership']);
     $this->assertTrue(is_a($contribution->_relatedObjects['membership'][$this->_membershipId . '_' . $this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
-    $this->assertTrue(is_a($contribution->_relatedObjects['financialType'], 'CRM_Financial_BAO_FinancialType'));
     $this->assertNotEmpty($contribution->_relatedObjects['contributionRecur']);
     $this->assertNotEmpty($contribution->_relatedObjects['paymentProcessor']);
   }