From: eileen Date: Tue, 20 Oct 2020 23:46:10 +0000 (+1300) Subject: dev/core#927 preliminary cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1ba7b504afd7b0d08ab8041ed007956f729cb43b;p=civicrm-core.git dev/core#927 preliminary cleanup This just splits out the (I believe unreachable) 'no contribution id flow' and makes it clear the mystical addRecurLineItems is part of that flow - in preparation for moving handling to the cancelcontributionactions extension --- diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 7c33202a42..c20c3b4010 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Contribution; + /** * Class CRM_Core_Payment_BaseIPN. */ @@ -237,25 +239,28 @@ class CRM_Core_Payment_BaseIPN { } } - $addLineItems = FALSE; if (empty($contribution->id)) { $addLineItems = TRUE; + // CRM-15546 + $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ + 'labelColumn' => 'name', + 'flip' => 1, + ]); + $contribution->contribution_status_id = $contributionStatuses['Cancelled']; + $contribution->cancel_date = self::$_now; + $contribution->save(); + // Add line items for recurring payments. + if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id && $addLineItems) { + CRM_Contribute_BAO_ContributionRecur::addRecurLineItems($objects['contributionRecur']->id, $contribution); + } } - $participant = &$objects['participant']; - - // CRM-15546 - $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ - 'labelColumn' => 'name', - 'flip' => 1, - ]); - $contribution->contribution_status_id = $contributionStatuses['Cancelled']; - $contribution->cancel_date = self::$_now; - $contribution->save(); - - // Add line items for recurring payments. - if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id && $addLineItems) { - CRM_Contribute_BAO_ContributionRecur::addRecurLineItems($objects['contributionRecur']->id, $contribution); + else { + Contribution::update(FALSE)->setValues([ + 'cancel_date' => 'now', + 'contribution_status_id:name' => 'Cancelled', + ])->addWhere('id', '=', $contribution->id)->execute(); } + $participant = &$objects['participant']; if (!empty($memberships)) { foreach ($memberships as $membership) {