From 8477e25b25bb137fdfeabfe0223c52fb5cde5217 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Wed, 19 Apr 2023 14:20:05 +0100 Subject: [PATCH] Small cleanup on contribution receipt code --- CRM/Contribute/BAO/Contribution.php | 29 +++++++++++++---------------- api/v3/Contribution.php | 3 +-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 15cca651f5..5b45ee305d 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2472,9 +2472,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $this->_component = 'event'; } else { - $this->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute')); + $this->_component = $input['component'] ?? 'contribute'; } } + // @todo remove strtolower - check consistency + $this->_component = strtolower($this->_component); // 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. @@ -2482,10 +2484,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $this->find(TRUE); } - $paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $input, CRM_Utils_Array::value( - 'paymentProcessor', - $ids - )); + $paymentProcessorID = $input['payment_processor_id'] ?? $ids['paymentProcessor'] ?? NULL; if (!isset($input['payment_processor_id']) && !$paymentProcessorID && $this->contribution_page_id) { $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', @@ -2498,10 +2497,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac } $this->loadRelatedObjects($paymentProcessorID, $ids); - - if (empty($this->_component)) { - $this->_component = $input['component'] ?? NULL; - } + $paymentProcessor = $this->_relatedObjects['paymentProcessor'] ?? 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); @@ -2515,8 +2511,8 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $template = $this->_assignMessageVariablesToTemplate($values, $input, $returnMessageText); //what does recur 'mean here - to do with payment processor return functionality but // what is the importance - if (!empty($this->contribution_recur_id) && !empty($this->_relatedObjects['paymentProcessor'])) { - $paymentObject = Civi\Payment\System::singleton()->getByProcessor($this->_relatedObjects['paymentProcessor']); + if (!empty($this->contribution_recur_id) && !empty($paymentProcessor)) { + $paymentObject = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor); $entityID = $entity = NULL; if (isset($ids['contribution'])) { @@ -2524,7 +2520,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $entityID = $ids['contribution']; } if (!empty($ids['membership'])) { - //not sure whether is is possible for this not to be an array - load related contacts loads an array but this code was expecting a string + // not sure whether it is possible for this not to be an array - load related contacts loads an array but this code was expecting a string // the addition of the casting is in case it could get here & be a string. Added in 4.6 - maybe remove later? This AuthorizeNetIPN & PaypalIPN tests hit this // line having loaded an array $ids['membership'] = (array) $ids['membership']; @@ -2536,16 +2532,17 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $template->assign('updateSubscriptionBillingUrl', $paymentObject->subscriptionURL($entityID, $entity, 'billing')); $template->assign('updateSubscriptionUrl', $paymentObject->subscriptionURL($entityID, $entity, 'update')); } - // todo remove strtolower - check consistency - if (strtolower($this->_component) === 'event') { - $eventParams = ['id' => $this->_relatedObjects['participant']->event_id]; + + if ($this->_component === 'event') { + $eventID = $this->_relatedObjects['participant']->event_id; + $eventParams = ['id' => $eventID]; $values['event'] = []; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); //get location details $locationParams = [ - 'entity_id' => $this->_relatedObjects['participant']->event_id, + 'entity_id' => $eventID, 'entity_table' => 'civicrm_event', ]; $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 61483cb9c4..dd1ea77efc 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -392,7 +392,6 @@ function _civicrm_api3_contribute_format_params($params, &$values) { * @throws Exception */ function civicrm_api3_contribution_sendconfirmation($params) { - $ids = []; $allowedParams = [ 'receipt_from_email', 'receipt_from_name', @@ -404,7 +403,7 @@ function civicrm_api3_contribution_sendconfirmation($params) { 'payment_processor_id', ]; $input = array_intersect_key($params, array_flip($allowedParams)); - CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id']); + CRM_Contribute_BAO_Contribution::sendMail($input, [], $params['id']); return []; } -- 2.25.1