From 436f3267dd8aee11c2c39981224d2e6f9185c3ca Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 12 Nov 2020 15:49:31 +1300 Subject: [PATCH] dev/core#2158 Remove detail about updating related components when editing a contribution status Note that with this merged it's also possible to remove a lot of code from transitionComponents --- CRM/Contribute/BAO/Contribution.php | 95 ---------------------------- CRM/Contribute/Form/Contribution.php | 13 ++-- 2 files changed, 6 insertions(+), 102 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 2f5c8769d8..952fd400a6 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4856,101 +4856,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac return $contributeSettings[$name] ?? NULL; } - /** - * This function process contribution related objects. - * - * @param int $contributionId - * @param int $statusId - * @param int|null $previousStatusId - * - * @param string $receiveDate - * - * @return null|string - */ - public static function transitionComponentWithReturnMessage($contributionId, $statusId, $previousStatusId = NULL, $receiveDate = NULL) { - $statusMsg = NULL; - if (!$contributionId || !$statusId) { - return $statusMsg; - } - - $params = [ - 'contribution_id' => $contributionId, - 'contribution_status_id' => $statusId, - 'previous_contribution_status_id' => $previousStatusId, - 'receive_date' => $receiveDate, - ]; - - $updateResult = CRM_Contribute_BAO_Contribution::transitionComponents($params); - - if (!is_array($updateResult) || - !($updatedComponents = CRM_Utils_Array::value('updatedComponents', $updateResult)) || - !is_array($updatedComponents) || - empty($updatedComponents) - ) { - return $statusMsg; - } - - // get the user display name. - $sql = " - SELECT display_name as displayName - FROM civicrm_contact -LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_contact.id ) - WHERE civicrm_contribution.id = {$contributionId}"; - $userDisplayName = CRM_Core_DAO::singleValueQuery($sql); - - // get the status message for user. - foreach ($updatedComponents as $componentName => $updatedStatusId) { - - if ($componentName == 'CiviMember') { - $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, - CRM_Member_PseudoConstant::membershipStatus() - ); - - $statusNameMsgPart = 'updated'; - switch ($updatedStatusName) { - case 'Cancelled': - case 'Expired': - $statusNameMsgPart = $updatedStatusName; - break; - } - - $statusMsg .= "
" . ts("Membership for %1 has been %2.", [ - 1 => $userDisplayName, - 2 => $statusNameMsgPart, - ]); - } - - if ($componentName == 'CiviEvent') { - $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, - CRM_Event_PseudoConstant::participantStatus() - ); - if ($updatedStatusName == 'Cancelled') { - $statusMsg .= "
" . ts("Event Registration for %1 has been Cancelled.", [1 => $userDisplayName]); - } - elseif ($updatedStatusName == 'Registered') { - $statusMsg .= "
" . ts("Event Registration for %1 has been updated.", [1 => $userDisplayName]); - } - } - - if ($componentName == 'CiviPledge') { - $updatedStatusName = CRM_Utils_Array::value($updatedStatusId, - CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') - ); - if ($updatedStatusName == 'Cancelled') { - $statusMsg .= "
" . ts("Pledge Payment for %1 has been Cancelled.", [1 => $userDisplayName]); - } - elseif ($updatedStatusName == 'Failed') { - $statusMsg .= "
" . ts("Pledge Payment for %1 has been Failed.", [1 => $userDisplayName]); - } - elseif ($updatedStatusName == 'Completed') { - $statusMsg .= "
" . ts("Pledge Payment for %1 has been updated.", [1 => $userDisplayName]); - } - } - } - - return $statusMsg; - } - /** * Get the contribution as it is in the database before being updated. * diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index d453df3a7c..c28a695d92 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1602,13 +1602,12 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // process associated membership / participant, CRM-4395 if ($contribution->id && $action & CRM_Core_Action::UPDATE) { - $this->statusMessage[] = CRM_Contribute_BAO_Contribution::transitionComponentWithReturnMessage($contribution->id, - $contribution->contribution_status_id, - CRM_Utils_Array::value('contribution_status_id', - $this->_values - ), - $contribution->receive_date - ); + CRM_Contribute_BAO_Contribution::transitionComponents([ + 'contribution_id' => $contribution->id, + 'contribution_status_id' => $contribution->contribution_status_id, + 'previous_contribution_status_id' => $this->_values['contribution_status_id'] ?? NULL, + 'receive_date' => $contribution->receive_date, + ]); } array_unshift($this->statusMessage, ts('The contribution record has been saved.')); -- 2.25.1