i have a number of course that have been upgraded progressively from the old 1.9 days to Moodle 2.5
I want to get rid of the legacy files, because they are causing the backup files to swell to stupid sizes in the 1-3GB range.
But nothing seems to work. Turning them off, doesn't stop them entering the backup. Importing into a new course and then backing up, also doesn't prevent them showing up.
I have seen a lot of talk about this and this tracker issue seems to be about it.
Is there any way to kill legacy files, so they don't end up in the backup file?
OK, I found this closed tracker issue which explained it all:
To summarise it was previously possible to import without legacy files, but this was really a bug which suited some, but hindered more. So two fixes were made independently. One offered the user the option to opt out of legacy files in the import. The other always brought through legacy files. Ultimately it was decided that the latter was the best option because it applied to restore as well as import, and was a consistent policy.
Anyway following that, I found a solution. Comment out this line
Around line 74 of /backup/moodle2/restore_course_task.class.php
Then legacy files won't be restored. Just uncomment it when you don't need to kill legacy files anymore.
Actually it makes more sense to get rid of legacy files at at the backup stage. So to do that edit the /backup/moodle2/backup_stepslib.php file.
i) Around line 435, is list of backup steps. Remove "legacyfiles" from that list of steps
The unaltered list, looks like this:
$course = new backup_nested_element('course', array('id', 'contextid'), array(
'shortname', 'fullname', 'idnumber',
'summary', 'summaryformat', 'format', 'showgrades',
'marker', 'maxbytes', 'legacyfiles', 'showreports',
'visible', 'groupmode', 'groupmodeforce',
'defaultgroupingid', 'lang', 'theme',
'enablecompletion', 'completionstartonenrol', 'completionnotify'));
ii) And on line 515, comment out this line:
$course->annotate_files('course', 'legacy', null);
And an important part of this is the need to make sure that your course does not still depend on legacy files. Otherwise you will cripple it in backup and restore, if you leave legacy files behind.
I decided it would be easier to write a plugin to copy legacy files into each file area they were required. Easier than doing it all manually that is. It wasn't easier, but if a few other people use it, perhaps it will have been time well spent.
It is a TinyMCE plugin, called "legacy files go poof." You will need to use it on each html editor/html area you wish to purge legacy files from. (Yup .. you read that right.) You go in, select all or some of the content, and press the "poof" icon. It will copy the files and update the html for you. Then you save the activity as usual. It works best if you turn off legacy files first in course settings. Then you will see the broken links turn into pictures and stuff.
I will try and make a video to make it clearer. But you can get the plugin from:
I too hope to solve this problem in two sites. Both are "old" sites originated around Moodle 1.4/1.5, successively upgraded to 1.9.19+. After a couple of failed attempts to upgrade the full sites to 2.2, we decided to take the manual backup/restore path, the target version was finally Moodle 2.4. By that time the opting out of "legacy files" was not possible, so both sites now contain legacy files.
There is no immediate problem, since we do not take "automatic" backups (we take site level backups). In fact the legacy files made the transition easier for most of the teachers and they still have nothing against them. My worry is that because of these legacy files we'll hit the wall in a future upgrade.
I haven't looked into the details, and wanted to say thank you for the work you have done!
Die Legacy Files, die.
Bug request for multiple legacy files delete: https://tracker.moodle.org/browse/MDL-36008 Good voting, sort of, and the possible cure is here thanks to Marina: https://tracker.moodle.org/browse/MDL-36121
Make sure you vote. Michael R has observed it has not reached 100 yet.