Moodle

attempts to restore course from backup (1.9) fails with: "Can't find the record for question [#] for which I am trying to restore a state"

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.9.2
  • Fix Version/s: None
  • Component/s: Backup
  • Labels:
    None
  • Environment:
    Apache2.2 PHP 5.2.5 including Windows versions
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_19_STABLE

Description

Restore Library issues under 1.9.2 + (Build: 20080827)

Problem (Similar to MDL-16155):

All attempts to restore course from backup (1.9) fails with:

"Can't find the record for question [#] for which I am trying to restore a state"

Result:

Produces invalid course module instances similar to issue MDL-14326 which is the result of zero instances in course_modules table for new course.

This error is encountered when:

<QUESTION_CATEGORY>
<QUESTIONS>
<QUESTION>

no loner includes a quiz question for which there are attempts and question states to be restored from backup.

The question/restorelib.php function question_states_restore_mods attempts to restore a question state for which there are no question record in backup_ids.table_name='question' for any given backup_ids.backup_code. When XML TAGS

<STATES>
<STATE>
<ID>31774</ID>
<QUESTION>7</QUESTION>

Tries to be recoded the attempt fails before attempting to recode the
answer field due to no matching record (old_id) being found in
backup_ids.

Solution:

mod/quiz/restorelib.php

function quiz_restore_mods and function quiz_recode_layout($layout, $restore) needs check of backup_ids WHERE table_name=`question` AND backup_code=".$restore->backup_unique_code to help enforce proper recoding of the the questions field for each valid question witin <QUESTIONS>.

function quiz_attempts_restore_mods($quiz_id,$info,$restore)
restores only those attempts and question states for questions
that have a valid entry in backup_ids.table_name=`question`.

question/restorelib.php

function question_states_restore_mods

Only restores question states for questions that exist in backup_ids.table_name=`question` where matching old_id and new_id can be obtained otherwise don't include the question state records for those questions that are not defined in <QUESTIONS><QUESTION>.
For those questions that do exist in backup_ids.table_name=`question` that have matching new_id=mdl_question.id entries make sure we don't try to restore question_states that have a null answer field due to NULL question qtype recode. The mdl_question_states.answer field cannot be null so we don't want to try to write a new question_states record that will fail anyhow. Checks for <NEWEST_STATES><NEWEST_STATE> since these fields cannot be null.

I have made some of these changes with very positive results and have tested with several course backups that were otherwise failing upon course resore with various issues including those encapulated by MDL-14326 which cannot prevent zero instance modules due to restore failure in question_states_restore_mods when we begin to recode the answer field.

Try proposed patches:

mod_quiz_restorelib.patch
question_restorelib.patch

Which will implement a few checks and balances to help avoid
restoration of data that will not be valid due to table
strcuture field enforcement rules or missing quiz questions
for which there are attempts and therefore question states.

  1. mod_quiz_restorelib.patch
    30/Aug/08 2:33 PM
    3 kB
    John T. Macklin
  2. question_restorelib.patch
    30/Aug/08 2:33 PM
    4 kB
    John T. Macklin
  1. course_modules_table-view.jpg
    191 kB
    30/Aug/08 3:04 PM
  2. course-result-topic_outline.jpg
    38 kB
    30/Aug/08 2:59 PM
  3. QuestionStatesError1.jpg
    146 kB
    30/Aug/08 2:33 PM
  4. question-states-null-answer.jpg
    140 kB
    30/Aug/08 2:57 PM

Activity

Hide
John T. Macklin added a comment -

Sample Course used to reproduce this issue in Moodle 1.9.2+ (Build: 20080827)

Show
John T. Macklin added a comment - Sample Course used to reproduce this issue in Moodle 1.9.2+ (Build: 20080827)
Hide
Robert Russo added a comment -

Any ideas on a fix for this. The patches don't seem to solve the issue.

Show
Robert Russo added a comment - Any ideas on a fix for this. The patches don't seem to solve the issue.
Hide
Eloy Lafuente (stronk7) added a comment -

Wow... this was really old.... so... we are missing (used) questions in the backup? Any idea, Tim?

Show
Eloy Lafuente (stronk7) added a comment - Wow... this was really old.... so... we are missing (used) questions in the backup? Any idea, Tim?
Hide
Tim Hunt added a comment -

No idea. It usually works.

There are probably ways to trick it. For example, I would guess that the following would not work.

1. Create a quiz that picks one random question from category X that is shared at site level.

2. Student attempts quiz.

3. Move all the questions from category X to category Y.

4. Create backup.

5. Try to restore.

But, normal situations should work fine.

Show
Tim Hunt added a comment - No idea. It usually works. There are probably ways to trick it. For example, I would guess that the following would not work. 1. Create a quiz that picks one random question from category X that is shared at site level. 2. Student attempts quiz. 3. Move all the questions from category X to category Y. 4. Create backup. 5. Try to restore. But, normal situations should work fine.
Hide
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
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
Michael de Raadt added a comment -

I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Show
Michael de Raadt added a comment - I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Dates

  • Created:
    Updated:
    Resolved: