-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM-21421 Fix to allow updating an existing CaseContact record #11268
CRM-21421 Fix to allow updating an existing CaseContact record #11268
Conversation
@mattwire it would be nice to have a unit test for this but the change seems to make sense |
@seamuslee001 Happy to create a unit test, I'd like to get @colemanw feedback first. |
Something's not right here... Aside from You mentioned that the problem you encountered is easy to reproduce with the api explorer. What are the steps? |
Create a case:
This will fail:
With error:
This will also fail (it calls CRM_Case_BAO_CaseContact::create internally) (and this is how the issue was identified as this is what webform is doing):
Here is the fatal error:
This is reproduceable on a clean 4.7.27 and master, as long as the UI_case_contact_id index has been updated to UNIQUE (as it will be for all new installs and is specified in the XML since 4.7.20). This can be reproduced using webform_civicrm by creating a simple webform:
Enable the cases, set it to existing contact and update existing cases. |
2eab157
to
4c90ead
Compare
Hmm, why did this test pass even though #11270 was unmerged? Now that it is merged, this test should still pass but it worries me that it didn't fail before. |
@civicrm-builder retest this please. |
4c90ead
to
be84446
Compare
jenkins, test this please |
…ng_existing_casecontact CRM-21421 Fix to allow updating an existing CaseContact record
Overview
Found during a webform submission that updates a case status, but easy to replicate using the Case.Create API.
The function CRM_Case_BAO_CaseContact::create requires that you either specify a CaseContact ID or it will try and add a new one. However, the database index UI_case_contact_id has recently been changed to be UNIQUE and was causing the function CRM_Case_BAO_CaseContact::create to crash. The change has been in CiviCRM since 4.7.20 but the change to the database would have been made at some point after CiviCRM started warning when indexes were inconsistent.
Before
It is not possible to update cases via the API once the UI_case_contact_id index has been updated to "UNIQUE".
After
It is possible to update cases via the API once the UI_case_contact_id index has been updated to "UNIQUE".
Technical Details
Adds an API call to CRM_Case_BAO_CaseContact which calls CaseContact.getsingle with contact_id and case_id as parameters. If an existing CaseContact.id is found that is used instead of trying to create a new one.
Comments
@colemanw I'm not sure if the way I've fixed this is the right way, ie. using the API, and I'm not sure why it appears that it was previously creating new CaseContact entries every time it was updating a case?
When you get a minute, would you mind reviewing this PR and advising what the correct fix should be?