refactor creation of membership_payment records into shared function
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 20 May 2014 00:38:49 +0000 (12:38 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 27 May 2014 09:04:57 +0000 (21:04 +1200)
CRM/Member/BAO/Membership.php

index e51d28800e7fcc4f64e4c0b7b858f76400ed2fa4..ae90d9aa14d0f8cd92b9a440327d8faee500e574 100644 (file)
@@ -1321,17 +1321,7 @@ AND civicrm_membership.is_test = %2";
 
           $createdMemberships[$memType] = $membership;
           if (!empty($membershipContribution)) {
-            //insert payment record
-            $dao = new CRM_Member_DAO_MembershipPayment();
-            $dao->membership_id = $membership->id;
-            $dao->contribution_id = $membershipContribution->id;
-            //Fixed for avoiding duplicate entry error when user goes
-            //back and forward during payment mode is notify
-            if (!$dao->find(TRUE)) {
-              CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao);
-              $dao->save();
-              CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao);
-            }
+            self::linkMembershipPayment($membership, $membershipContribution);
           }
         }
         if ($form->_priceSetId && !empty($form->_useForMember) && !empty($form->_lineItem)) {
@@ -1362,17 +1352,7 @@ AND civicrm_membership.is_test = %2";
         self::updateRecurMembership($membership, $membershipContribution);
 
         if (!empty($membershipContributionID)) {
-          //insert payment record
-          $dao = new CRM_Member_DAO_MembershipPayment();
-          $dao->membership_id = $membership->id;
-          $dao->contribution_id = $membershipContributionID;
-          //Fixed for avoiding duplicate entry error when user goes
-          //back and forward during payment mode is notify
-          if (!$dao->find(TRUE)) {
-            CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao);
-            $dao->save();
-            CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao);
-          }
+          self::linkMembershipPayment($membership, $membershipContribution);
         }
       }
     }
@@ -2464,6 +2444,25 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
     }
   }
 
+  /**
+   * Create linkages between membership & contribution - note this is the wrong place for this code but this is a
+   * refactoring step. This should be BAO functionality
+   * @param $membership
+   * @param $membershipContribution
+   */
+  public static function linkMembershipPayment($membership, $membershipContribution) {
+    $dao = new CRM_Member_DAO_MembershipPayment();
+    $dao->membership_id = $membership->id;
+    $dao->contribution_id = $membershipContribution->id;
+    //Fixed for avoiding duplicate entry error when user goes
+    //back and forward during payment mode is notify
+    if (!$dao->find(TRUE)) {
+      CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao);
+      $dao->save();
+      CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao);
+    }
+  }
+
   /**
    * Function to process price set and line items.
    *