-
-
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
dev/core#667 Fix bug where entity_tags are not deleted by 'soft FK' #16832
Conversation
(Standard links)
|
dc5c0a5
to
c5f5a1b
Compare
This looks fine to me would appreciate @totten just doing a review as well |
CRM/Core/BAO/EntityTag.php
Outdated
if ($event->action !== 'delete' | ||
// Activity can call the pre hook for delete with no ID - this seems to be isolated to activity.... | ||
// @todo - what is the correct way to standardise? | ||
|| ($event->entity === 'Activity' && !$event->id)) { |
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.
Wait... what?
Why would this hook be called with no id? Is that a bug?
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.
It feels like it to me - but in activity BAO
public static function deleteActivity(&$params, $moveToTrash = FALSE) {
// CRM-9137
if (!empty($params['id']) && !is_array($params['id'])) {
CRM_Utils_Hook::pre('delete', 'Activity', $params['id'], $params);
}
else {
CRM_Utils_Hook::pre('delete', 'Activity', NULL, $params);
}
if (Civi::$statics[__CLASS__]['tagged_entities'][$event->entity]) { | ||
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_entity_tag WHERE entity_table = %1 AND entity_id = %2', | ||
[1 => [Civi::$statics[__CLASS__]['tagged_entities'][$event->entity], 'String'], 2 => [$event->id, 'Integer']] | ||
); |
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.
Firing off an ad-hoc query feels icky somehow. Shouldn't we call pre/post hooks before deleting entityTags? And shouldn't there already be a bao function to delete entityTags? And can we avoid an infinite loop in the process of calling a pre hook from within a pre hook listener?
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.
good point about the loop.
My instinct here was that this is kind of a bottom-of-the-food-chain entity & the efficiency of a single query makes sense
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.
Oh - the existing entity-tag functions hurt my head
Hang on, it looks like there was a |
ohhh |
@colemanw so I feel like to merge this we need to resolve the following
Performance wise it's a bit mixed - doing a get before any deletes does reduce locking operations but if a contact had hundreds of tags individual deletes would be a bit of a drag. |
So for:
I guess it doesn't need to be in this PR, but I'd like to see a dispatcher system that makes it easier for entities to subscribe to create/update/delete events fired by other entities. |
c5f5a1b
to
4c40c02
Compare
@colemanw I've updated it to use the other listener |
4c40c02
to
6c5e24d
Compare
6c5e24d
to
bc59613
Compare
Looks good! |
test this please |
1 similar comment
test this please |
Hmm it failed around the same place `not ok 139 - Error: CRM_Case_XMLProcessor_ProcessTest::testCreateActivityWithDefaultContactByRelationship |
bc59613
to
9d4c4ff
Compare
Ah it's because I deleted that fn you questioned - but it IS being called |
Overview
Fixes a bug where deleting a contact does not delete tags associated with the contact
Before
After
entity_tag record is cleaned up
Technical Details
This utilises an approach @colemanw & @totten & I discussed about switching to a pre hook rather than ad hoc function calls. It's an initial foray & it would be good to limit it to being called on delete. Other entities could do with this - e.g the participants are deleted & then the participant notes in the current flow - I'm pretty sure the note won't be deleted due to the participant going first.
Comments