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 containsmembership_status_id
instead ofstatus_id
. This discrepancy leads to thein_array()
function trying to operate on aNULL
value, causing the error.
Proposed Fix:
- I replaced occurrences of
status_id
withmembership_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