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

Records from mdl_files_reference never deleted

XMLWordPrintable

    • MOODLE_27_STABLE, MOODLE_29_STABLE, MOODLE_30_STABLE, MOODLE_31_STABLE, MOODLE_35_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • MDL-57046_mdl_files_reference_cleanup
    • 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:
        1. update mdl_files set timemodified = timemodified - (60 * 60 * 24 * 14), timecreated = timecreated - (60 * 60 * 24 * 14);
        2. update mdl_files_reference set lastsync = lastsync - (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); update mdl_files_reference set lastsync = lastsync - (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

      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.

            Unassigned Unassigned
            tmuras Tomasz Muras
            Glyn (Mathew) May Glyn (Mathew) May
            Andrew Lyons Andrew Lyons
            Votes:
            5 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 20 minutes
                2h 20m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.