## 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
274
299
9

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

• 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.
• 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.
• 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 ?
• 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.
• 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.
• 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.
• Mon, Oct 26, 2015, 8:53 PM
Thank Barry, its working fine for me on moodle 2.8
• Tue, Dec 8, 2015, 1:31 PM
I get the following error when I run the plug-in:

Exception - RecursiveDirectoryIterator::__construct(/mnt/zion/neo/moodle_courses/student_vet): failed to open dir: No such file or directory

Is there anything I can do to fix it?

Rgds
Petras
• Tue, Dec 15, 2015, 10:00 AM
Hi Petras, we had a similar error and found we had a backup directory stipulated in our Admin/Courses/Backups info that didn't exist. So somewhere in your settings that path is listed but doesn't exist (isn't necessarily the backups). Maybe you could create the folder path or find the missing reference to it under the Administration area?
• Mon, Dec 21, 2015, 11:17 PM
Hi,
I have installed this plugin on our Moodle, it has brought up a huge list of backup files (.mbz) - around 1940 to be precise. I can click on the link and download these so they are present. When I follow the directory path they are not there, also when I try to delete it through the plugin it says "There was a problem deleting the following files" and makes me continue onto the report. Any ideas where these backups are, and why they aren't deleting through the plugin? Would love to clear them off the disk.
Cheers!
Scott