When a user gets "cancelled reassign" uid's in the table file_managed don't get updated to the new uid (0) making them orphaned

Created on 29 February 2012, over 12 years ago
Updated 31 March 2023, over 1 year ago

Problem/Motivation

When users are canceled any files attached to that user are not updated and lead to orphaned files.

Steps to reproduce

  1. Create a test user
  2. Upload a file
  3. Cancel the test user selecting make content belong to anonymous
  4. Check the database and verify the file ownership is still to the ID of the deleted user

Proposed resolution

When a user is canceled make any files belong to anonymous.

Remaining tasks


Review

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Original Post

I think I said it in whole in the subject line.

I deleted two users but in the file_managed table the uids are still from the now deleted users. I would have thought the uids would be changed to zero (the anonymous user).

I'm guessing there needs to be a hook in the file module somewhere to pick up the "user reassign" action.

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
File systemΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Reg

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to RTBC over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    The approach was already validated before in #14 and I think this looks good as well, this has enough test coverage as well.

    I was doubting if the hook was the right place or if we should do it where the user actually gets removed, but I think this is better so that it all sticks in the file module.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    No longer applies.

    Fix looks good though

    +++ b/core/modules/file/tests/src/Functional/FileListingTest.php
    @@ -214,6 +217,57 @@ public function testFileListingUsageNoLink() {
    +    // Create node entity and attach the created file.
    +    $node = $this->drupalCreateNode(['type' => 'article', 'file' => $file]);
    +    $node->save();
    

    Why do we create a node and an entity to attach the file to?

    Isn't one (the entity test entity) enough?

Production build 0.71.5 2024