From 560df6345cd017710d11ccf1067222f7e197e6c4 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 5 Sep 2020 09:19:01 +1200 Subject: [PATCH] [REF] Simplify logic on calling self::updateContributionStatus self::updateContributionStatus is only called when contributionStatusId has been set - there is only one place that is set so move the code up there rather than set a param to trigger action further down --- CRM/Event/Form/Task/Batch.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/CRM/Event/Form/Task/Batch.php b/CRM/Event/Form/Task/Batch.php index 163c830cf1..f8ac3af5f3 100644 --- a/CRM/Event/Form/Task/Batch.php +++ b/CRM/Event/Form/Task/Batch.php @@ -268,7 +268,7 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { $contributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($participantId, 'Event' ); - if (!$contributionId) { + if (!$contributionId || !$participantId) { return; } @@ -280,28 +280,22 @@ class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task { $negativeStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"); $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - $contributionStatusId = NULL; if (array_key_exists($statusId, $positiveStatuses)) { - $contributionStatusId = array_search('Completed', $contributionStatuses); + $params = [ + 'component_id' => $participantId, + 'contribution_id' => $contributionId, + 'contribution_status_id' => array_search('Completed', $contributionStatuses), + 'IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved' => 1, + ]; + + //change related contribution status. + self::updateContributionStatus($params); } if (array_key_exists($statusId, $negativeStatuses)) { civicrm_api3('Contribution', 'create', ['id' => $contributionId, 'contribution_status_id' => 'Cancelled']); return; } - if (!$contributionStatusId || !$participantId || !$contributionId) { - return; - } - - $params = [ - 'component_id' => $participantId, - 'contribution_id' => $contributionId, - 'contribution_status_id' => $contributionStatusId, - 'IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved' => 1, - ]; - - //change related contribution status. - self::updateContributionStatus($params); } /** -- 2.25.1