Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-57046

Records from mdl_files_reference never deleted

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Development in progress
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 2.7.17, 2.9.9, 3.0.7, 3.1.3, 3.5.1, 3.7.1, 3.8
    • Fix Version/s: None
    • Component/s: Files API, Repositories
    • Testing Instructions:
      Hide

      Setup:

      1. Create new course ('Test Course')
      2. Navigate to Site administration -> Plugins -> Repositories -> Manage repositories
      3. Set "File system" to "Enabled and visible"
      4. Press save on the new page shown
      5. Once on the "Manage repositories" page scroll to "File system"
        1. Click on "Settings"
        2. Click on "Create a repository instance"
        3. Create new repository called "test1"
        4. Create a new file in the repository: echo Info > ../moodledata/repository/test1/info.txt

      Test:

      1. Navigate to "Test Course"
      2. Turn editing on
      3. Add file resource
        1. Choose a file from file system repository "test1"
        2. Select info.txt file
        3. Choose "Create an alias/shortcut to the file" option
      4. Review mdl_files_reference table and notice new entry there
      5. Review mdl_files table and notice new entries
      6. Delete the file resource from Moodle course
      7. Help Moodle clean up the old entries - age them by 2 weeks: update mdl_files set timemodified = timemodified - (60 * 60 * 24 * 14), timecreated = timecreated - (60 * 60 * 24 * 14);
      8. Run Moodle cron
      9. Review mdl_files table
        1. Confirm if the 4 entries have been removed (including draft file entries)
      10. If they are still there, run clean-up task manually: php admin/tool/task/cli/schedule_task.php --execute='\core\task\file_trash_cleanup_task'
      11. Review the mdl_files_reference table
        1. Confirm /info.txt reference entry has been removed
      Show
      Setup: Create new course ('Test Course') Navigate to Site administration -> Plugins -> Repositories -> Manage repositories Set "File system" to "Enabled and visible" Press save on the new page shown Once on the "Manage repositories" page scroll to "File system" Click on "Settings" Click on "Create a repository instance" Create new repository called "test1" Create a new file in the repository:  echo Info > ../moodledata/repository/test1/info.txt Test: Navigate to "Test Course" Turn editing on Add file resource Choose a file from file system repository "test1" Select info.txt file Choose "Create an alias/shortcut to the file" option Review mdl_files_reference table and notice new entry there Review mdl_files table and notice new entries Delete the file resource from Moodle course Help Moodle clean up the old entries - age them by 2 weeks: update mdl_files set timemodified = timemodified - (60 * 60 * 24 * 14), timecreated = timecreated - (60 * 60 * 24 * 14); Run Moodle cron Review mdl_files table Confirm if the 4 entries have been removed (including draft file entries) If they are still there, run clean-up task manually: php admin/tool/task/cli/schedule_task.php --execute='\core\task\file_trash_cleanup_task' Review the mdl_files_reference table Confirm /info.txt reference entry has been removed
    • Affected Branches:
      MOODLE_27_STABLE, MOODLE_29_STABLE, MOODLE_30_STABLE, MOODLE_31_STABLE, MOODLE_35_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-57046_mdl_files_reference_cleanup

      Description

      Records in mdl_files_reference are not deleted, even when resource that linked to them is removed and there are no more references from mdl_files to mdl_files_reference.

      Basically the table will grow forever - which is a problem for bigger Moodle installations.

      To reproduce the issue:
      1. Configure "File system" repository, put a file there.
      2. Create new course with a file resource. Choose a file from file system repository and pick "Create an alias/shortcut to the file" option.
      3. Review mdl_files_reference table and notice new entry there.
      4. Review mdl_files table - there will be 2 new records linking to mdl_files_reference (with ID set in column referencefileid) - one in user/draft and another in mod_resource/content.
      5. Delete resource.
      6. mod_resource/content entries from mdl_files will be gone, entry in mdl_files_reference stays.
      7. Edit your draft entries to speed up their clean up, e.g. run

      moosh sql-run 'UPDATE mdl_files SET timecreated = 0 WHERE component="user" AND filearea="draft" AND filename="."'
      

      8. Clear draft files

       ./admin/tool/task/cli/schedule_task.php --execute=\\core\\task\\file_trash_cleanup_task
      

      9. Notice that all entries from mdl_files that were referencing mdl_files_reference table are gone. The entry in mdl_files_reference is still there.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tmuras Tomasz Muras
            Peer reviewer:
            Mathew May
            Integrator:
            Andrew Nicols
            Participants:
            Component watchers:
            Matteo Scaramuccia, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Dates

              Created:
              Updated:

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 50 minutes
                1h 50m