Moodle

Course backup connot find linked quiz pictures

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.2
  • Fix Version/s: None
  • Component/s: Backup
  • Labels:
    None
  • Environment:
    Debian / Linux
    OS X 10.5

Description

Course backup (with quizzes) returns an error message that the linked pictures don't exist:
[...]
Include Quizzes with user data
Linked file 3bildzeichen.JPG doesn't exist
Linked file 3bildzeichen_em0.jpg doesn't exist
Linked file 3bildzeichen_em1.jpg doesn't exist
[...]

  1. file_type_course.patch
    20/Aug/09 9:51 PM
    0.6 kB
    Bartosz Cisek
  2. fix_course_backup.diff
    07/May/09 7:24 PM
    1.0 kB
    Ibragimov Rinat
  1. image001.png
    63 kB
    18/Feb/09 1:37 PM
  2. image001.png
    98 kB
    18/Feb/09 1:37 PM

Issue Links

Activity

Hide
Olli Salo added a comment -

The attached files seem to get into the backup file, but does the backup work after restoring it? I tried it and it seems so, but can we be certain about it?

If somebody could tell us the error message is not that serious and we don't need to worry about, it could be cool - otherwise at least our teachers seem to stop using the backup feature, which is naturally a pity.

Show
Olli Salo added a comment - The attached files seem to get into the backup file, but does the backup work after restoring it? I tried it and it seems so, but can we be certain about it? If somebody could tell us the error message is not that serious and we don't need to worry about, it could be cool - otherwise at least our teachers seem to stop using the backup feature, which is naturally a pity.
Hide
Trevor Johnson added a comment -

We have the same issue.

The problem looks like its is in \Moodle\question\backuplib.php function question_insert_site_file_names

In his foreach loop the value of SITEID is incorrect.

foreach (array_keys($urls) as $url){
if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){ $inserturl = new object(); $inserturl->backup_code = $backup_unique_code; $inserturl->file_type = 'site'; $url = clean_param($url, PARAM_PATH); $inserturl->path = addslashes($url); $status = $status && insert_record('backup_files', $inserturl); } else { notify(get_string('linkedfiledoesntexist', 'question', $url)); }
}

If you add
echo $CFG->dataroot.'/'.SITEID.'/'.$url;
before
if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){
you will see SITEID <> the course ID.

Show
Trevor Johnson added a comment - We have the same issue. The problem looks like its is in \Moodle\question\backuplib.php function question_insert_site_file_names In his foreach loop the value of SITEID is incorrect. foreach (array_keys($urls) as $url){ if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){ $inserturl = new object(); $inserturl->backup_code = $backup_unique_code; $inserturl->file_type = 'site'; $url = clean_param($url, PARAM_PATH); $inserturl->path = addslashes($url); $status = $status && insert_record('backup_files', $inserturl); } else { notify(get_string('linkedfiledoesntexist', 'question', $url)); } } If you add echo $CFG->dataroot.'/'.SITEID.'/'.$url; before if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){ you will see SITEID <> the course ID.
Hide
Trevor Johnson added a comment -

Attached file 1 is displaying the issue
Attached file 2 is displaying the the incorrect SITEID in this case it should be 39 not 1

Show
Trevor Johnson added a comment - Attached file 1 is displaying the issue Attached file 2 is displaying the the incorrect SITEID in this case it should be 39 not 1
Hide
Dennis Meyer added a comment -

Same problem here But I'm not able to restore the file - it seems that moodle ran into a loop...

Show
Dennis Meyer added a comment - Same problem here But I'm not able to restore the file - it seems that moodle ran into a loop...
Hide
Ibragimov Rinat added a comment -

this fix may help

Show
Ibragimov Rinat added a comment - this fix may help
Hide
Ibragimov Rinat added a comment -

(look for fix_course_backup.diff file on the top of screen)

Show
Ibragimov Rinat added a comment - (look for fix_course_backup.diff file on the top of screen)
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Ibragimov,

I really don't get the point about your change in backup/backuplib.php

There are two functions there:

backup_copy_course_files(): in charge of copying course files to backup
backup_copy_site_files(): in charge of copying site files to backup

And each one, has its own source dir (SITEID for site and $preferences->backup_course for course) and that's correct. And that cannot be changed.

So the question is... from where can questions get images? both from course and from site? We have one preliminar step where modules are able to "inform" backup about what files they are using, both course and site files... perhaps questions are missing that ability?

Adding Tim here, in case he can clarify how it's supposed to work. Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Ibragimov, I really don't get the point about your change in backup/backuplib.php There are two functions there: backup_copy_course_files(): in charge of copying course files to backup backup_copy_site_files(): in charge of copying site files to backup And each one, has its own source dir (SITEID for site and $preferences->backup_course for course) and that's correct. And that cannot be changed. So the question is... from where can questions get images? both from course and from site? We have one preliminar step where modules are able to "inform" backup about what files they are using, both course and site files... perhaps questions are missing that ability? Adding Tim here, in case he can clarify how it's supposed to work. Ciao
Hide
Tim Hunt added a comment -

Here is a brief summary of how it should work.

  • If a question category is associated with a course cateogry context of the system context, then all associated files should be in the site files area.
  • If a question category is associated with a course context of activity context, then the associated files should be stored in the course files area.

So, backup_copy_site_files should use SITEID.

Show
Tim Hunt added a comment - Here is a brief summary of how it should work.
  • If a question category is associated with a course cateogry context of the system context, then all associated files should be in the site files area.
  • If a question category is associated with a course context of activity context, then the associated files should be stored in the course files area.
So, backup_copy_site_files should use SITEID.
Hide
Ibragimov Rinat added a comment -

So I'm disappointed.
Function question_insert_site_file_names($course, $backup_unique_code) in question\backuplib.php have $course parameter but it never used in function body.
It's called by function quiz_check_backup_mods in mod\quiz\backuplib.php only if $course != SITEID.

It seems that question_insert_site_file_names functionality was designed as if it name was question_insert_course_file_names.

Show
Ibragimov Rinat added a comment - So I'm disappointed. Function question_insert_site_file_names($course, $backup_unique_code) in question\backuplib.php have $course parameter but it never used in function body. It's called by function quiz_check_backup_mods in mod\quiz\backuplib.php only if $course != SITEID. It seems that question_insert_site_file_names functionality was designed as if it name was question_insert_course_file_names.
Hide
Tom Morris added a comment -

I implemented Ibragimov's code.

Results:
1. Error listings "Linked file... doesn't exist" do not appear on the "Backup Details"page. (hopeful result...)
2. Backup operation halts at the "Zipping backup" line.

Conclusion:
This problem is unresolved.

Given this problem:
1. My auto and manual course backups fail to complete – if I have questions with images linked to course files.
2. If I want to backup quizzes as part of normal backup operations, I am forced to eliminate all linked images in quiz questions.
3. If I want to include images in my quiz questions, then I cannot include quizzes as part of the periodic course backup.

This is not a minor problem.
This problem presents me with two mutually exclusive options. One imposes editorial control over question styles. The other removes the basic operation of data backup for crucial and laboriously constructed course elements.

I am not aware of reasonable workarounds that would allow me to achieve the desired result.

Show
Tom Morris added a comment - I implemented Ibragimov's code. Results: 1. Error listings "Linked file... doesn't exist" do not appear on the "Backup Details"page. (hopeful result...) 2. Backup operation halts at the "Zipping backup" line. Conclusion: This problem is unresolved. Given this problem: 1. My auto and manual course backups fail to complete – if I have questions with images linked to course files. 2. If I want to backup quizzes as part of normal backup operations, I am forced to eliminate all linked images in quiz questions. 3. If I want to include images in my quiz questions, then I cannot include quizzes as part of the periodic course backup. This is not a minor problem. This problem presents me with two mutually exclusive options. One imposes editorial control over question styles. The other removes the basic operation of data backup for crucial and laboriously constructed course elements. I am not aware of reasonable workarounds that would allow me to achieve the desired result.
Hide
Karsten Burger added a comment -

Ibragimoc's patch work for me on one specific course.

Tim mentioned that the behavior of moodle should be correct. I can't track the problem. Which influence can the patch have to other courses with quizzes?

Show
Karsten Burger added a comment - Ibragimoc's patch work for me on one specific course. Tim mentioned that the behavior of moodle should be correct. I can't track the problem. Which influence can the patch have to other courses with quizzes?
Hide
Bartosz Cisek added a comment -

In our case worked substitution "SITEID" to "$course" in question/backuplib.php at line 520. I also checked other courses and it seems that everything is fine.

Show
Bartosz Cisek added a comment - In our case worked substitution "SITEID" to "$course" in question/backuplib.php at line 520. I also checked other courses and it seems that everything is fine.
Hide
Bartosz Cisek added a comment -

I fully agree with Ibragimov Rinat. Function question_insert_site_file_names is called only when $course != SITEID so $course parameter can be safely used instead. Additionally few lines below every file is marked as "site" file: $inserturl->file_type = 'site';

Those DB records are later used to list files to back up in backup/backuplib.php function backup_copy_site_files(). Because $rootdir has hardcoded SITEID so there is no way to find those files under /moodledata/1/ and error is returned.

Changing file_type from "site" to "course" solved my problems with backup. Patch attached.

Show
Bartosz Cisek added a comment - I fully agree with Ibragimov Rinat. Function question_insert_site_file_names is called only when $course != SITEID so $course parameter can be safely used instead. Additionally few lines below every file is marked as "site" file: $inserturl->file_type = 'site'; Those DB records are later used to list files to back up in backup/backuplib.php function backup_copy_site_files(). Because $rootdir has hardcoded SITEID so there is no way to find those files under /moodledata/1/ and error is returned. Changing file_type from "site" to "course" solved my problems with backup. Patch attached.
Hide
Bartosz Cisek added a comment -

Substitution file type from "site" to "course". Fixes problem with backup of a course with quiz

Show
Bartosz Cisek added a comment - Substitution file type from "site" to "course". Fixes problem with backup of a course with quiz
Hide
Jakob Ackermann added a comment -

I'm using 1.9.9 and this issue still exist.

Show
Jakob Ackermann added a comment - I'm using 1.9.9 and this issue still exist.
Hide
Nadav Kavalerchik added a comment -

proposed patch:

foreach (array_keys($urls) as $url){
            if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){
                $inserturl = new object();
                $inserturl->backup_code = $backup_unique_code;
                $inserturl->file_type = 'site';
                $url = clean_param($url, PARAM_PATH);
                $inserturl->path = addslashes($url);
                $status = $status && insert_record('backup_files', $inserturl);
            } else {
                //notify(get_string('linkedfiledoesntexist', 'question', $url));
                // new code,follows...
                if (file_exists($CFG->dataroot.'/'.$course.'/'.$url)){
                  $inserturl = new object();
                  $inserturl->backup_code = $backup_unique_code;
                  $inserturl->file_type = 'course';
                  $url = clean_param($url, PARAM_PATH);
                  $inserturl->path = $course.'/'.addslashes($url);
                  $status = $status && insert_record('backup_files', $inserturl);
                } else {
                  notify(get_string('linkedfiledoesntexist', 'question', $url));
                }
            }
Show
Nadav Kavalerchik added a comment - proposed patch:
foreach (array_keys($urls) as $url){
            if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){
                $inserturl = new object();
                $inserturl->backup_code = $backup_unique_code;
                $inserturl->file_type = 'site';
                $url = clean_param($url, PARAM_PATH);
                $inserturl->path = addslashes($url);
                $status = $status && insert_record('backup_files', $inserturl);
            } else {
                //notify(get_string('linkedfiledoesntexist', 'question', $url));
                // new code,follows...
                if (file_exists($CFG->dataroot.'/'.$course.'/'.$url)){
                  $inserturl = new object();
                  $inserturl->backup_code = $backup_unique_code;
                  $inserturl->file_type = 'course';
                  $url = clean_param($url, PARAM_PATH);
                  $inserturl->path = $course.'/'.addslashes($url);
                  $status = $status && insert_record('backup_files', $inserturl);
                } else {
                  notify(get_string('linkedfiledoesntexist', 'question', $url));
                }
            }

Dates

  • Created:
    Updated: