Skip to content

Fix for TypeError in 'Update Membership Statuses' Scheduled Job

I've encountered a TypeError while running the 'Update Membership Statuses' scheduled job in CiviCRM, specifically with the CiviRules extension. The error occurs because the in_array() function receives a NULL value due to status_id not being set in $this->conditionParams.

Issue Details:

  • Error Message:
    TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 101 of /.../CRM/CivirulesConditions/Generic/Status.php).
  • Cause: The $this->conditionParams array contains membership_status_id instead of status_id. This discrepancy leads to the in_array() function trying to operate on a NULL value, causing the error.

Proposed Fix:

  • I replaced occurrences of status_id with membership_status_id where necessary.
  • Added a check to ensure that membership_status_id exists in the $entityData array before performing operations on it.

Testing:

  • I've tested the patch on my site, and it resolves the issue. The scheduled job now completes successfully without any errors or warnings.
  • The change does not affect other sites where this issue wasn't present, as they might not have memberships to update when the job runs.

Note:

  • The issue may not be prevalent on other instances as they might not trigger the problematic code path if no memberships are being updated.

I'd like to extend my thanks to @ErikHommel for his valuable guidance in identifying and resolving this issue.

I'd appreciate it if you could review the patch and provide feedback. I'm open to suggestions for further improvements.

Thank you!

Let me know if you need any adjustments!

Edited by Vinay Gawade

Merge request reports

Loading