refactor pending one step closer to the form when renewing membership status - goal...
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 2 Jun 2015 10:46:48 +0000 (22:46 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 2 Jun 2015 10:46:48 +0000 (22:46 +1200)
CRM/Batch/Form/Entry.php
CRM/Member/BAO/Membership.php
CRM/Member/Form/MembershipRenewal.php
tests/phpunit/CRM/Member/BAO/MembershipTest.php

index 2b80fc9018a2547c6d42333168aa541e5da01ee1..601a62d2bdd9d35b7c236da65341754a5377b519 100755 (executable)
@@ -786,8 +786,14 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
           $membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper(
             $value['contact_id'],
             $value['membership_type_id'],
-            FALSE, $this, NULL, NULL,
-            $value['custom']
+            FALSE,
+            $this,
+            NULL,
+            NULL,
+            $value['custom'],
+            1,
+            NULL,
+            FALSE
           );
 
           // make contribution entry
index 3313801ba598e50d9d8abe80de370e158da81a97..62cda04ac06ae8ffb3e84db23dec070dcb182792 100644 (file)
@@ -1520,19 +1520,24 @@ AND civicrm_membership.is_test = %2";
    * @param int $membershipID
    *   Membership ID, this should always be passed in & optionality should be removed.
    *
-   * @throws CRM_Core_Exception
+   * @param bool $isPending
+   *   Is the transaction pending. We are working towards this ALWAYS being true and completion being done
+   *   in the complete transaction function, called by all types of payment processor (removing assumptions
+   *   about what they do & always doing a pending + a complete at the appropriate time).
    *
+   * @return
    */
   public static function renewMembershipFormWrapper(
     $contactID,
     $membershipTypeID,
     $is_test,
     &$form,
-    $changeToday = NULL,
-    $modifiedID = NULL,
-    $customFieldsFormatted = NULL,
-    $numRenewTerms = 1,
-    $membershipID = NULL
+    $changeToday,
+    $modifiedID,
+    $customFieldsFormatted,
+    $numRenewTerms,
+    $membershipID,
+    $isPending
   ) {
     $statusFormat = '%Y-%m-%d';
     $format = '%Y%m%d';
@@ -1548,8 +1553,10 @@ AND civicrm_membership.is_test = %2";
     $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
 
     // check is it pending. - CRM-4555
-    list($pending, $contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId) = self::extractFormValues($form, $changeToday, $membershipTypeDetails);
-    list($membership, $renewalMode, $dates) = self::renewMembership($contactID, $membershipTypeID, $is_test, $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $allStatus, $membershipTypeDetails, $contributionRecurID, $format, $membershipSource, $ids, $statusFormat, $isPayLater, $campaignId);
+    list($contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId) = self::extractFormValues($form, $changeToday);
+    list($membership, $renewalMode, $dates) = self::renewMembership($contactID, $membershipTypeID, $is_test,
+      $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $isPending, $allStatus,
+      $membershipTypeDetails, $contributionRecurID, $format, $membershipSource, $ids, $statusFormat, $isPayLater, $campaignId);
     $form->set('renewal_mode', $renewalMode);
     if (!empty($dates)) {
       $form->assign('mem_start_date',
@@ -2303,7 +2310,8 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
       $isTest, $form, NULL,
       CRM_Utils_Array::value('cms_contactID', $membershipParams),
       $customFieldsFormatted, $numTerms,
-      $membershipID
+      $membershipID,
+      self::extractPendingFormValue($form, $memType)
     );
 
     if (!empty($membershipContribution)) {
@@ -2332,15 +2340,19 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
   }
 
   /**
-   * Extract relevant values from the form so we can separate form logic from BAO logcis.
+   * Determine if the form has a pending status.
+   *
+   * This is an interim refactoring step. This information should be extracted at the form layer.
+   *
+   * @deprecated
    *
    * @param CRM_Core_Form $form
-   * @param $changeToday
-   * @param $membershipTypeDetails
+   * @param int $membershipID
    *
-   * @return array
+   * @return bool
    */
-  public static function extractFormValues($form, $changeToday, $membershipTypeDetails) {
+  public static function extractPendingFormValue($form, $membershipID) {
+    $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipID);
     $pending = FALSE;
     //@todo this is a BAO function & should not inspect the form - the form should do this
     // & pass required params to the BAO
@@ -2354,6 +2366,18 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
         $pending = TRUE;
       }
     }
+    return $pending;
+  }
+
+  /**
+   * Extract relevant values from the form so we can separate form logic from BAO logcis.
+   *
+   * @param CRM_Core_Form $form
+   * @param $changeToday
+   *
+   * @return array
+   */
+  public static function extractFormValues($form, $changeToday) {
     $contributionRecurID = isset($form->_params['contributionRecurID']) ? $form->_params['contributionRecurID'] : NULL;
 
     //we renew expired membership, CRM-6277
@@ -2384,7 +2408,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
         $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
       }
     }
-    return array($pending, $contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId);
+    return array($contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId);
   }
 
   /**
index eb977eac39ed5ee7f79561265f91fb7ab0194fed..77af3103d9c60f733fd7cb5d1c9df1442a528531 100644 (file)
@@ -613,7 +613,8 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
       $formValues['membership_type_id'][1],
       $isTestMembership, $this, NULL, NULL,
       $customFieldsFormatted, $numRenewTerms,
-      $this->_membershipId
+      $this->_membershipId,
+      CRM_Member_BAO_Membership::extractPendingFormValue($this, $formValues['membership_type_id'][1])
     );
 
     $endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
index 94dc6854d12860b8ff6eb7614963f72b91cd1b29..2b2ba6c61ad0a40b3f25674f496cfeb80e91d80d 100644 (file)
@@ -528,7 +528,11 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase {
       $isTestMembership,
       $membershipRenewal,
       NULL,
-      NULL
+      NULL,
+      NULL,
+      1,
+      NULL,
+      FALSE
     );
     $endDate = date("Y-m-d", strtotime($membership->end_date . " +1 year"));
 
@@ -602,7 +606,18 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase {
 
     $membershipRenewal = new CRM_Core_Form();
     $membershipRenewal->controller = new CRM_Core_Controller();
-    $MembershipRenew = CRM_Member_BAO_Membership::renewMembershipFormWrapper($contactId, $this->_membershipTypeID, $isTestMembership = 0, $membershipRenewal, NULL, NULL);
+    $MembershipRenew = CRM_Member_BAO_Membership::renewMembershipFormWrapper(
+      $contactId,
+      $this->_membershipTypeID,
+      $isTestMembership = 0,
+      $membershipRenewal,
+      NULL,
+      NULL,
+      NULL,
+      1,
+      NULL,
+      FALSE
+      );
 
     $this->assertDBNotNull('CRM_Member_BAO_MembershipLog',
       $MembershipRenew->id,