Move a little code from
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 9 Aug 2022 01:49:17 +0000 (13:49 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 9 Aug 2022 08:01:20 +0000 (20:01 +1200)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/Task/Invoice.php
tests/phpunit/CRM/Core/Payment/BaseIPNTest.php

index ccd3b85223da4ff3d6dc3b844fa750e0c15e110a..57aa175402b011c2141495f84299c405466ddb9b 100644 (file)
@@ -1830,6 +1830,15 @@ LEFT JOIN  civicrm_contribution contribution ON ( componentPayment.contribution_
     $contribution->id = $ids['contribution'];
     $contribution->find();
 
+    if (empty($contribution->_component)) {
+      if (!empty($ids['event'])) {
+        $contribution->_component = 'event';
+      }
+      else {
+        $contribution->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute'));
+      }
+    }
+
     $contribution->loadRelatedObjects($input, $ids);
 
     $memberships = $contribution->_relatedObjects['membership'] ?? [];
@@ -2324,20 +2333,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 (empty($this->_component)) {
-      if (!empty($ids['event'])) {
-        $this->_component = 'event';
-      }
-      else {
-        $this->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute'));
-      }
-    }
-
-    // If the object is not fully populated then make sure it is - this is a more about legacy paths & cautious
-    // refactoring than anything else, and has unit test coverage.
-    if (empty($this->financial_type_id)) {
-      $this->find(TRUE);
-    }
 
     $paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $input, CRM_Utils_Array::value(
       'paymentProcessor',
@@ -2463,6 +2458,21 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     if (empty($ids['contact']) && isset($this->contact_id)) {
       $ids['contact'] = $this->contact_id;
     }
+
+    if (empty($this->_component)) {
+      if (!empty($ids['event'])) {
+        $this->_component = 'event';
+      }
+      else {
+        $this->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute'));
+      }
+    }
+
+    // If the object is not fully populated then make sure it is - this is a more about legacy paths & cautious
+    // refactoring than anything else, and has unit test coverage.
+    if (empty($this->financial_type_id)) {
+      $this->find(TRUE);
+    }
     $this->loadRelatedObjects($input, $ids);
 
     if (empty($this->_component)) {
index 0451bd6c8936da700d7e4097230e8af437893a67..13eb2721cb937e0f2ff55a52056f635076a7798a 100644 (file)
@@ -244,6 +244,16 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
       // and calls deprecated code. If we decide a contribution title is a
       // 'real thing' then we should create a token.
       $ids = array_merge(CRM_Contribute_BAO_Contribution::getComponentDetails($contributionID), $ids);
+
+      if (empty($contribution->_component)) {
+        if (!empty($ids['event'])) {
+          $contribution->_component = 'event';
+        }
+        else {
+          $contribution->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute'));
+        }
+      }
+
       $contribution->loadRelatedObjects($input, $ids);
 
       $input['amount'] = $contribution->total_amount;
index ea963d511511f45ddf1eb4b72276bb7d46559daf..a68f1c700222909f6ef6b90954906f0cb1989b9e 100644 (file)
@@ -114,6 +114,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
     $contribution = new CRM_Contribute_BAO_Contribution();
     $contribution->id = $this->_contributionId;
     $contribution->find(TRUE);
+    $contribution->_component = 'contribute';
     $ids = array_merge(CRM_Contribute_BAO_Contribution::getComponentDetails($this->_contributionId), $this->ids);
     $contribution->loadRelatedObjects($this->input, $ids);
     $this->assertNotEmpty($contribution->_relatedObjects['membership']);