CRM-15798 membership_type api tidy-up - preparatory to test fixes
authorEileen McNaughton <eileen@fuzion.co.nz>
Thu, 8 Jan 2015 04:34:57 +0000 (17:34 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 26 Jan 2015 22:57:17 +0000 (11:57 +1300)
CRM/Member/BAO/MembershipType.php
api/v3/MembershipType.php
tests/phpunit/api/v3/MembershipTest.php

index b5f4dd3eec253cd27194d4d3f3b0da5db91cdf19..59bfb5bdeb819edabff24068503ee23a3c8960c8 100644 (file)
@@ -128,10 +128,20 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
     if ($id) {
       self::updateAllPriceFieldValue($id, $params);
     }
-
+    self::flush();
     return $membershipType;
   }
 
+  /**
+   * Flush anywhere that membership types might be cached
+   * @throws \CiviCRM_API3_Exception
+   */
+  static function flush() {
+    CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
+    civicrm_api3('membership', 'getfields', array('cache_clear' => 1, 'fieldname' => 'membership_type_id'));
+    civicrm_api3('profile', 'getfields', array('action' => 'submit', 'cache_clear' => 1));
+  }
+
   /**
    * Delete membership Types
    *
index 483fb710f789c640e389b86db2f827d908fe0b55..1fe6772f5690bf29a4c905a84588653d741ce4c0 100644 (file)
  *   newly created or updated membership type property values.
  */
 function civicrm_api3_membership_type_create($params) {
-  $ids['membershipType'] = CRM_Utils_Array::value('id', $params);
-  $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $params);
-  $ids['contributionType'] = CRM_Utils_Array::value('financial_type_id', $params);
-
-  $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($params, $ids);
-  $membershipType = array();
-  _civicrm_api3_object_to_array($membershipTypeBAO, $membershipType[$membershipTypeBAO->id]);
-  CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
-  civicrm_api3('membership', 'getfields', array('cache_clear' => 1, 'fieldname' => 'membership_type_id'));
-  civicrm_api3('profile', 'getfields', array('action' => 'submit', 'cache_clear' => 1));
-  return civicrm_api3_create_success($membershipType, $params, 'membership_type', 'create', $membershipTypeBAO);
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Membership_type');
 }
 
 /**
index d5eb12c08f3824ddc4b019eb86d6c8aa9bb6dd23..8ed9bc10c4163e99093afb30b35f5642fb1cc056 100644 (file)
@@ -1019,7 +1019,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
 
 
   /**
-   * Test that if datesdate are not set they not over-ridden if id is passed in
+   * Test that if dates are set they not over-ridden if id is passed in
    */
   public function testMembershipDatesNotOverridden() {
     $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);