-
-
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
ManagedEntities - Track modification and auto-update #21989
Conversation
(Standard links)
|
8546db3
to
ad95c79
Compare
ad95c79
to
6b344e7
Compare
This uses hooks to ensure managed records are always cleared out when an entity is deleted. Fixes OptionValue::delete which was previously not calling hooks.
6b344e7
to
a2bf592
Compare
This uses hooks to update a timestamp field whenever a managed record is manually updated by a user, allowing us to know if a record is still in its 'pristine' managed state or if it has been altered.
638735c
to
60614bb
Compare
|
The former. Because the modification timestamp is only updated for supported entities, for all others it will remain
Yes, it would have that effect. IMO that's not a bad thing, after all these are managed entities, so I would expect them to reappear if deleted. Arguably they shouldn't do so if the policy is "never" but I'm not sure that's important enough to block this PR. For your reading pleasure, here is the writeup I did when I first submitted this PR with only the first commit. These details felt less important in the big picture once this PR evolved to what it is now, so I edited them out of the description, but the revision history is preserved for posterity: Overview Ensures managed records are always cleared out when an entity is deleted. This prevents perceived bugs caused by orphaned records hanging around in the To minimize risk and improve performance, this only targets those entities who have opted in to the v4 Before
After Technical Details This solves it by using Note: in the original version of this commit I did not restrict it by entity type, and to get tests passing I had to fix |
CRM/Core/ManagedEntities.php
Outdated
@@ -421,6 +433,10 @@ protected function removeStaleEntity($dao) { | |||
$doDelete = FALSE; | |||
break; | |||
|
|||
case 'unmodified': | |||
$doDelete = empty($dao->entity_modified_date); |
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.
If you use attempt to use the new policy on an entity that doesn't support it, what's expected to happen? Does it effectively use some other mode? Or does it raise an error?
The former. Because the modification timestamp is only updated for supported entities, for all others it will remain null; which in practice would cause the mode to act like "always".
Would this be a sensible place to emit a warning if someone has mixed unmodified
with an entity that lacks modification-tracking?
I like that it's able to execute without crashing. 👍 It seems support would roll out incrementally (entity-by-entity/version-by-version) - so we'd expect various permutations {extension-version x managed-entity-policy x core-version x ...} over time. If a particular configuration declares a policy that can't be met, then a warning seems appropriate...
I really like the idea of Thanks for adding the explanation about the first commit. I'm a little ambivalent about scenarios that involve Which has prompted me to think about
Getting too abstract... Maybe better to think about an example... Suppose we have an extension
If the admin has only (1) customized the None of this is meant as a hard block on |
I guess the question is, good compared to what? For search displays, it's the best choice available because the others are:
So Here's another consideration: user visibility. Up until now, managed entities came and went in the shadows, it was mysterious or completely unknown to users. The Afform admin UI started to change that concept (albeit with file-based entities) and now I've implemented something very similar to the SearchKit UI. This is fast-moving code across some merged & in-progress PRs so just as a recap, that UI will show the user:
Because of the user-visibility, I feel like having it work the way Afforms work is a mitigating factor which makes |
OK, that all makes sense. 👍 |
60614bb
to
3357fb7
Compare
@totten I was able to fix |
3357fb7
to
08e373f
Compare
…used' for APIv4 Update mode 'unmodified' will only update a record if it has not been locally edited. This new setting works only for entities opted-in to the APIv4 ManagedEntity trait, and will emit a warning and fall back on 'always' for others. Cleanup mode 'unmodified' now works for APIv4 managed entities, and they are cleaned up in reverse order to ensure references are deleted before their parents.
08e373f
to
095e8ae
Compare
Updates look pretty good. The test coverage seems pretty detailed and appropriate. 👍 Merging |
Overview
Keeps track of user modifications to managed entities, and provides a new auto-update mode to prevent overwriting user-modified entities.
This new mode only works for those entities who have opted in to the v4
ManagedEntity
trait; so far this is onlySavedSearch
andSearchDisplay
, but others could easily be added.Before
Each managed entity may specify two policies:
update
policy: When an upgraded extension provides updates to a managed entity (e.g. new search criteria for aSavedSearch
), the options for how to manage this change were limited to:always
: force-update the savedSearch on-site with the new one from the extension, overwriting any user modificationsnever
: updates to the managed entity in the extension would be ignoredThe former is good for getting new functionality from extensions; the latter is respectful of user-customizations. Neither is perfect.
cleanup
policy: Similarly, when an extension is uninstalled, the options for deleting managed entities are:always
: delete it no matter whatnever
: leave it lying around for the user to deal withunused
: check fk references before deletingThe
unused
mode is preferable but was broken for SearchDisplays, and for SavedSearches it failed to take Afforms into account.After
All previous modes still work. The
unused
cleanup mode has been fixed for SearchDisplays and now accounts for usage by Afforms. Additionally, the following update mode is available (but only for compliant v4 entities):unmodified
will be respectful of user changes and only pull in updates from upgraded managed files if the local copy is unmodified.Comments
This gives SavedSearches, SearchDisplays, etc. the ability to behave like packaged Afforms, with a packaged copy that will always be used unless the user modifies it and creates the equivalent of a local copy, which can then be reverted. If the record is never manually edited then it will be treated like a packaged entity and aggressively managed, but once it is touched by the user it will be left alone. If the extension is uninstalled it will be removed if not in use by Afforms, Smart Groups, etc.
Technical Details
This implements
hook_civicrm_post()
to propagate updates to thecivicrm_managed
record:civicrm_managed
record.civicrm_managed
record.It adds a new extra APIv4 field to the
ManagedEntity
trait:local_modified_date
which can be used in UIs the same way as Afform'shas_local
field.To track usage by Afforms, the Afform extension now implements
hook_civicrm_referenceCounts()
to check useages by SavedSearches and SearchDisplays.