Backup and restore question.

Backup and restore question.

by Tim Hunt -
Number of replies: 2
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
In backup/restore_execute.html, we have the code
$restore->backup_version = $info->backup_backup_version;

makes the backup version number from the backup file available to the restore code. That is coming from the <INFO>/<BACKUP_VERSION> tag in the backup XML file.

My question is: has that tag always been there? I am getting error reports from people trying to restore 1.4 backups incuding quiz questions. The problem is quiz question types used to be integers, and now they are strings, so they need to be converted. However the code
            if ($restore->backup_version < 2006032200) {
                // The qtype was an integer that now needs to be converted to the name
                $qtypenames = array(1=>'shortanswer',2=>'truefalse',3=>'multichoice',4=>'random',5=>'match',
                 6=>'randomsamatch',7=>'description',8=>'numerical',9=>'multianswer',10=>'calculated',
                 11=>'rqp',12=>'essay');
                $question->qtype = $qtypenames[$question->qtype];
            }

is already there. It is just not having any effect with old backup files. I am wondering whether $restore->backup_version may be undefined when restoring really old backup files, and therefore we need to apply the following patch? (I don't know the backup/restore code well enough to be sure.)

Index: backup/restore_execute.html
===================================================================
RCS file: /cvsroot/moodle/moodle/backup/restore_execute.html,v
retrieving revision 1.57
diff -u -r1.57 restore_execute.html
--- backup/restore_execute.html	3 Jun 2006 20:18:02 -0000	1.57
+++ backup/restore_execute.html	8 Aug 2006 16:57:10 -0000
@@ -15,7 +15,11 @@
     $restore->original_wwwroot = $info->original_wwwroot;
     //Add info->backup_version to $restore to be able to detect versions in the restore process
     //(to decide when to convert wiki texts to markdown...)
-    $restore->backup_version = $info->backup_backup_version;
+    if (!empty($info->backup_backup_version)) {
+        $restore->backup_version = $info->backup_backup_version;
+    } else {
+        $restore->backup_version = 0;
+    }

     //Check login
     require_login();

Average of ratings: -
In reply to Tim Hunt

Re: Backup and restore question.

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Tim,

if I'm not wrong, $restore->backup_version (the variable in the restore process) is available since 1.5. But the value in XML files have been present since the born of the backup procedure.

Also, I think that both undefined and empty values evaluate as 0 in comparisons (checked under PHP 4) so, your code to convert qtypes should be executed without problems both if the version is lower or undefined.

So, the problem should be in other place (I think). Perhaps such backups are buggy and they don't include such questions or the $restore variable arrives modified to the restore_questions() function. Uhm... one backup file could help to trace the problem...

Ciao smile

Edited: Oh, oh. I was just posting this message when I remember that, between 1.4 and 1.5 one alternative "mod/quiz/restorelibpre15.php" script was added, because changes were too big to handle all them in the same code. In theory it only worked with the module part (attempts and so on), not with the question bank but I'm pretty sure that it had some hardcoded qtypes using numbers. If it hasn't been upgraded to support the changes between 1.5 and 1.6, uhm, if can be the cause of problems restoring pre1.5 quizzes! sad
In reply to Eloy Lafuente (stronk7)

Re: Backup and restore question.

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Thanks for the speedy reply and the hints. I can probably work it out now.

I'm not that bothered about this, except that now two people have asked about restoring 1.4 era backup files into 1.6.

In both cases, it was the questions they wanted to get back, and that bit of it should be possible.