Skip to content

Commit

Permalink
Merge pull request #24190 from eileenmcnaughton/load_related
Browse files Browse the repository at this point in the history
Move a little code from legacy function `loadRelatedObjects` to the calling functions
  • Loading branch information
mattwire authored Aug 10, 2022
2 parents 639e58b + 219ac01 commit 55d3832
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
40 changes: 25 additions & 15 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,16 @@ public static function transitionComponents($params) {

$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $ids['contribution'];
$contribution->find();
$contribution->find(TRUE);

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);

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
12 changes: 11 additions & 1 deletion CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,21 @@ public static function printPDF($contribIDs, &$params, $contactIds) {

$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $contributionID;
$contribution->fetch();
$contribution->find(TRUE);
// @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.
$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 55d3832

Please sign in to comment.