-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Switch to relationship BAO when modifying relationships in change case status so we don't bypass hooks #15030
Switch to relationship BAO when modifying relationships in change case status so we don't bypass hooks #15030
Conversation
(Standard links)
|
@demeritcowboy any thoughts |
Yep I can review - fix seems like a good idea. Regarding the should/shouldn't there's been some back and forth around that (example PRs below). Currently, changing one thing breaks something else since it gets interpreted differently between dashboard, manage case, search, contact relationships tab, and also differences of opinion. There was an idea listed at the first link here: https://lab.civicrm.org/dev/core/issues/542 |
@demeritcowboy yes - there is the small change in this PR & the larger discussion it raises... |
If the client is an org, this seems to cause the change case status activity to hang when closing the case. Doesn't seem to happen with current. I'll try to track it down but it will probably be tomorrow (my timezone, so that would be two days from now for you - he he). Hey do you both have horseracing? Why don't you tell me the winners and I'll place a bet in my timezone before the race and split the winnings with you - how has nobody ever thought of this before? (grin) |
Ah great plan - what could possibly go wrong |
Actually I can see what it is. The api includes a check that the relationship "is valid" and it ends up throwing an uncaught exception. It seems pre-existing, and I'm thinking would have a problem for any code that uses the api to end an org relationship? But is currently a bit of a blocker. In general the api for Relationship seems to have a fair amount of business logic, including where it does something with memberships(?) and current employer, so I know the PR seems like a small change but maybe worth a little more review than at first glance. |
015b79f
to
4aabc58
Compare
@demeritcowboy I've pushed an amended version that does not use the API but calls By the way, my specific requirement is actually to prevent the relationship being updated at all. |
Looks like the add() function needs to be fed more params, but otherwise seems like it should work. Or thinking out loud, if this ends up not working then if the custom code is implementing hooks anyway, would it work to have the custom code call getCaseRoles and save the results somewhere during hook_preprocess, and then restore during postprocess? Not ideal, but just a thought. |
@demeritcowboy Thanks - it seems to me like the "better" fix here is to fixup |
@mattwire is this no longer WIP or is there more to do still? |
@demeritcowboy I've opened #15103 to handle the change required to the Relationship BAO so we need to get that reviewed/merged and then rebase/merge this one. |
Thanks @mattwire - will take a look. |
017a539
to
2357be8
Compare
…e status so we don't bypass hooks
2357be8
to
ebdc731
Compare
@demeritcowboy If you have time, the relevant PRs have now been merged and this is ready for final review. |
Yep will take a look. |
|
OK - merging based on the above review |
Overview
Replace direct SQL UPDATE with
Relationship.create APICRM_Contact_BAO_Relationship::add()
when changing case status so we don't bypass hooksWe can't use the API (yet) because it contains too much business logic, so switching from direct SQL to the BAO.
Before
Relationship end_date is updated using a direct SQL query, bypassing hooks
After
Relationship end_date is updated using the
Relationship.create APICRM_Contact_BAO_Relationship::add()
so no hooks are bypassedTechnical Details
Direct SQL query -> BAO call
Comments
I'm not convinced we should necessarily be "reopening" relationships just because we change the case status. Also, I wonder whether we should be changing the active/inactive flag if we change the end_date. But I'm not proposing any change in this PR which retains the same functionality as before.