Reports: File trash (Orphaned file locator)

report_filetrash
Maintained by 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
811
103
7

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

Contributors

• Tue, Sep 3, 2013, 6:58 AM
Hi Anthony, thanks for taking a look at this. I have made the changes as suggested.
• Sat, Sep 21, 2013, 7:10 AM
Hi Anthony, I noticed that I forgot to upload my changes as a new version. I've done that now.
• Thu, Jun 5, 2014, 5:24 PM
Hi Barry. Thanks for sharing this report with the community and for fixing the issues mentioned above. I am going to approve it now.
During the review of the plugin, I found couple of issues that should raise your attention and be fixed in future updates of your
plugin.

Your report throws PHP "Notice: Array to string conversion in report/filetrash/lib.php on line 187". Please double check the arrays
processing there.

I believe your report should exclude the file /warning.txt in the filepool. It is supposed to stay there for admins who browse the
moodledata directory.

I noticed that you create functions in the global PHP scope without the valid frankenstyle prefix. This is strongly discouraged in
order to prevent collisions with (current and/or future) core code or some other plugin. See
http://docs.moodle.org/dev/Coding_style#Functions_and_Methods for details.

Please note that leading and trailing whitespace in strings is not supported by Moodle localisation tools. Translators of your
plugin will be unable to have them in their non-English strings. Please fix your English language pack so that it does not rely on
whitespace around the string value.

I believe you would consider this feedback for further versions of your report. Said that, you are cleared to land now. Runway free,
welcome to Plugins directory!
• Tue, Aug 12, 2014, 2:38 PM
Hi Barry, I like the sound of this add-on and we were quite keen to try it out. Is there any plan to update this addon to be compatible with Moodle 2.6?
We just tried installing this on our 3.6.3+ site and when we go to the report we just get a blank page.
Thanks
Anita
• Sun, May 17, 2015, 11:30 PM
Hi Anita, I have updated this plugin with a new version which also supports Moodle 2.6.
• Mon, May 18, 2015, 11:28 PM
I too had a blank screen on installation - this was solved by enabling php_fileinfo.dll
• Tue, May 19, 2015, 4:10 AM
Thanks Sarah. I have updated the description and the documentation to reflect this requirement
• 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?"
• 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)
• 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.

Jacques
• 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.
• Thu, May 28, 2015, 2:57 PM
Hi Barry,

It's working fine now, thanks !

Jacques
• Fri, May 29, 2015, 5:00 PM
Hi,

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?
• 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).
• 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.$mime='mime';
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.