From 85fbe0cc749cec94cec06209c707734ab8a03432 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 4 Sep 2023 12:38:51 +1200 Subject: [PATCH] Pass specific ids rather than ids array It is unclear when we pass ids what ids we care about (& in general how many ids we are using from the various functions). In fact 2 specific IDs are used (one from the _relatedObjects array) so pass these in and stop passing in ids. Also stop setting an id that we never use --- CRM/Contribute/BAO/Contribution.php | 19 +++++++++---------- tests/phpunit/CRM/PCP/BAO/PCPTest.php | 19 +------------------ 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6495ed0031..2a9eaccc6e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2533,9 +2533,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $this->loadRelatedObjects($paymentProcessorID, $ids); $paymentProcessor = $this->_relatedObjects['paymentProcessor'] ?? NULL; + $eventID = isset($ids['event']) ? (int) $ids['event'] : NULL; + $participantID = isset($ids['participant']) ? (int) $ids['participant'] : NULL; //not really sure what params might be passed in but lets merge em into values - $values = array_merge($this->_gatherMessageValues($input, $values, $ids), $values); + $values = array_merge($this->_gatherMessageValues($values, $eventID, $participantID), $values); $values['is_email_receipt'] = !$returnMessageText; foreach (['receipt_date', 'cc_receipt', 'bcc_receipt', 'receipt_from_name', 'receipt_from_email', 'receipt_text', 'pay_later_receipt'] as $fld) { if (!empty($input[$fld])) { @@ -2569,7 +2571,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac } if ($this->_component === 'event') { - $eventID = $this->_relatedObjects['participant']->event_id; $eventParams = ['id' => $eventID]; $values['event'] = []; @@ -2610,7 +2611,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac } return CRM_Event_BAO_Event::sendMail($ids['contact'], $values, - $this->_relatedObjects['participant']->id, $this->is_test, $returnMessageText + $participantID, $this->is_test, $returnMessageText ); } else { @@ -2686,16 +2687,14 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * as part of CRM-9996 refactoring as a step towards simplifying the composeMessage function * Values related to the contribution in question are gathered * - * @param array $input - * Input into function (probably from payment processor). * @param array $values - * @param array $ids - * The set of ids related to the input. + * @param int|null $eventID + * @param int|null $participantID * * @return array * @throws \CRM_Core_Exception */ - public function _gatherMessageValues($input, &$values, $ids = []) { + public function _gatherMessageValues($values, ?int $eventID, ?int $participantID) { // set display address of contributor $values['billingName'] = ''; if ($this->address_id) { @@ -2771,11 +2770,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac ); // if this is onbehalf of contribution then set related contact if (!empty($relatedContact['individual_id'])) { - $values['related_contact'] = $ids['related_contact'] = $relatedContact['individual_id']; + $values['related_contact'] = $relatedContact['individual_id']; } } else { - $values = array_merge($values, $this->loadEventMessageTemplateParams((int) $ids['event'], (int) $this->_relatedObjects['participant']->id, $this->id)); + $values = array_merge($values, $this->loadEventMessageTemplateParams($eventID, $participantID, $this->id)); } $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $this->id); diff --git a/tests/phpunit/CRM/PCP/BAO/PCPTest.php b/tests/phpunit/CRM/PCP/BAO/PCPTest.php index 3280d4042f..595274b91c 100644 --- a/tests/phpunit/CRM/PCP/BAO/PCPTest.php +++ b/tests/phpunit/CRM/PCP/BAO/PCPTest.php @@ -234,24 +234,7 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { 'receipt_from_email' => 'donationFake@civicrm.org', 'contribution_status' => 'Completed', ]; - $gathered_values = $contribution_bao->_gatherMessageValues( - [ - 'payment_processor_id' => $payment_processor['id'], - 'is_email_receipt' => TRUE, - ], - $values, - [ - 'component' => 'contribute', - 'contact_id' => $contact_contributor, - 'contact' => $contact_contributor, - 'financialType' => $contribution['values'][$contribution['id']]['financial_type_id'], - 'contributionType' => $contribution['values'][$contribution['id']]['contribution_type_id'], - 'contributionPage' => $contributionPage['id'], - 'membership' => [], - 'paymentProcessor' => $payment_processor['id'], - 'contribution' => $contribution['id'], - ] - ); + $gathered_values = $contribution_bao->_gatherMessageValues($values, NULL, NULL); $this->assertEquals([ 'receipt_from_name' => 'CiviCRM Fundraising Dept.', -- 2.25.1