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) »
  • Post Membership delete hook - no contact_id?
Pages: [1]

Author Topic: Post Membership delete hook - no contact_id?  (Read 774 times)

crawdaddyFL

  • I’m new here
  • *
  • Posts: 11
  • Karma: 2
  • CiviCRM version: 4.1.3
  • CMS version: Joomla 2.5.6
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Post Membership delete hook - no contact_id?
June 29, 2012, 09:03:16 am
I'm attempting to write a hook that takes an action when a Contact's Membership is deleted, but I noticed I'm not getting a contact_id provided in the objectRef during the post-Membership delete hook:

Object ID: 286
Object: CRM_Member_DAO_Membership Object ( [id] => 286 [contact_id] => [membership_type_id] => [join_date] => [start_date] => [end_date] => [source] => [status_id] => [is_override] => [reminder_date] => [owner_membership_id] => [is_test] => [is_pay_later] => [contribution_recur_id] => [campaign_id] => [_DB_DataObject_version] => 1.8.12 [__table] => civicrm_membership [N] => 0 [_database_dsn] => [_database_dsn_md5] => 927092404cb5c3525bb72cf81b730c9f [_database] => jml25 [_query] => Array ( [condition] => WHERE ( civicrm_membership.id = 286 ) ) [_DB_resultid] => [_resultFields] => [_link_loaded] => [_join] => [_lastError] => )

This seems counter-intuitive; is it by design, or a bug? 

In any case, since I'm not getting it, I guess I'll have to look up the contact_id by membership ID in the civicrm_membership table, probably in a pre-Membership delete hook.  Sound right?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Post Membership delete hook - no contact_id?
June 29, 2012, 10:25:26 am

if its not sent in by the hook, then u need to retrieve it in your code.

In general we try to optimize the code and minimize the number of db calls we make. However we can and should establish a few standards as to what values can a hook expect etc

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

crawdaddyFL

  • I’m new here
  • *
  • Posts: 11
  • Karma: 2
  • CiviCRM version: 4.1.3
  • CMS version: Joomla 2.5.6
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Re: Post Membership delete hook - no contact_id?
June 29, 2012, 10:42:24 am
Thanks Lobo.  From a hook perspective, if the action is associated with a contact at all, it seems like the contact ID should be provided.

The post-membership delete context, in my case, is less about needing membership object information and more about the contact who just lost it.

I'm sure everyone uses this in different ways.


crawdaddyFL

  • I’m new here
  • *
  • Posts: 11
  • Karma: 2
  • CiviCRM version: 4.1.3
  • CMS version: Joomla 2.5.6
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Re: Post Membership delete hook - no contact_id?
June 29, 2012, 01:45:43 pm
Related to this, it appears that the Membership delete hooks aren't called when deleting a contact.  The contact's membership DB entries are deleted, so shouldn't the hooks be called as part of this process?


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Post Membership delete hook - no contact_id?
June 29, 2012, 02:01:05 pm

we use mysql cascaded deletes to do the deletions and hence the hooks for those are not called explicitly. You'll need to trap the contact delete hook to catch this case. It makes the code a lot cleaner and easier (and probably a lot faster too)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

crawdaddyFL

  • I’m new here
  • *
  • Posts: 11
  • Karma: 2
  • CiviCRM version: 4.1.3
  • CMS version: Joomla 2.5.6
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Re: Post Membership delete hook - no contact_id?
June 29, 2012, 02:23:54 pm
Got it, thanks Lobo.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Post Membership delete hook - no contact_id?

This forum was archived on 2017-11-26.