-
-
Notifications
You must be signed in to change notification settings - Fork 827
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
dev/core#3722 Stop infinite reconciliation #23955
Conversation
(Standard links)
|
I'm unclear what this reconciliation is even for. Why is it needed? And why is it needed only under that condition? |
@colemanw I'm not sure if we can remove the reconciliation altogether, but that would be the cleanest option. I can only imagine it's there because of possible "forked" entities? It only gets called if the |
@colemanw here's where it was added 9c19292 "CRM-14786 - CaseType - Perform reconciliation whenever a case-type definition changes" https://issues.civicrm.org/jira/browse/CRM-14786 Sounds like it is only specific to the XML file where adding an would automatically create the activity type if it doesn't already exist. I assume we don't want that with mgd.php files which should be explicit for all of those. And doesn't play nicely with that anyway. |
I added some code comments. |
Looks like my PR isn't backwards-compatible yet. |
I was wondering what would happen if you call api casetype.create with a definition. Then there's no physical xml file, so it looks like it's skipping the reconciliation. That's how I interpret the test fail. |
@demeritcowboy that seems spot on. In the test it's created it with a fixture, just defined in a variable. It doesn't seem like quite a real world test of functionality but I guess it's possible. Now I'm not sure what to check for. Perhaps a parameter that's only found in the API4 export. The one that seems obvious is |
Going to see if it's okay with specifying |
But then what if you call Ideas:
|
|
@demeritcowboy right. I just tested and yes, it won't reconcile when adding a case type that way. I might try setting a statics as you suggest. |
When I try the equivalent of As for statics, this seems to work:
Though you suggested putting it in |
This works too:
|
Now I'm trying a static. I ended up putting it into |
Are you passing a string? It's expecting an array, at least in v3, like in that test that failed earlier:
|
CRM/Case/BAO/CaseType.php
Outdated
// @see CRM-14786 Reconcilation added to manage whenever a case-type XML definition changes, | ||
// in order to add/remove associated activity and relationship types. | ||
if (!isset(\Civi::$statics[__CLASS__][$params['name']])) { | ||
\Civi::$statics[__CLASS__][$params['name']] = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$params['name'] can be blank, e.g. if calling this to update using id instead of name. There is $caseTypeName which should always be set. But I'm wondering if it even needs to be that specific, since (I think) the reconciliation will reconcile whatever needs reconciling and so just needs to be called once. To be honest I'm not sure exactly how it works, and when PHASE_POST_COMMIT occurs.
In reverse, I suppose there's also the situation where, e.g. during upgrade, this might be an issue, because let's say you have something that does casetype.create in 5.52 and something calls reconciliation, then another casetype.create in 5.53 and something calls reconciliation. That second one won't run if running upgrades via cli since the static will stick.
I'm just thinking of some things to test out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I meant to use $caseTypeName
.
Based on your second thought it seems like setting it per $caseTypeName
might be needed. Unless even that could be repeated across upgrades.
Yes. I blindly tested it in the GUI. I'm assuming that in the GUI there's no way to pass it an array. So it seems a bit of an oddball. |
I can't figure out the failure. Says there were no test failures. |
When that happens you need to hunt in the console log:
|
Running out of steam here. So the last version of this PR that passed as where I restricted it to v3, though not sure if it would pass against master now. |
Taking a step back, what is it you're ultimately trying to do in your extension? Can you just implement hook_civicrm_caseType and put your case type in an xml file? |
For my own project I can just patch Civi via composer until this gets fixed. I had an xml file up until recently. I had also specified some activity types in mgd.php files. But when I added another activity type in mgd.php and also specified it in the casetype xml file CiviCRM complained that the activity type already existed. It was only when I switched to just using mgd.php that it worked. So with a patch I can wait a bit - I don't have to worry about all the permutations on my own project. |
In case it turns out that checking if it's API4 or API3 managed entity is the best way to go, then I just came across |
That function checks if an entity is supported by v4, not whether a particular managed record uses v3 or 4. But that is possible to check as well by inspecting a given record. Something like |
That was effectively the same as one of the earlier commits, it's just that then calling There might be some bugs creep in if v3 calls get blindly replaced with v4 calls - but there's only one obvious place I see in core and it's unlikely to be replaced (in an upgrade script). |
@demeritcowboy does this mean you're warming up to the idea of checking v3/v4 so long as it's documented not to try |
Warming might be too strong a word (grin) but it looks like there's very few obvious uses in universe, and we know there's at least one test that covers the v3 use, so go for it! |
Gr... I don't even see the test |
|
Can one of the admins verify this patch? |
@herbdool thanks for your work on this. I was able to resurrect this PR in the form of #27430 - I used a slightly different approach to prevent recursion (the new-ish ability of managed entities to target a specific module) and that stopped the test from crashing... then I found out that the test itself was broken. That was a fun one. |
Good to see this gnarly one fixed! |
Overview
Fixes https://lab.civicrm.org/dev/core/-/issues/3722
Before
It schedules managed entity reconciliation over and over and over and over and over again.
After
It only schedules reconciliation if the definition is from an xml file and it is in the db already.
Technical Details
New to 5.50.0 we can now export CaseTypes as managed entities from API4. This attempts to fix the assumptions in CaseType which thinks it's coming from an xml file alone.