From 8256753d0077e6003cb23825522ef875d70691be Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 9 Aug 2022 13:49:17 +1200 Subject: [PATCH] Move a little code from --- CRM/Contribute/BAO/Contribution.php | 38 ++++++++++++------- CRM/Contribute/Form/Task/Invoice.php | 10 +++++ .../phpunit/CRM/Core/Payment/BaseIPNTest.php | 1 + 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index ccd3b85223..57aa175402 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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)) { diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index 0451bd6c89..13eb2721cb 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -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; diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php index ea963d5115..a68f1c7002 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -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']); -- 2.25.1