Restoring a Moodle 2 front page course to Moodle 3

Restoring a Moodle 2 front page course to Moodle 3

by Tony Atkin -
Number of replies: 1

Attempting to restore a backup of the front page from a Moodle 2.7 installation to the front page of a new Moodle 3.0 installation it failed with the message  "You can only restore front page backups on the front page"

I found a tracker which references this error, MDL-51448 but since Moodle Tracker is not accepting new accounts I thought to document how I worked around it here.

In /backup/util/helper/restore_prechecks_helper.class.php I found the following code:

        // The original_course_format var was introduced in Moodle 2.9.
        $originalcourseformat = null;
        if (!empty($controller->get_info()->original_course_format)) {
            $originalcourseformat = $controller->get_info()->original_course_format;
        }

        // We can't restore other course's backups on the front page.
        if ($controller->get_courseid() == SITEID &&
                $originalcourseformat != 'site' &&
                $controller->get_type() == backup::TYPE_1COURSE) {
            $errors[] = get_string('errorrestorefrontpagebackup', 'backup');
        }

        // We can't restore front pages over other courses.
        if ($controller->get_courseid() != SITEID &&
                $originalcourseformat == 'site' &&
                $controller->get_type() == backup::TYPE_1COURSE) {
            $errors[] = get_string('errorrestorefrontpagebackup', 'backup');
        }

This tests the state of the 'original_course_format' xml variable in the moodle_backup.xml file in the moodle backup it is trying to restore but does not seem to do anything useful in situations where that variable does not exist, pre 2.9.

As a work-around I unzipped the backup file from 2.7 then edited moodle_backup.xml to add the line:

<original_course_format>site</original_course_format> after the original_course_id line

Repacked the backup as a zip file, changed the extension from .zip to .mbz and successfully restored it to the front page course to the moodle 3.0 site as a full replacement.

So far this has only been used on a testing installation of Moodle 3.

Average of ratings: -
In reply to Tony Atkin

Re: Restoring a Moodle 2 front page course to Moodle 3

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Tony,

Thanks for this and sorry you were unable to create a tracker account at the time. This should be resolved. It would be greatly appreciated if you could comment on the tracker issue, that way there will be one location containing all the discussion.

Regards,

Mark