Your Moodle version

Reports: File trash (Orphaned file locator)

Maintained by Picture of Barry Oosthuizen Barry Oosthuizen
Utility for listing, downloading and deleting orphaned files (file no longer referenced in the files db table but still present in the Moodle data and/or backup directory

The files in the Moodle data folder and backup folders are referenced in the "files" table in the database.  If you view the folders themselves you will find the sha1 hash code under which the file has been saved and referenced in the database.  If you have any orphaned files (files no longer referenced by the database but still present on your disk) it will be very difficult to find them.  This utility enables you to immediately receive a list of orphaned files together with the file type and size.  You can download the file to see what it is (the name is a sha1 hash so that won't give you any clues).  If you are happy to delete the file you can select it with the checkbox next to it's description and click delete.  You will be asked for confirmation before the file is finally deleted.

Please note:  This plugin requires the fileinfo PHP extension


Screenshot #0


Picture of Barry Oosthuizen
Barry Oosthuizen (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Barry Oosthuizen
    Tue, May 19, 2015, 4:10 AM
    Thanks Sarah. I have updated the description and the documentation to reflect this requirement
  • Picture of Blair F.
    Fri, May 22, 2015, 2:30 AM
    I am also getting an empty file list. I've checked with our I.T. guy and he says, "It should be okay… it comes with the php-common extension: fileinfo support => enabled" If we, in fact, have no files would the report return "no files found?"
  • Picture of Barry Oosthuizen
    Fri, May 22, 2015, 2:40 AM
    If you have no orphaned files (files which are no longer referenced in the database) a message should appear saying "no files found". Valid files (ones referenced in the db) are not listed.

    If you believe there is a bug you could set debugging to developer and report back what it says here (if anything)
  • Picture of Jacques Monnard
    Wed, May 27, 2015, 9:06 PM
    Hi Barry,

    We are also getting a blank page on Moodle 2.7. With debugging enabled, it appears there is a problem with php reaching its memory limit. Now we could increase the memory limit in php.ini, but our installation is working fine with the current limit, and we would prefer not having to change this. Instead, you could use the Moodle function "raise_memory_limit" in your plugin to temporarily increase the limit. This is what Moodle core code and plugins do when they require additional memory for some operations (e.g. backups). I tried this with your code and it works fine.

  • Picture of Barry Oosthuizen
    Thu, May 28, 2015, 4:36 AM
    Hi Jacques, Thanks for the useful report. I have updated the code now. Please let me know if it works ok now.
  • Picture of Jacques Monnard
    Thu, May 28, 2015, 2:57 PM
    Hi Barry,

    It's working fine now, thanks !

  • Picture of Iñigo Zendegi Urzelai
    Fri, May 29, 2015, 5:00 PM

    I've tested the plugin in several Moodle 2.7 instances and it works, but it has a performance issue: when there are many orphaned files in the list it takes several minutes to load the list (that's ok), but if only one file is checked to be deleted it takes several minutes to show the confirmation message and to delete that file. It seems like the plugin is executing something (maybe the query that loads the list) before the confirmation message and the deletion too, and I think it shouldn't, should it?
  • Picture of Barry Oosthuizen
    Thu, Jun 18, 2015, 4:21 AM
    Hi Iñigo, thanks for your feedback. I made a small change which will cut out one of the long file comparisons (so its 33% faster now).
  • Picture of Marcus Green
    Tue, Jun 30, 2015, 11:57 PM
    I found this report timed out on our site, which didn't surprise me as it does have a large number of files. I made it work by editing the file classes/classes.php and commenting out the lines
    //$finfo = finfo_open(FILEINFO_MIME_TYPE);
    //$mime = (string)finfo_file($finfo, $pathfile[0]);
    And adding a dummy value for the $mime variable as follows.
    After that it ran fairly quickly and I can live without knowing what the mime type is. The author might consider adding this as a toggle in the settings or as an option when starting to run the report. Anyway, many thanks for developing this and making it available.
  • Picture of Barry Oosthuizen
    Mon, Aug 3, 2015, 6:32 AM
    Thanks for the idea Marcus. I have updated the plugin to have a setting to show / hide file extensions. Hiding them will make the report much faster and hopefully prevent timeouts.
  • Picture of Geir Johansen
    Thu, Aug 20, 2015, 4:30 PM
    I've installed this plugin in Moodle 2.9.1+ but it seems like the plugin is not adding itself the admin menu. It's possible to bring up the file report by manually entering the /report/filetrash/index.php URL, but a "Section error" appears when trying to delete files. So perhaps some work is needed before this plugin is compatible with Moodle 2.9 ?
  • Picture of Justin Reeve
    Thu, Oct 22, 2015, 10:36 PM
    Installed this plugin in Moodle 2.6. I get the same problems as Geir Johansen: not adding itself to the admin menu, and "Section error" whenever I try to delete files.
  • Picture of Denis Massé
    Sat, Oct 24, 2015, 4:53 AM
    For Justin an Geir, i got the same problems and correct it by adding this line in settings.php file:

    $ADMIN->add('reports', new admin_externalpage('report_filetrash', get_string('pluginname', 'report_filetrash'), "$CFG->wwwroot/report/filetrash/index.php",'report/filetrash:view'));

    (base on report/security and modify for report_filetrtrash)

    Now i get the menu but still get "Section error" when i try delete files.
  • Picture of Barry Oosthuizen
    Sat, Oct 24, 2015, 11:14 PM
    Thanks for the reports and suggested fix. I have updated the plugin now. Hopefully this should fix the section error problems and make the report link show up.
  • Picture of Denis Massé
    Mon, Oct 26, 2015, 8:53 PM
    Thank Barry, its working fine for me on moodle 2.8
1 2
Please login to post comments