Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-19894

Images in questions causes an error at backup

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.5
    • Fix Version/s: None
    • Component/s: Backup, Questions, Quiz
    • Labels:
      None
    • Database:
      PostgreSQL
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      Hi all,

      We have once more a problem witch course backups. A couple of tests figured out that the problem is related to quizzes. Please follow the steps to reproduce the bug.

      1. Create a question category which is associated with a course category.
      2. Create a multiple choice question and insert a picture into the question using the "Image to display" field. The image should be used nowhere else as content in the course.
      3. Create a quiz with this question
      4. Try to make a backup of the course including user data and the quiz
      Following errors will be shown up:
      Linked file images/pic.jpg doesn't exist

      When you exclude the quizzes from the backup, there will be no error.

      I can reproduce this issue on two different moodle installations.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            kburger Karsten Burger added a comment -

            Please find attached a possible solution. A developer should have a look to the sql-statement.

            Show
            kburger Karsten Burger added a comment - Please find attached a possible solution. A developer should have a look to the sql-statement.
            Hide
            anthoc1 Anthony O'Connell added a comment -

            We've had the same issue here and we have 10 installations. When we exclude quizzes from the backup, the backup works correctly. Removing all the images from the quizzes (we had images in questions, answers, and feedback) allows us to manually and automatically backup the course successfully. Would really love a fix for this because images make quizzes more interesting.

            Show
            anthoc1 Anthony O'Connell added a comment - We've had the same issue here and we have 10 installations. When we exclude quizzes from the backup, the backup works correctly. Removing all the images from the quizzes (we had images in questions, answers, and feedback) allows us to manually and automatically backup the course successfully. Would really love a fix for this because images make quizzes more interesting.
            Hide
            stronk7 Eloy Lafuente (stronk7) added a comment -

            Hi Karsten,

            can you confirm if the same happens with current Moodle 1.9.7+ ?

            I've followed your steps 1-4, using one image stored in site files in one question belonging to one category... and the backup is executed perfectly, with the image being included ok and without any error.

            I've:

            • category1 (which default questions category contains one multichoice question using one site image).
            • course1 in category1: with one quiz using the question above. It's displayed ok and included in backup ok too.

            Not sure if that's 100% your situation.

            Ciao

            Show
            stronk7 Eloy Lafuente (stronk7) added a comment - Hi Karsten, can you confirm if the same happens with current Moodle 1.9.7+ ? I've followed your steps 1-4, using one image stored in site files in one question belonging to one category... and the backup is executed perfectly, with the image being included ok and without any error. I've: category1 (which default questions category contains one multichoice question using one site image). course1 in category1: with one quiz using the question above. It's displayed ok and included in backup ok too. Not sure if that's 100% your situation. Ciao
            Hide
            kburger Karsten Burger added a comment -

            Hi Eloy

            Unfortunately I have currently no 1.9.7 installation available and we never install the + version. I can confirm the problem in 1.9.6 too.

            By the way, the backup executes perfectly but in my case there is an error message shown up before the backup starts. It's on the screen where all information of the backup is printed.

            Maybe Anthony can give us a hand too.

            Show
            kburger Karsten Burger added a comment - Hi Eloy Unfortunately I have currently no 1.9.7 installation available and we never install the + version. I can confirm the problem in 1.9.6 too. By the way, the backup executes perfectly but in my case there is an error message shown up before the backup starts. It's on the screen where all information of the backup is printed. Maybe Anthony can give us a hand too.
            Hide
            fikar Miroslav Fikar added a comment -

            I can confirm the issue with our 1.9.7+ installation (2007101570). I did the four step procedure of Carsten. I can provide exported XML file with one category and one question in it if needed (with figure encoded in base64).

            Show
            fikar Miroslav Fikar added a comment - I can confirm the issue with our 1.9.7+ installation (2007101570). I did the four step procedure of Carsten. I can provide exported XML file with one category and one question in it if needed (with figure encoded in base64).
            Hide
            fikar Miroslav Fikar added a comment -

            Hi Eloy,
            > I've followed your steps 1-4, using one image stored in site files in one question belonging to one category
            please store image in course files and not site files.
            Miroslav

            Show
            fikar Miroslav Fikar added a comment - Hi Eloy, > I've followed your steps 1-4, using one image stored in site files in one question belonging to one category please store image in course files and not site files. Miroslav
            Hide
            grupp Andreas Grupp added a comment -

            Hello to all

            I can confirm that the bug is still in a Moodle 1.9.8 (Build: 20100326).

            As far as I could analyse the problem the backup and the restore works - but on the first page after starting the backup the errors are shown! These errors are in my opinion "false negative" error-messages because

            • the images are there
            • they get included in the backup
            • the restore brings the images back again
            • and as far as I could see the restored tests work.

            But the normal users (and we have "some" of them ) are afraid because of the error messages.

            Andreas

            Show
            grupp Andreas Grupp added a comment - Hello to all I can confirm that the bug is still in a Moodle 1.9.8 (Build: 20100326). As far as I could analyse the problem the backup and the restore works - but on the first page after starting the backup the errors are shown! These errors are in my opinion "false negative" error-messages because the images are there they get included in the backup the restore brings the images back again and as far as I could see the restored tests work. But the normal users (and we have "some" of them ) are afraid because of the error messages. Andreas
            Hide
            nadavkav Nadav Kavalerchik added a comment -

            i can confirm this issue on Moodle 1.9.5 (Build: 20090515)

            Show
            nadavkav Nadav Kavalerchik added a comment - i can confirm this issue on Moodle 1.9.5 (Build: 20090515)
            Hide
            grupp Andreas Grupp added a comment -

            Hello again

            After the bug was still in the current version of Moodle (Moodle 1.9.10 (Build: 20101025))
            I tried to find the problem and think I found it. The bug is in line 505 of the before
            mentioned version of Moodle. The line looks like this:

            if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){

            I detected that SITEID always has a value of 1 in this lib. So I changed the code
            to the following line

            if (file_exists($CFG->dataroot.'/'.$course.'/'.$url)){

            by replacing SITEID with $course and this solved the problem. As I do not know wheter
            this is a good solution it would be great if someone more experienced than me could look
            whether this is fine.

            Andreas

            Show
            grupp Andreas Grupp added a comment - Hello again After the bug was still in the current version of Moodle (Moodle 1.9.10 (Build: 20101025)) I tried to find the problem and think I found it. The bug is in line 505 of the before mentioned version of Moodle. The line looks like this: if (file_exists($CFG->dataroot.'/'.SITEID.'/'.$url)){ I detected that SITEID always has a value of 1 in this lib. So I changed the code to the following line if (file_exists($CFG->dataroot.'/'.$course.'/'.$url)){ by replacing SITEID with $course and this solved the problem. As I do not know wheter this is a good solution it would be great if someone more experienced than me could look whether this is fine. Andreas
            Hide
            grupp Andreas Grupp added a comment -

            Hello again, probably especially to you Eloy as the assignee for this

            My last suggestion to fix this bug was not ok. After testing this I had to recognize that now an error while copying site files is coming up. So I analysed the code a little bit deeper.

            As I understand this the work of the problematic function should be to detect all files in questions that do not exist in the course files but only on site level. Because normally all linked files in a question exist on course level the function is not able to find the files on site level. The problem seems to be that the function only looks for linked files and does not distinguish between files on course and on site level. All course files are searched on site level where they normally do not exist - and then the error-message arises.

            I have now a new solution to solve the problem - not nice but it seems to work. The flow of logic would be the following:

            1. The first if() is untouched. It looks whether the file exists on site level.
            2. In the else-part of this if() there was until now only a notification that the file does not exist when not found on site level.
            3. I now introduced a nested if() in the else-part and look whether the file exists on course level. If yes nothing has to be done, if not the notification is sent.

            The code now looks like this and I hope this is now better (code startin in line 504):

                    foreach (array_keys($urls) as $url){
                        /* SITEID has the value 1. First test whether file exists on site-level */
                        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 {
                            /* Ok, file does not exist on site-level, perhaps on course-level? */
                            if (!file_exists($CFG->dataroot.'/'.$course.'/'.$url)){
                              notify(get_string('linkedfiledoesntexist', 'question', $url));
                            }
                        }
                    }

            A diff of the old to the new code gives me:

            504a505
            >             /* SITEID has the value 1. First test whether file exists on site-level */
            513c514,517
            <                 notify(get_string('linkedfiledoesntexist', 'question', $url));
            ---
            >                 /* Ok, file does not exist on site-level, perhaps on course-level? */
            >                 if (!file_exists($CFG->dataroot.'/'.$course.'/'.$url)){
            >                   notify(get_string('linkedfiledoesntexist', 'question', $url));
            >                 }

            Is this a better solution that works for all of you?

            Andreas

            Show
            grupp Andreas Grupp added a comment - Hello again, probably especially to you Eloy as the assignee for this My last suggestion to fix this bug was not ok. After testing this I had to recognize that now an error while copying site files is coming up. So I analysed the code a little bit deeper. As I understand this the work of the problematic function should be to detect all files in questions that do not exist in the course files but only on site level. Because normally all linked files in a question exist on course level the function is not able to find the files on site level. The problem seems to be that the function only looks for linked files and does not distinguish between files on course and on site level. All course files are searched on site level where they normally do not exist - and then the error-message arises. I have now a new solution to solve the problem - not nice but it seems to work. The flow of logic would be the following: The first if() is untouched. It looks whether the file exists on site level. In the else-part of this if() there was until now only a notification that the file does not exist when not found on site level. I now introduced a nested if() in the else-part and look whether the file exists on course level. If yes nothing has to be done, if not the notification is sent. The code now looks like this and I hope this is now better (code startin in line 504): foreach (array_keys($urls) as $url){ /* SITEID has the value 1. First test whether file exists on site-level */ 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 { /* Ok, file does not exist on site-level, perhaps on course-level? */ if (!file_exists($CFG->dataroot.'/'.$course.'/'.$url)){ notify(get_string('linkedfiledoesntexist', 'question', $url)); } } } A diff of the old to the new code gives me: 504a505 > /* SITEID has the value 1. First test whether file exists on site-level */ 513c514,517 < notify(get_string('linkedfiledoesntexist', 'question', $url)); --- > /* Ok, file does not exist on site-level, perhaps on course-level? */ > if (!file_exists($CFG->dataroot.'/'.$course.'/'.$url)){ > notify(get_string('linkedfiledoesntexist', 'question', $url)); > } Is this a better solution that works for all of you? Andreas
            Hide
            salvetore Michael de Raadt added a comment -

            Thanks for reporting this issue.

            We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

            If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

            Michael d;

            lqjjLKA0p6

            Show
            salvetore Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
            Hide
            deliot Dan Eliot added a comment -

            This affects Moodle 1.9.16 (Build: 20120109) as of 1-23-2012. I'm having this issue currently.

            Show
            deliot Dan Eliot added a comment - This affects Moodle 1.9.16 (Build: 20120109) as of 1-23-2012. I'm having this issue currently.
            Hide
            timhunt Tim Hunt added a comment -

            1.9.x is no longer supported, and this is not a problem in Moodle 2.0+, so closing. Sorry.

            Show
            timhunt Tim Hunt added a comment - 1.9.x is no longer supported, and this is not a problem in Moodle 2.0+, so closing. Sorry.

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: