Bug When Restoring Overridden Status on Related Memberships
Overview
Under certain special circumstances, once a main membership that has related memberships (eg. a membership held by an employer for a maximum number of employees), if the status is overridden for a specific date, and the date has been met so that status for the main membership and its related memberships can now be calculated by the membership status calculation job, some of the related memberships may get deleted.
Reproduction steps
The specific conditions that need to be met are:
- Have an organization with a membership that has a maximum number of related memberships via a specific relationship (eg. 3 maximum related contacts with employee relationship).
- Have more contacts related to the organization that the maximum related memberships (eg 5)
- Distribute the memberships to the contacts so that the first created contact, and the last contacts have the related memberships.
- Give the main membership an overridden status for a date in the past.
Run membership status calculation job.
Current behaviour
Under this conditions, when the job is run, what will happen is the 3 memberships will be allocated to the first 3 contacts related to the organization. So if before the job was run, we had contacts with ID's 1001, 1002, 1003, 1004, 1005, and the three memberships were for contacts 1001, 1004 and 1005, when the job runs, the memberships will be given to contacts 1001, 1002 and 1003, and the memberships for 1004 and 1005 will be deleted. Furthermore, a fatal exception is thrown when the job is run.
Expected behaviour
- Running the job should maintain the memberships to the contacts they've already been given to.
- The job should run and complete without failure.
Environment information
- __CiviCRM: 5.24.6
- __PHP: 7.2
- __CMS: Drupal 7.71
- __Database: MySQL 5.7
- __Web Server: Nginx
Comments
I have debugged the issue and found a fix. I will add the PR to the ticket once I have it up.