hook_civicrm_post does not receive contact_id from CRM_Member_BAO_Membership::updateAllMembershipStatus

Created on 16 June 2025, 29 days ago

Problem/Motivation

I honestly don't know if this is an issue in version 8*. I found this in a Drupal 7 installation, see https://civicrm.stackexchange.com/questions/49552/membership-statusses-n...

I am surprised I found no bug reports about it here - perhaps they were there in the 7* version.

CRM_Member_BAO_Membership::updateAllMembershipStatus , which is called from scheduled jobs, writes its own record since 5.76. As a result, when CRM_Core_DAO::writeRecord is called, it triggers CRM_Utils_Hook::post which is what `hook_civicrm_post` receives. However, this is now a very shallow object and does not contain a contact_id anymore.

I can see in the 8.* code `civicrm_member_roles_civicrm_post` expects this contact_id. It looks like it will properly fail if it isn't there and not update the associated user. The 7.* seems to fail worse.

Proposed resolution

The shallow `$objref` does contain the membership id. You should be able to find the contact id using that.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇱Netherlands commonpike

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024