Non-core contributed modules

Book backup does not recreate links to quiz

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.9.4, 1.9.5
  • Fix Version/s: None
  • Component/s: Module: Book
  • Labels:
    None
  • Database:
    Any
  • Affected Branches:
    MOODLE_19_STABLE

Description

We are heavy users of the book feature, and within books use links back to resources, forums and quizzes.

When backing up a course, then restoring, the hyperlinks used within books linking to resources at the course level are recreated with new ID numbers. However, the links to quizzes remain hard-coded to the initial course.

Basically, this makes is a challenge to backup a course as a template and restore the course to create an entirely new course. The new course keeps its links to the initial course. It seems to only affect links to quiz modules, and not other modules/blocks.

Activity

Hide
Eloy Lafuente (stronk7) added a comment -

Moved to contrib and assigning to Petr, book guru. Thanks for report, Leszek!

Show
Eloy Lafuente (stronk7) added a comment - Moved to contrib and assigning to Petr, book guru. Thanks for report, Leszek!
Hide
Matt D. added a comment - - edited

We've experienced the same issue, but it only happens when using relative hyperlinks instead of absolute hyperlinks.

Results in a broken link when restoring: ../mod/quiz/view.php?id=123
Works correctly when restoring: http://hostname/mod/quiz/view.php?id=123

We use the book module to link to assignments, quizzes and forums. A solution is to edit the "/mod/book/backuplib.php" file and tell it to replace all relative links with absolute links.

Within the "book_encode_content_links" function, add the following after the "$result = $content;" line (around line 111):

$result = str_replace("../../", $CFG->wwwroot . "/", $result);
$result = str_replace("../", $CFG->wwwroot . "/mod/", $result);

And then add the following before the "return $result;" line:

$buscar="/(".$base."\/mod\/quiz\/view.php?id\=)([0-9]+)/";
$result= preg_replace($buscar,'$@QUIZVIEWBYID*$2@$',$result);

$buscar="/(".$base."\/mod\/assignment\/view.php?id\=)([0-9]+)/";
$result= preg_replace($buscar,'$@ASSIGNMENTVIEWBYID*$2@$',$result);

$buscar="/(".$base."\/mod\/forum\/view.php?id\=)([0-9]+)/";
$result= preg_replace($buscar,'$@FORUMVIEWBYID*$2@$',$result);

Then try backing up and restoring a course that was affected. The links should point to the new course.

Show
Matt D. added a comment - - edited We've experienced the same issue, but it only happens when using relative hyperlinks instead of absolute hyperlinks. Results in a broken link when restoring: ../mod/quiz/view.php?id=123 Works correctly when restoring: http://hostname/mod/quiz/view.php?id=123 We use the book module to link to assignments, quizzes and forums. A solution is to edit the "/mod/book/backuplib.php" file and tell it to replace all relative links with absolute links. Within the "book_encode_content_links" function, add the following after the "$result = $content;" line (around line 111): $result = str_replace("../../", $CFG->wwwroot . "/", $result); $result = str_replace("../", $CFG->wwwroot . "/mod/", $result); And then add the following before the "return $result;" line: $buscar="/(".$base."\/mod\/quiz\/view.php?id\=)([0-9]+)/"; $result= preg_replace($buscar,'$@QUIZVIEWBYID*$2@$',$result); $buscar="/(".$base."\/mod\/assignment\/view.php?id\=)([0-9]+)/"; $result= preg_replace($buscar,'$@ASSIGNMENTVIEWBYID*$2@$',$result); $buscar="/(".$base."\/mod\/forum\/view.php?id\=)([0-9]+)/"; $result= preg_replace($buscar,'$@FORUMVIEWBYID*$2@$',$result); Then try backing up and restoring a course that was affected. The links should point to the new course.
Hide
Petr Škoda (skodak) added a comment -

Relative links in Moodle are not going to work, sorry.

The standard links pointing to http://mysite/mod/quiz/view.php?id=123 work fine for me. If you enable debug mode the restore process will print the relinking info such as:

hjkkhjlhkjl<div><br /></div><div><a href="$@QUIZVIEWBYID*4@$" title="qui">quiz </a></div>
changed to
hjkkhjlhkjl<div><br /></div><div><a href="http://mysite/moodle19/mod/quiz/view.php?id=8" title="qui">quiz</a></div>

You can also validate that the backup xml contains links in the form href="$@QUIZVIEWBYID*4@$"

I can not reproduce this problem, sorry.

Petr

Show
Petr Škoda (skodak) added a comment - Relative links in Moodle are not going to work, sorry. The standard links pointing to http://mysite/mod/quiz/view.php?id=123 work fine for me. If you enable debug mode the restore process will print the relinking info such as:
hjkkhjlhkjl<div><br /></div><div><a href="$@QUIZVIEWBYID*4@$" title="qui">quiz </a></div>
changed to
hjkkhjlhkjl<div><br /></div><div><a href="http://mysite/moodle19/mod/quiz/view.php?id=8" title="qui">quiz</a></div>
You can also validate that the backup xml contains links in the form href="$@QUIZVIEWBYID*4@$" I can not reproduce this problem, sorry. Petr

Dates

  • Created:
    Updated:
    Resolved: