CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Update membership status on a single member programmatically?
Pages: [1]

Author Topic: Update membership status on a single member programmatically?  (Read 760 times)

man4mac

  • I’m new here
  • *
  • Posts: 9
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Druapl 7
  • MySQL version: 5.5
  • PHP version: 5+
Update membership status on a single member programmatically?
December 03, 2012, 11:08:37 am
Scenario: We have a smoothly running CiviCRM 4.1.5 site on Drupal 7 with a large amount of custom development to meet specific business logic. One of those custom pieces taps into the CiviCRM API to manually update a membership expiration date. This works great! However, we are not updating the membership status at the same time, and occasionally end up with memberships that have an expiration date in the future, but still have their membership status id set to "expired" until the update_membership cron job gets run. Unfortunately that is potentially 24 hours of poor user experience for our end users.

This seems like a simple question, but I cannot seem to find a way to update the status on a single member. The cron job does this for everyone, but we need to do this programmatically on a single member, at a moments notice. I also dont want to manually set the status_id with the API since the membership status rules are subject to change. Any help would be greatly appreciated!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Update membership status on a single member programmatically?
December 03, 2012, 11:53:48 am
Try adding this param with the membership create api

$params['skipStatusCal'] = 0;

You can see it defaults to 1 on updates ....

Code: [Select]
  if (CRM_Utils_Array::value('id', $params) && !isset($params['skipStatusCal'])) {
    //don't calculate dates on exisiting membership - expect API use to pass them in
    // or leave unchanged
    $params['skipStatusCal'] = 1;
  }
  else {
    // also check for status id if override is set (during add/update)
    if (isset($params['is_override']) &&
      !CRM_Utils_Array::value('status_id', $params)
    ) {
      return civicrm_api3_create_error('Status ID required');
    }
  }

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

man4mac

  • I’m new here
  • *
  • Posts: 9
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Druapl 7
  • MySQL version: 5.5
  • PHP version: 5+
Re: Update membership status on a single member programmatically?
December 03, 2012, 12:15:43 pm
Eileen: That completely nailed it. Thank you so much.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Update membership status on a single member programmatically?

This forum was archived on 2017-11-26.