Skip to content

Commit

Permalink
Move a little code from
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 9, 2022
1 parent 35e5f39 commit 340ba2b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
38 changes: 24 additions & 14 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,15 @@ public static function transitionComponents($params) {
$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'] ?? [];
Expand Down Expand Up @@ -2324,20 +2333,6 @@ public function loadRelatedObjects($input, &$ids) {
// 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',
Expand Down Expand Up @@ -2463,6 +2458,21 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
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)) {
Expand Down
10 changes: 10 additions & 0 deletions CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
// 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;
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function testLoadMembershipObjectsLoadAll() {
$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']);
Expand Down

0 comments on commit 340ba2b

Please sign in to comment.