Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291377

Dealing with unexpected file deletion due to incorrect file usage

$
0
0

Problem/Motivation

Recently @catch, @webchick, @xjm, @cottser, @cilefen and I discussed #2801777: Give users the option to prevent drupal from automatically marking unused files as temporary , #2810355: $entity->isDefaultTranslation() behaves incorrectly when changing default translation, causing file/image field usage to be set to zero, causing files to be deleted and #2708411: [PP-1] editor.module's editor_file_reference filter not tracking file usage correctly for translations. We all agreed that the current file usage behaviour that is resulting in files being deleted when they are being used by a site is unacceptable and a critical issue.

This was also discussed at Drupal Dev Days Seville — see the meeting notes.

This issue is exist to propose a series of steps to mitigate and fix these related issues.

The current behaviour

As files are "used" in different situations we add to the counter in the file_usage table. As the usages are removed we subtract from the counter. Once the counter gets to 0 the file is made temporary in \Drupal\file\FileUsage\FileUsageBase::delete(). Then a cron process (file_cron()) comes along and deletes temporary files after system.file:temporary_maximum_age seconds.

There are several cases where that counter is not incremented or decremented correctly.

Regardless of all the sub-issues we have the known issue that this does not track usages added by content editors if they are able to add links to file but editing the source HTML. Also the system of maintaining a counter seems very fragile and evidence supports that :).

Which cases/issues are there?

These fall into clear buckets, along three axes:

  1. Field (image/file/entity reference) versus editor.module's editor_file_reference filter
  2. Entity revisions versus entity translations
  3. Data loss: yes or no
Short descriptionData loss?Field or filter?Revision or translation?IssueNotes
Deleting entity with revisions + image/file fieldnoFieldRevision#1239558: Deleting an entity with revisions and file/image field does not release file usage of non-default revisions, causing files to lingerNo data loss, but irrepairable, therefore still critical.
Changing default translation + image/file fieldYESFieldTranslation#2810355: $entity->isDefaultTranslation() behaves incorrectly when changing default translation, causing file/image field usage to be set to zero, causing files to be deletedThis was caused by the "fix" for another critical: #2787187: Data loss: Deleting a translation of an entity deletes all file_usage entries for files referenced by the entity
The critical #2666700: User profile images unexpectedly deleted was merged into this — it has the same root cause, but different steps to reproduce.
Generic entity reference fieldsYESFieldN/A#2826127: Usage of Files Referenced in Entity Reference Fields Not TrackedA missing feature. File usage support is only present on file and image fields, which subclass the generic entity reference field code.
Filter + translationsYES FilterTranslation#2708411: [PP-1] editor.module's editor_file_reference filter not tracking file usage correctly for translationsWas implemented using entity hooks before Translation API matured.
Filter + revisions + adding/removing imagesnoFilterRevision#2892368: editor.module's hook_entity_update() does not count file usages correctly when adding/removing images without creating new revisionsThe only "normal" priority issue here, because it cannot lead to data loss, and can be repaired
The mitigation for all the rows with YES in the Data loss? columnN/A#2801777: Give users the option to prevent drupal from automatically marking unused files as temporary This is a mitigation for:
  • existing sites that desperately need a solution NOW
  • sites where it doesn't matter if files end up getting deleted or not (running out of disk space is only an issue on sites where there is a lot of editing that includes the need for replacing one file with another, without having an old revision still pointing to it)

The downside: it becomes difficult to delete "unused" files, which can be a security problem (e.g. accidentally uploaded PDF with sensitive data, now how to delete it?). That's less of a problem than files just disappearing right under you though. Worst case, the site administrator could be asked to remove the file from disk manually.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD


Viewing all articles
Browse latest Browse all 291377

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>