Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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.
Sample Course used to reproduce this issue in Moodle 1.9.2+ (Build: 20080827)