Problem/Motivation

I have an entity reference field type for file entities on a custom block type. When a file is added (referenced) on the field, the usage is not recorded. This is a problem if you enable orphan file deletion.

Before working on this read #2821423: Dealing with unexpected file deletion due to incorrect file usage.

Steps to reproduce

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

N/A

API changes

Data model changes

Release notes snippet

Comments

dobrzyns created an issue. See original summary.

catch’s picture

Priority: Normal » Major

At least major if not critical.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xjm’s picture

Priority: Major » Critical

Yeah I think this is critical, since it will also result in unexpected deletion of the files.

effulgentsia’s picture

In #2831274-200: Bring Media entity module to core as Media module, I suggested removing the ability to make ER fields to file entities. Here's what I said in that comment:

Remove File from this screen. It's actually broken. If you select it, you get an ER field to File entities (not a File field, like you do if you picked File from the previous screen), which then lets you reference files that were uploaded to other nodes. But usage from such a reference isn't tracked, so if you delete the original node, you lose the file from these other places. Now that we have Media as an option, there's no reason to choose File on this screen.

There was a UX call following that comment where people on the UX team +1'd that suggestion, but I don't have the link to that recording at the moment (though I can dig it up if needed).

However, we don't have Media field in core yet, and even once we do, I don't know if we have sufficient consensus on removing ER fields to file entities. So, I don't know if we want to fix this issue by making usage tracking work, or if we want to "fix" it by removing ER fields to files.

effulgentsia’s picture

Issue tags: +Triaged D8 critical

I discussed this with @xjm, @catch, @alexpott, and @cottser. We agreed to keep this Critical for now, since it is a data integrity bug, so tagging it as triaged.

#2821423: Dealing with unexpected file deletion due to incorrect file usage is the issue for dealing with all the file usage problems more systemically, but that's a Plan issue for now, so the individual bugs are still independent issues.

#2862461: When adding a reference field, remove "File" from the offered entity types is the issue for deprecating ER fields to file entities in favor of using Media fields instead, per #5. However, while we can remove the capability from the UI, we'll still need to deal with BC for sites that already have this.

Therefore, this issue still needs to be addressed.

Wim Leers’s picture

I suggested removing the ability to make ER fields to file entities.

But that'd be breaking the integrity of the data modeling capabilities of Drupal. It'd also be a BC break.

Here's an alternative proposal:

  1. Move all the logic in FileFieldItemList::postSave() + FileFieldItemList::delete() + FileFieldItemList::deleteRevision() to hook_entity_insert() + hook_entity_update() + hook_entity_delete() + hook_entity_revision_delete() implementations owned by the file module
  2. The logic can remain largely the same, but would be called for every instanceof EntityReferenceFieldItemList, i.e. for every entity reference field
  3. Hence that'd solve this bug.
catch’s picture

Priority: Critical » Major
Issue tags: -Triaged D8 critical

Now that #2801777: Give users the option to prevent drupal from automatically marking unused files as temporary is in, this no longer results in unexpected file deletion. #2821423: Dealing with unexpected file deletion due to incorrect file usage is open as a critical meta-issue to discuss the broader approach on this. So I'm going to downgrade this to major after discussion with @xjm and @cilefen, since we feel effort would be better spent on replacing the file_usage system at this point. We can still fix this bug of course as a major.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative

Update IS.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.