1

I'm going to write a hook to distinguish a saved membership record, how do I know the last action of saved membership record is edit or renewal?

3

CiviCRM keeps track of membership changes in civicrm_membership_log table for all changes to membership attributes like start date, end date, status. But it will pretty difficult for you to guess if the membership is actually being renewed or updated unless you perform some more checks with different log entries from civicrm_membership_log table.

The other and most easiest/convenient way to know renewal or status change is through Activities. CiviCRM create different activities for membership when a membership is added, renewed and status/type is changed etc(see in attached image list of Activity types for membership). So it will be easy to use post or pre hook on Activity to guess the context.

HTH

Pradeep

  • Thank you so much. Before I post this question, I decided to use your second method. But, I worried about the data integrity because I'm not sure that pre and post hook perform in same db transaction. – pnbps Oct 10 '18 at 12:46
  • Depends on the requirement. – Pradeep Nayak Oct 10 '18 at 12:49
0

CiviCRM keeps log tables that document changes to core tables like civicrm_membership. They're all prefixed log_, so in this case you could look for the newest row in log_civicrm_membership for the relevant contact_id and/or id (id being the membership ID from the core table).

That might contain enough data to help you distinguish between the two cases you describe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.