dev/core#927 preliminary cleanup
authoreileen <emcnaughton@wikimedia.org>
Tue, 20 Oct 2020 23:46:10 +0000 (12:46 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 21 Oct 2020 19:18:39 +0000 (08:18 +1300)
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

CRM/Core/Payment/BaseIPN.php

index 7c33202a42f4ae3f5ec0d6b6c819d2d1069308d1..c20c3b4010c8b232a02520c64a13f0935c914c52 100644 (file)
@@ -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) {