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, almost 13 years ago
Updated 16 January 2023, almost 2 years 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 review

Version

10.1

Component
File system 

Last updated about 10 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

Merge Requests

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 almost 2 years 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?

  • First commit to issue fork.
  • Merge request !10610Update files user id on user account cancel → (Open) created by mohit_aghera
  • Pipeline finished with Canceled
    6 days ago
    Total: 103s
    #372817
  • Pipeline finished with Success
    6 days ago
    Total: 368s
    #372822
  • 🇮🇳India mohit_aghera Rajkot

    I've addressed the feedback in #40
    I think node tests aren't required as such.

    Fixed a few more things in the PR
    - convert it to use OOP hooks
    - Fixed a few things in tests.
    - Tests seems green now.

    Hiding all the patches in favour of MR.

  • Pipeline finished with Failed
    6 days ago
    Total: 585s
    #373299
  • Pipeline finished with Success
    6 days ago
    Total: 316s
    #373310
  • 🇺🇸United States smustgrave

    Nice!

    Left 1 item of feedback on the MR.

Production build 0.71.5 2024