Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21216 Replace member_BAO_membershiptype_getMembershipTypesByOrg with API eq… #11020

Conversation

mattwire
Copy link
Contributor

…uivalent

Overview

Replace the BAO function getMembershipTypesByOrg with generic API function.

Before

Custom code that does the same as the API

After

Generic API is used to retrieve the same information in the same format.

Technical Details

The API supports the necessary parameters to retrieve the information that is being retrieved by the custom function.

Copy link
Contributor

@seamuslee001 seamuslee001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes here, I haven't tested them but the code looks correct to me. @eileenmcnaughton Eileen any thoughts?

@eileenmcnaughton
Copy link
Contributor

In order to test this I put the following code

    $memberTypesSameParentOrg = civicrm_api3('MembershipType', 'get', array(
      'member_of_contact_id' => $orgID,
    ));
    return CRM_Utils_Array::value('values', $memberTypesSameParentOrg, array());

into the existing getMembershipTypesByOrg function & ran the tests identified in this PR - they still passed.

I am going to merge this as the code looks good & I believe the tests adequately cover it. But I wonder if we shouldn't change the function to be more deprected ie change the function to

  public static function getMembershipTypesByOrg($orgID) {
    Civi::log()->warning('Deprecated function getMembershipTypesByOrg, please user membership_type api', array('civi.tag' => 'deprecated'));
    $memberTypesSameParentOrg = civicrm_api3('MembershipType', 'get', array(
      'member_of_contact_id' => $orgID,
    ));
    return CRM_Utils_Array::value('values', $memberTypesSameParentOrg, array());
  }

@eileenmcnaughton eileenmcnaughton merged commit f70263e into civicrm:master Sep 23, 2017
@@ -849,8 +849,10 @@ public static function getContactMembership($contactID, $memType, $isTest, $memb
$params = array('id' => $memType);
$membershipType = array();
if (CRM_Member_BAO_MembershipType::retrieve($params, $membershipType)) {
$memberTypesSameParentOrg = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($membershipType['member_of_contact_id']);
$memberTypesSameParentOrgList = implode(',', array_keys($memberTypesSameParentOrg));
$memberTypesSameParentOrg = civicrm_api3('MembershipType', 'get', array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does look like it will run into problems when there are more than 25 membership types due to API requests having a default limit of 25 values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg true!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire did you see that comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-( Please see new PR #11029 that fixes this and also updates deprecated function based on your comments @eileenmcnaughton @tschuettler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants