Skip to content
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#1753 - Attachments aren't deleted when deleting activity #17298

Merged

Conversation

demeritcowboy
Copy link
Contributor

@demeritcowboy demeritcowboy commented May 12, 2020

Overview

https://lab.civicrm.org/dev/core/-/issues/1753

  1. Create an activity, e.g. a meeting or one more likely to have an attachment like an email activity.
  2. Add an attachment.
  3. Delete the activity, e.g. from your contact's activity tab.
  4. Look in sites/default/files/civicrm/custom. The attachment file is still there.
  5. Also the entries are still there in civicrm_file and civicrm_entity_file even though the entry in civicrm_activity isn't there anymore.

Also in the added test the last three asserts all fail.

Before

Deleting an activity leaves the attachments orphaned in the filesystem and database.

After

Deleting an activity also deletes the attachments.

Technical Details

Oversight?

Possibly there's a reason it didn't delete attachments - anybody know of one? The function call I've added checks the reference count in case it's shared with another entity, so it's only deleted from the filesystem if this is the last reference.

Comments

I thought I had seen this before a long time ago but (a) in CiviCase you never delete, and (b) it doesn't really come up for me personally for regular activities either, and (c) it's not something users would notice and report.

@civibot
Copy link

civibot bot commented May 12, 2020

(Standard links)

@civibot civibot bot added the master label May 12, 2020
@demeritcowboy demeritcowboy force-pushed the activity-attachment-delete branch from 727ece7 to 612594c Compare May 12, 2020 02:20
@demeritcowboy demeritcowboy changed the title [WIP/TEST] dev/core#1753 - Failing test showing that attachments aren't deleted when deleting activity dev/core#1753 - Failing test showing that attachments aren't deleted when deleting activity May 12, 2020
@demeritcowboy demeritcowboy changed the title dev/core#1753 - Failing test showing that attachments aren't deleted when deleting activity dev/core#1753 - Attachments aren't deleted when deleting activity May 12, 2020
@demeritcowboy demeritcowboy force-pushed the activity-attachment-delete branch from 612594c to 8ee4df1 Compare May 12, 2020 03:02
@demeritcowboy
Copy link
Contributor Author

jenkins retest this please

1 similar comment
@demeritcowboy
Copy link
Contributor Author

jenkins retest this please

@totten
Copy link
Member

totten commented May 12, 2020

Possibly there's a reason it didn't delete attachments - anybody know of one? The function call I've added checks the reference count in case it's shared with another entity, so it's only deleted from the filesystem if this is the last reference.

Yeah, IMHO, if the civicrm_file reference-count is zero, then I can't imagine a case for keeping it.

There are other cases which may sound similar - but don't apply, eg

  • If we were talking about contact images, then references and locations can be really bonkers. But civicrm_file is more locked down.
  • If we were talking about garbage-collection after-the-fact (e.g. deleting all orphaned files of unknown origin), then that might give pause. But this is deleting files that were attached (like 2 milliseconds ago) and now become orphans.

@kcristiano
Copy link
Member

I have replicated the issue and done an r-run on this. The attachments are deleted when the activity is deleted.

I did test with CiviCase:

  • add an activity to a Case
  • Follow Up
  • attach a document
  • delete activity from within manage case

Attachment is not deleted. @demeritcowboy is this expected?

@demeritcowboy
Copy link
Contributor Author

demeritcowboy commented May 19, 2020

@kcristiano Thanks for testing and thanks for thinking of civicase. Yes it is expected because in civicase nothing is ever fully deleted. In the activities section on manage case there's a semi-hidden accordion called "Search Filters" above the table and in there is a "Deleted Activities" checkbox. If you click that you'll see the activity you deleted.

If you want to see how that matches up in the code it's just a few lines down from the change I've made, around line 197 in the else block that handles "moveToTrash".

@kcristiano
Copy link
Member

Perfect. That makes sense and this looks good to merge.

@Stoob
Copy link
Contributor

Stoob commented May 25, 2020

jenkins retest this please

@kcristiano kcristiano added the merge ready PR will be merged after a few days if there are no objections label May 25, 2020
@Stoob
Copy link
Contributor

Stoob commented May 26, 2020

I have tested this PR.

The file is removed when the activity is deleted.

Attached screenshot is the result if you try to access it.

I can't personally think of a reason that deleting an entity in CiviCRM with an attached file wouldn't remove the file from the filesystem as well. This is the same behavior of Drupal when a node is deleted for what it's worth. But that doesn't mean that someone hasn't come to expect or use a file behavior in their workflow one way or the other. I seems unlikely they would, but I am not certain with whom to even check.

file

@jaapjansma
Copy link
Contributor

@demeritcowboy what do you think of the comment posted by @Stoob? If you agree we can ask @eileenmcnaughton or @mattwire to merge this.

@eileenmcnaughton
Copy link
Contributor

I'm +1 on merging this - I think people have kicked the tyres on it pretty well & tried to think of the edge cases.

@kcristiano has given it 'merge-ready' which should mean 'this is mergeable but giving a little more time for people to comment' - so I'll solicit last comments - really last objections on chat in case anyone has some

@demeritcowboy
Copy link
Contributor Author

test this please

@eileenmcnaughton eileenmcnaughton merged commit 6218310 into civicrm:master Jun 2, 2020
@demeritcowboy
Copy link
Contributor Author

Thanks everybody!

@demeritcowboy demeritcowboy deleted the activity-attachment-delete branch June 2, 2020 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants