Link only partially updated on course restore

Link only partially updated on course restore

by Lea Cohen -
Number of replies: 3
One of our courses has Labels with links to various sections in the course.
When we backup the course and restore it as a new course, the link is only partially updated: the course id is updated to the new course id, but the section id in the link isn't updated. This leads to a "Can not find data record in course_sections database table" error, which makes sense, since the section id from the backed up course is not relevant in the restored course.

Is this a bug? Should Moodle be updating the section ids too? If so, how can it be fixed?

Average of ratings: -
In reply to Lea Cohen

Re: Link only partially updated on course restore

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It should be updated. If not, it is a bug.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Link only partially updated on course restore

by Lea Cohen -
Thanks. I'm a programmer - can you direct me a little, how to go about finding where the bug is?
Thank you very much.
In reply to Lea Cohen

Re: Link only partially updated on course restore

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Moodle backup and restore is quite a complex system (because it needs to be), so it may take some patience to work out. There are docs in the dev docs, which you can find an read if you want to add context to these hints:

The cold that tells the backup system that labels contain links that need to be updated is https://github.com/moodle/moodle/blob/master/mod/label/backup/moodle2/restore_label_activity_task.class.php#L54. That looks OK. That is, what needs to have links updated is specified by methods called define_decode_contents.

Then, the code that knows how to update links to specific course sections ... well it might either be in the core backup code. Or, if the URL is specific to the course format you are using, then in may be in the course format. This is done by methods with name define_decode_rules. Looking at
https://github.com/moodle/moodle/blob/6153be6850869cdc3a6ae925dcf6e688ac481333/backup/moodle2/restore_section_task.class.php#L139
https://github.com/moodle/moodle/blob/6153be6850869cdc3a6ae925dcf6e688ac481333/backup/moodle2/restore_course_task.class.php#L146
It seems like there is no code to rewrite links to section.

I have not looked in the tracker, to see if there is already a bug report for this.
Average of ratings: Useful (1)