# Restoring of user attempts in quiz module (attached solution)

## Details

• Type: Bug
• Status: Closed
• Priority: Critical
• Resolution: Fixed
• Affects Version/s: 1.5.4
• Fix Version/s:
• Component/s:
• Labels:
None
• Environment:
All
• Affected Branches:
MOODLE_15_STABLE
• Fixed Branches:
MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

## Description

• Introduction:

This issue AFAIK was discussed on MDL-3159, and reported on bugs #4054, #4139 and #4608.

At quiz changelog, appears the following entry:

2005-06-06 Monday 04:25 gustav_delius * restorelib.php: Restoring of user attempts and states disabled for now, see MDL-3159

I found a post at moodle forums, see:

http://moodle.org/mod/forum/discuss.php?d=30923

This post has a version of restorelib.php with attempts restore implemented.

I've used this modified version verifying the code against latest stable CVS version which at this time is 1.58.2.6 2006/02/14 22:55:11, for a mass restore due to an hard disk crash.

• Now, some interesting numbers involved on this work:
• 6989 users;
• 773 courses;
• 385 quiz;
• 9041 questions;
• 21025 attempts;

and 72 long hours recovering it .

All restored quizzes seem to be OK. For now, there were no problems detected among dozens of hand verifications. If some problem appears, I'll report them here.

Hope Gustav can integrate this code, will surely be very appreciated by moodle community.

## Activity

Hide
Martin Dougiamas added a comment -

From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 11 May 2006, 11:00 PM:

I took the liberty of adding the people involved so far in this issue. Hope my numbers can provide some trust for a code commit.

Last but not least thanks Julian: you save my day.

From Eloy Lafuente (stronk7 at moodle.org) Thursday, 11 May 2006, 11:54 PM:

IMO it will be really great to have attempts working on 1.5.4!

If somebody can check the patch (it's a huge one) works as expected (bug 3159)... I'm really out of time now

Thanks Paulo!

From Eloy Lafuente (stronk7 at moodle.org) Thursday, 11 May 2006, 11:54 PM:

From Gustav Delius (gwd2 at york.ac.uk) Friday, 12 May 2006, 02:27 PM:

I think it is highly unlikely that we can afford the manpower to implement this in 1.5.4. I do remember looking at the code when doing the restore for 1.6 and felt that it was not stable enough to go into Moodle 1.5. I think we have to devote our efforts to testing the restore code in 1.6 more before contemplating backporting it to 1.5.4.

From Eloy Lafuente (stronk7 at moodle.org) Friday, 12 May 2006, 05:21 PM:

Aha. That's another interesting path, backporting 1.6 restore code to 1.5.x... if the patch attached here doesn't suit your requirements for 1.5.x... nothing against it from me, of course.

Ciao

From Paulo Matos (paulo.matos at fct.unl.pt) Wednesday, 24 May 2006, 09:53 PM:

Well, as promissed here are some bug we found out:

• Random questions whith multichoice does not show the values on answers just a,b,c,d.
• In several places, namely while diplaying item analisys I got:

Error: Missing question options! (multichoice)

Can someone give me a hint where to look?

I put a testcase that is too big to be attached here:

http://moodle.fct.unl.pt/bug_report/

TIA. Paulo.

From Gustav Delius (gwd2 at york.ac.uk) Friday, 26 May 2006, 05:12 PM:

Paulo, thanks for your help with testing the restore code. Tim has now taken over maintenance of the question engine and I am assigning this bug to him.

From Paulo Matos (paulo.matos at fct.unl.pt) Friday, 26 May 2006, 09:58 PM:

Ok Delius! Tim, I'm willing to help to solve this issue, just too complicated to get it done without help in a reasonable amount of time. Don't hesitate in contact me. As I said before I experiencied an overall disk crash, I have a huge pressure to solve this issue.

Keep the good work guys.

Paulo.

From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 1 June 2006, 06:37 AM:

Tim, any hints on this?

From Paulo Matos (paulo.matos at fct.unl.pt) Tuesday, 6 June 2006, 02:35 AM:

I think I found the problem... options order are not recoded to the new IDs, as you can see bellow ($states[$i] for a single question)

$states->options->order is incorrect, as well as$states->seq_number...

I manage to see that the options reach the correct print_question_formulation_and_controls() function but as the order is incorrect it prints nothing....

Can now someone give me a small hint where to dig on??

Regards,

Paulo

Bellow is an smaple output of $states for a question while reviewing an attempt (mod/quiz/review.php?q=617&attempt=15581) ------------------------------------------------ STATES -------------------------------- stdClass Object ( [question] => 9793 [0] => 251594 [id] => 251594 [1] => 15581 [attempt] => 15581 [2] => 9793 [3] => 0 [originalquestion] => 0 [4] => 2 [seq_number] => 2 [5] => random9768-20216,20213,20214,20215,20217:20217 [6] => 1141912664 [timestamp] => 1141912664 [7] => 6 [event] => 6 [8] => 1 [grade] => 1 [9] => 1 [raw_grade] => 1 [10] => 0.1 [penalty] => 0.1 [11] => 0.0 [sumpenalty] => 0.0 [responses] => Array ( [] => 20217 ) [changed] => [options] => stdClass Object ( [order] => Array ( [0] => 20216 [1] => 20213 [2] => 20214 [3] => 20215 [4] => 20217 ) [question] => stdClass Object ( [0] => 9768 [id] => 9768 [1] => 621 [category] => 621 [2] => 0 [parent] => 0 [3] => 13. (7.0 × 106)/(2.0 × 10-6)= [name] => 13. (7.0 × 106)/(2.0 × 10-6)= [4] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^ { - 6} }} =$$ [questiontext] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^{ - 6} }} =$$ [5] => 1 [questiontextformat] => 1 [6] => [image] => [7] => 1 [defaultgrade] => 1 [8] => 0.1 [penalty] => 0.1 [9] => 3 [qtype] => 3 [10] => 1 [length] => 1 [11] => moodle.fct.unl.pt+060305202237+vwz4EM [stamp] => moodle.fct.unl.pt+060305202237+vwz4EM [12] => 4 [version] => 4 [13] => 0 [hidden] => 0 [options] => stdClass Object ( [0] => 6229 [id] => 6229 [1] => 9768 [question] => 9768 [2] => 0 [layout] => 0 [3] => 27611,27612,27613,27614,27615 [answers] => Array ( [27611] => stdClass Object ( [id] => 27611 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 12}$$ [answer] => $$3.5 \times 10^{ - 12}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27612] => stdClass Object ( [id] => 27612 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 6}$$ [answer] => $$3.5 \times 10^{ - 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27613] => stdClass Object ( [id] => 27613 [0] => 9768 [question] => 9768 [1] => 3.5 [answer] => 3.5 [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27614] => stdClass Object ( [id] => 27614 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 6}$$ [answer] => $$3.5 \times 10^{ 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27615] => stdClass Object ( [id] => 27615 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 12}$$ [answer] => $$3.5 \times 10^{ 12}$$ [2] => 1 [fraction] => 1 [3] => [feedback] => ) [20216] => [20213] => [20214] => [20215] => [20217] => ) [4] => 1 [single] => 1 ) [name_prefix] => resp9793_ [maxgrade] => 1 ) ) [last_graded] => stdClass Object ( [question] => 9793 [0] => 251594 [id] => 251594 [1] => 15581 [attempt] => 15581 [2] => 9793 [3] => 0 [originalquestion] => 0 [4] => 2 [seq_number] => 2 [5] => random9768-20216,20213,20214,20215,20217:20217 [6] => 1141912664 [timestamp] => 1141912664 [7] => 6 [event] => 6 [8] => 1 [grade] => 1 [9] => 1 [raw_grade] => 1 [10] => 0.1 [penalty] => 0.1 [11] => 0.0 [sumpenalty] => 0.0 [responses] => Array ( [] => 20217 ) [changed] => [options] => stdClass Object ( [order] => Array ( [0] => 20216 [1] => 20213 [2] => 20214 [3] => 20215 [4] => 20217 ) [question] => stdClass Object ( [0] => 9768 [id] => 9768 [1] => 621 [category] => 621 [2] => 0 [parent] => 0 [3] => 13. (7.0 × 106)/(2.0 × 10-6)= [name] => 13. (7.0 × 106)/(2.0 × 10-6)= [4] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^ { - 6} }} =$$ [questiontext] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^{ - 6} }} =$$ [5] => 1 [questiontextformat] => 1 [6] => [image] => [7] => 1 [defaultgrade] => 1 [8] => 0.1 [penalty] => 0.1 [9] => 3 [qtype] => 3 [10] => 1 [length] => 1 [11] => moodle.fct.unl.pt+060305202237+vwz4EM [stamp] => moodle.fct.unl.pt+060305202237+vwz4EM [12] => 4 [version] => 4 [13] => 0 [hidden] => 0 [options] => stdClass Object ( [0] => 6229 [id] => 6229 [1] => 9768 [question] => 9768 [2] => 0 [layout] => 0 [3] => 27611,27612,27613,27614,27615 [answers] => Array ( [27611] => stdClass Object ( [id] => 27611 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 12}$$ [answer] => $$3.5 \times 10^{ - 12}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27612] => stdClass Object ( [id] => 27612 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 6}$$ [answer] => $$3.5 \times 10^{ - 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27613] => stdClass Object ( [id] => 27613 [0] => 9768 [question] => 9768 [1] => 3.5 [answer] => 3.5 [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27614] => stdClass Object ( [id] => 27614 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 6}$$ [answer] => $$3.5 \times 10^{ 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27615] => stdClass Object ( [id] => 27615 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 12}$$ [answer] => $$3.5 \times 10^{ 12}$$ [2] => 1 [fraction] => 1 [3] => [feedback] => ) ) [4] => 1 [single] => 1 ) [name_prefix] => resp9793_ [maxgrade] => 1 ) ) ) ) From Tim Hunt (T.J.Hunt at open.ac.uk) Wednesday, 7 June 2006, 01:14 AM: Paulo, Sorry, no hints. I am still very new to this, and I suspect you now understand this part of the code better than me. It's really great that you are investigating this, and I hope your efforts are rewarded. From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 22 June 2006, 09:07 AM: Hi folks! Good news, seems that I finally get arround this one!!! The problem with random questions was that at restore time, parent field was not recoded at all on quiz_restore_questions(), and before calling quiz_recode_state_answer_field() recursively the$wrappedquestion was not set correctly.

I tested intensively this procedure with a lot of quiz attempts, all types of questions, however I had no questions of type

random+('MATCH' or 'RANDOMSAMATCH'), but they were afected for sure.

After all this work, I realized I had to do it by hand for some quizzes because they had new attempts (oh dear murphy ... ).

I forgot to mention the number of states involved on the big restore operation, just 507149.

See the new version of restorelib.php and give it a try!

Regards,

Paulo Matos

From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 22 June 2006, 09:21 AM:

Just upload the patch for those who want to see the differences between versions. Just +10 and -1 lines of code make the difference.

If someone could take the time to merge this it would be great.

Cheers,

Paulo Matos

Show
Martin Dougiamas added a comment - From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 11 May 2006, 11:00 PM: I took the liberty of adding the people involved so far in this issue. Hope my numbers can provide some trust for a code commit. Last but not least thanks Julian: you save my day. From Eloy Lafuente (stronk7 at moodle.org) Thursday, 11 May 2006, 11:54 PM: IMO it will be really great to have attempts working on 1.5.4! If somebody can check the patch (it's a huge one) works as expected (bug 3159)... I'm really out of time now Thanks Paulo! From Eloy Lafuente (stronk7 at moodle.org) Thursday, 11 May 2006, 11:54 PM: Adding the boss here too! From Gustav Delius (gwd2 at york.ac.uk) Friday, 12 May 2006, 02:27 PM: I think it is highly unlikely that we can afford the manpower to implement this in 1.5.4. I do remember looking at the code when doing the restore for 1.6 and felt that it was not stable enough to go into Moodle 1.5. I think we have to devote our efforts to testing the restore code in 1.6 more before contemplating backporting it to 1.5.4. From Eloy Lafuente (stronk7 at moodle.org) Friday, 12 May 2006, 05:21 PM: Aha. That's another interesting path, backporting 1.6 restore code to 1.5.x... if the patch attached here doesn't suit your requirements for 1.5.x... nothing against it from me, of course. Ciao From Paulo Matos (paulo.matos at fct.unl.pt) Wednesday, 24 May 2006, 09:53 PM: Well, as promissed here are some bug we found out: Random questions whith multichoice does not show the values on answers just a,b,c,d. In several places, namely while diplaying item analisys I got: Error: Missing question options! (multichoice) Can someone give me a hint where to look? I put a testcase that is too big to be attached here: http://moodle.fct.unl.pt/bug_report/ TIA. Paulo. From Gustav Delius (gwd2 at york.ac.uk) Friday, 26 May 2006, 05:12 PM: Paulo, thanks for your help with testing the restore code. Tim has now taken over maintenance of the question engine and I am assigning this bug to him. From Paulo Matos (paulo.matos at fct.unl.pt) Friday, 26 May 2006, 09:58 PM: Ok Delius! Tim, I'm willing to help to solve this issue, just too complicated to get it done without help in a reasonable amount of time. Don't hesitate in contact me. As I said before I experiencied an overall disk crash, I have a huge pressure to solve this issue. Keep the good work guys. Paulo. From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 1 June 2006, 06:37 AM: Tim, any hints on this? From Paulo Matos (paulo.matos at fct.unl.pt) Tuesday, 6 June 2006, 02:35 AM: I think I found the problem... options order are not recoded to the new IDs, as you can see bellow ($states [$i] for a single question) $states->options->order is incorrect, as well as$states->seq_number... I manage to see that the options reach the correct print_question_formulation_and_controls() function but as the order is incorrect it prints nothing.... Can now someone give me a small hint where to dig on?? Regards, Paulo Bellow is an smaple output of $states for a question while reviewing an attempt (mod/quiz/review.php?q=617&attempt=15581) ------------------------------------------------ STATES -------------------------------- stdClass Object ( [question] => 9793 [0] => 251594 [id] => 251594 [1] => 15581 [attempt] => 15581 [2] => 9793 [3] => 0 [originalquestion] => 0 [4] => 2 [seq_number] => 2 [5] => random9768-20216,20213,20214,20215,20217:20217 [6] => 1141912664 [timestamp] => 1141912664 [7] => 6 [event] => 6 [8] => 1 [grade] => 1 [9] => 1 [raw_grade] => 1 [10] => 0.1 [penalty] => 0.1 [11] => 0.0 [sumpenalty] => 0.0 [responses] => Array ( [] => 20217 ) [changed] => [options] => stdClass Object ( [order] => Array ( [0] => 20216 [1] => 20213 [2] => 20214 [3] => 20215 [4] => 20217 ) [question] => stdClass Object ( [0] => 9768 [id] => 9768 [1] => 621 [category] => 621 [2] => 0 [parent] => 0 [3] => 13. (7.0 × 106)/(2.0 × 10-6)= [name] => 13. (7.0 × 106)/(2.0 × 10-6)= [4] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^ { - 6} }} =$$ [questiontext] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^{ - 6} }} =$$ [5] => 1 [questiontextformat] => 1 [6] => [image] => [7] => 1 [defaultgrade] => 1 [8] => 0.1 [penalty] => 0.1 [9] => 3 [qtype] => 3 [10] => 1 [length] => 1 [11] => moodle.fct.unl.pt+060305202237+vwz4EM [stamp] => moodle.fct.unl.pt+060305202237+vwz4EM [12] => 4 [version] => 4 [13] => 0 [hidden] => 0 [options] => stdClass Object ( [0] => 6229 [id] => 6229 [1] => 9768 [question] => 9768 [2] => 0 [layout] => 0 [3] => 27611,27612,27613,27614,27615 [answers] => Array ( [27611] => stdClass Object ( [id] => 27611 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 12}$$ [answer] => $$3.5 \times 10^{ - 12}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27612] => stdClass Object ( [id] => 27612 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 6}$$ [answer] => $$3.5 \times 10^{ - 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27613] => stdClass Object ( [id] => 27613 [0] => 9768 [question] => 9768 [1] => 3.5 [answer] => 3.5 [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27614] => stdClass Object ( [id] => 27614 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 6}$$ [answer] => $$3.5 \times 10^{ 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27615] => stdClass Object ( [id] => 27615 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 12}$$ [answer] => $$3.5 \times 10^{ 12}$$ [2] => 1 [fraction] => 1 [3] => [feedback] => ) [20216] => [20213] => [20214] => [20215] => [20217] => ) [4] => 1 [single] => 1 ) [name_prefix] => resp9793_ [maxgrade] => 1 ) ) [last_graded] => stdClass Object ( [question] => 9793 [0] => 251594 [id] => 251594 [1] => 15581 [attempt] => 15581 [2] => 9793 [3] => 0 [originalquestion] => 0 [4] => 2 [seq_number] => 2 [5] => random9768-20216,20213,20214,20215,20217:20217 [6] => 1141912664 [timestamp] => 1141912664 [7] => 6 [event] => 6 [8] => 1 [grade] => 1 [9] => 1 [raw_grade] => 1 [10] => 0.1 [penalty] => 0.1 [11] => 0.0 [sumpenalty] => 0.0 [responses] => Array ( [] => 20217 ) [changed] => [options] => stdClass Object ( [order] => Array ( [0] => 20216 [1] => 20213 [2] => 20214 [3] => 20215 [4] => 20217 ) [question] => stdClass Object ( [0] => 9768 [id] => 9768 [1] => 621 [category] => 621 [2] => 0 [parent] => 0 [3] => 13. (7.0 × 106)/(2.0 × 10-6)= [name] => 13. (7.0 × 106)/(2.0 × 10-6)= [4] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^ { - 6} }} =$$ [questiontext] => $$\frac{{7.0 \times 10^6 }} {{2.0 \times 10^{ - 6} }} =$$ [5] => 1 [questiontextformat] => 1 [6] => [image] => [7] => 1 [defaultgrade] => 1 [8] => 0.1 [penalty] => 0.1 [9] => 3 [qtype] => 3 [10] => 1 [length] => 1 [11] => moodle.fct.unl.pt+060305202237+vwz4EM [stamp] => moodle.fct.unl.pt+060305202237+vwz4EM [12] => 4 [version] => 4 [13] => 0 [hidden] => 0 [options] => stdClass Object ( [0] => 6229 [id] => 6229 [1] => 9768 [question] => 9768 [2] => 0 [layout] => 0 [3] => 27611,27612,27613,27614,27615 [answers] => Array ( [27611] => stdClass Object ( [id] => 27611 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 12}$$ [answer] => $$3.5 \times 10^{ - 12}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27612] => stdClass Object ( [id] => 27612 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { - 6}$$ [answer] => $$3.5 \times 10^{ - 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27613] => stdClass Object ( [id] => 27613 [0] => 9768 [question] => 9768 [1] => 3.5 [answer] => 3.5 [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27614] => stdClass Object ( [id] => 27614 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 6}$$ [answer] => $$3.5 \times 10^{ 6}$$ [2] => 0 [fraction] => 0 [3] => [feedback] => ) [27615] => stdClass Object ( [id] => 27615 [0] => 9768 [question] => 9768 [1] => $$3.5 \times 10^ { 12}$$ [answer] => $$3.5 \times 10^{ 12}$$ [2] => 1 [fraction] => 1 [3] => [feedback] => ) ) [4] => 1 [single] => 1 ) [name_prefix] => resp9793_ [maxgrade] => 1 ) ) ) ) From Tim Hunt (T.J.Hunt at open.ac.uk) Wednesday, 7 June 2006, 01:14 AM: Paulo, Sorry, no hints. I am still very new to this, and I suspect you now understand this part of the code better than me. It's really great that you are investigating this, and I hope your efforts are rewarded. From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 22 June 2006, 09:07 AM: Hi folks! Good news, seems that I finally get arround this one!!! The problem with random questions was that at restore time, parent field was not recoded at all on quiz_restore_questions(), and before calling quiz_recode_state_answer_field() recursively the$wrappedquestion was not set correctly. I tested intensively this procedure with a lot of quiz attempts, all types of questions, however I had no questions of type random+('MATCH' or 'RANDOMSAMATCH'), but they were afected for sure. After all this work, I realized I had to do it by hand for some quizzes because they had new attempts (oh dear murphy ... ). I forgot to mention the number of states involved on the big restore operation, just 507149. See the new version of restorelib.php and give it a try! Regards, Paulo Matos From Paulo Matos (paulo.matos at fct.unl.pt) Thursday, 22 June 2006, 09:21 AM: Just upload the patch for those who want to see the differences between versions. Just +10 and -1 lines of code make the difference. If someone could take the time to merge this it would be great. Cheers, Paulo Matos
Hide
Tim Hunt added a comment -

It would be nice to get this working for 1.7, but no promises.

Show
Tim Hunt added a comment - It would be nice to get this working for 1.7, but no promises.
Hide
Martin Dougiamas added a comment -

The patches that Paulo created are available here:

Show
Martin Dougiamas added a comment - The patches that Paulo created are available here: http://moodle.org/bugs/bug.php?op=show&bugid=5482
Hide
Paulo Matos added a comment -

I would make some effort to update it to 1.6.3! I'm moving from 1.5.4 to 1.6.3 in a few days.

Show
Paulo Matos added a comment - I would make some effort to update it to 1.6.3! I'm moving from 1.5.4 to 1.6.3 in a few days.
Hide
Tim Hunt added a comment -

It would be really brilliant if you could update your patch for Moodle 1.6.2+. If you do, I will happily deal with merging it into 1.7dev too. Thanks, Tim.

Show
Tim Hunt added a comment - It would be really brilliant if you could update your patch for Moodle 1.6.2+. If you do, I will happily deal with merging it into 1.7dev too. Thanks, Tim.
Hide
Tim Hunt added a comment -

Paulo, did you get a chance to do any further work on this? Thanks.

Show
Tim Hunt added a comment - Paulo, did you get a chance to do any further work on this? Thanks.
Hide
Paulo Matos added a comment -

Yes I did, I also sent you an email with some questions, did you got it?

Show
Paulo Matos added a comment - Yes I did, I also sent you an email with some questions, did you got it?
Hide
Paulo Matos added a comment -

Hi Tim! I finally got the time to rewrite this patch to 1.6.x.

Unfortunatelly I was unable to test it as good as I wanted. Because my most complex course backups
are taking too much time to restore hitting all the time with php max_execution_time setting even with
2400 seconds and no load at all at the server (not even reaching this part).

This 20m test cycles are just killing me.

Do you have any course with a considerably number of different questions and question types,
random suffled questions through categories and several well known attempts?

rewritten but the semantics seem to be the same.

Please take some time with this, and get back to me.

Paulo

Show
Paulo Matos added a comment - Hi Tim! I finally got the time to rewrite this patch to 1.6.x. Unfortunatelly I was unable to test it as good as I wanted. Because my most complex course backups are taking too much time to restore hitting all the time with php max_execution_time setting even with 2400 seconds and no load at all at the server (not even reaching this part). This 20m test cycles are just killing me. Do you have any course with a considerably number of different questions and question types, random suffled questions through categories and several well known attempts? Anyway. I just releasing the code for your review and test. Multichoice qtype had restore_recode_answer rewritten but the semantics seem to be the same. Please take some time with this, and get back to me. Paulo
Hide
Paulo Matos added a comment -

Patch Updated/Verified against moodle tree v1.6.4+ (2006050540).

Show
Paulo Matos added a comment - Patch Updated/Verified against moodle tree v1.6.4+ (2006050540). This still need some production testing. If you reached here this might be your chance, please report your experiences (good or bad)!
Hide
Paulo Matos added a comment -

I found an error on my previous submitted patches, on file moodle/question/type/random/questiontype.php
which I can't explain how it happened because restore simply breaks, well it's a worng table name on
$wrappedquestion->qtype = get_field('quiz_questions', 'qtype', 'id',$wrapped->new_id);
it must be:
$wrappedquestion->qtype = get_field('question', 'qtype', 'id',$wrapped->new_id);

Along the way I found out a more subtle one, with qtype on moodle/question/restorelib.php, now it's used
the name of qtype instead of id.

The other differences are new corrections.

Hunt it Tim!

Show
Paulo Matos added a comment - I found an error on my previous submitted patches, on file moodle/question/type/random/questiontype.php which I can't explain how it happened because restore simply breaks, well it's a worng table name on get_field, so instead of: $wrappedquestion->qtype = get_field('quiz_questions', 'qtype', 'id',$wrapped->new_id); it must be: $wrappedquestion->qtype = get_field('question', 'qtype', 'id',$wrapped->new_id); Along the way I found out a more subtle one, with qtype on moodle/question/restorelib.php, now it's used the name of qtype instead of id. The other differences are new corrections. Hunt it Tim!
Hide
Paulo Matos added a comment -

Here goes another version of the patch, this time I made a few verifications to make it stronger against backups with problems on random questions.
Sometimes backups are messed up and there are present some attempts that should not be there.

Show
Paulo Matos added a comment - Here goes another version of the patch, this time I made a few verifications to make it stronger against backups with problems on random questions. Sometimes backups are messed up and there are present some attempts that should not be there.
Hide
Paulo Matos added a comment -

Tim... does this code area has changed much in 1.7 and 1.8?
If not, this might be easy to merge.
Hope to hear your thoughts on this.

Paulo

Show
Paulo Matos added a comment - Tim... does this code area has changed much in 1.7 and 1.8? If not, this might be easy to merge. Hope to hear your thoughts on this. Paulo
Hide
Tim Hunt added a comment -

I was just having a bit of a look at this.

Question: Why does the patch only changes some, but not all of the question types? (Perhaps I just need to study it more.)

Also, note, the latest patch applies cleanly to 1.6 stable.

It mostly applies to 1.7 and 1.8 stable. Only the multichoice and truefalse parts don't, and they look pretty easy to fix.

Show
Tim Hunt added a comment - I was just having a bit of a look at this. Question: Why does the patch only changes some, but not all of the question types? (Perhaps I just need to study it more.) Also, note, the latest patch applies cleanly to 1.6 stable. It mostly applies to 1.7 and 1.8 stable. Only the multichoice and truefalse parts don't, and they look pretty easy to fix.
Hide
Paulo Matos added a comment -

Answering to your question: I fixed errors on match, multichoice and truefalse and implemented restore_recode_answer() on random the others are correct.

Paulo

Show
Paulo Matos added a comment - Answering to your question: I fixed errors on match, multichoice and truefalse and implemented restore_recode_answer() on random the others are correct. Paulo
Hide
Paulo Matos added a comment - - edited

Tim.. I know you're burried until your neck with work, but don't let this baby without it's 1st birthday present.
Cheers,
Paulo.

Show
Paulo Matos added a comment - - edited Tim.. I know you're burried until your neck with work, but don't let this baby without it's 1st birthday present. Cheers, Paulo.
Hide
Tim Hunt added a comment -

I managed to find a bit of time to work on this! I managed to apply the patch to Moodle 1.9 beta2+, with a few changes. The result is attached. Unfortunately, I have not run out of time again, and this needs a lot of testing. Any help anyone can give me is greatly appreciated.

Show
Tim Hunt added a comment - I managed to find a bit of time to work on this! I managed to apply the patch to Moodle 1.9 beta2+, with a few changes. The result is attached. Unfortunately, I have not run out of time again, and this needs a lot of testing. Any help anyone can give me is greatly appreciated.
Hide
Tim Hunt added a comment -

And here is a patch against 1.8.3+ from a few days ago. I don't think 1.8 is changing very much, so it should apply quite easily.

Show
Tim Hunt added a comment - And here is a patch against 1.8.3+ from a few days ago. I don't think 1.8 is changing very much, so it should apply quite easily.
Hide
Tim Hunt added a comment -

In my patch, it does not correctly restore the parentid column for random questions. I was testing that when I ran out of time.

Show
Tim Hunt added a comment - In my patch, it does not correctly restore the parentid column for random questions. I was testing that when I ran out of time.
Hide
Paulo Matos added a comment -

Yes, random questions have parent field set to its own id. Most of other types set to zero (0) and, if recall correctly, multi* are set to the "real" parents. I can't recall where, only thing i can say is that it was done correctly on 1.6.x.

Show
Paulo Matos added a comment - Yes, random questions have parent field set to its own id. Most of other types set to zero (0) and, if recall correctly, multi* are set to the "real" parents. I can't recall where, only thing i can say is that it was done correctly on 1.6.x.
Hide
Paulo Matos added a comment -

Hi Tim et al!
I reviewd your update patch and fixed parent id of random questions. I rewrote that part, moving the code from the "if ($question_exists)" block on restorelib to a bit after, so now it's less complicated and more readable. Hopefully this part of the code has not changed in CVS, so I think this time you'll be able to merge it into the tree. Cheers, Paulo Show Paulo Matos added a comment - Hi Tim et al! I reviewd your update patch and fixed parent id of random questions. I rewrote that part, moving the code from the "if ($question_exists)" block on restorelib to a bit after, so now it's less complicated and more readable. Hopefully this part of the code has not changed in CVS, so I think this time you'll be able to merge it into the tree. Cheers, Paulo
Hide
Tim Hunt added a comment -

Just reviewing the latest patch.

1. In applies cleanly to the latest MOODLE_18_STABLE.

2. do we really need the else { // Handle old-style states in restore_recode_answer in random_qtype? I have never seen a state like that in the database. - Oh, I see, this matches code in restore_session_and_responses, so yes, we must correctly handle this case.

3. It does not apply cleanly to MOODLE_19_STABLE ... trying to merge by hand ... good, it is easy to merge.

Right, I think that is everything. I'm going to check this in - and we have not even got to this bug's 2nd birthday

Show
Tim Hunt added a comment - Just reviewing the latest patch. 1. In applies cleanly to the latest MOODLE_18_STABLE. 2. do we really need the else { // Handle old-style states in restore_recode_answer in random_qtype? I have never seen a state like that in the database. - Oh, I see, this matches code in restore_session_and_responses, so yes, we must correctly handle this case. 3. It does not apply cleanly to MOODLE_19_STABLE ... trying to merge by hand ... good, it is easy to merge. Right, I think that is everything. I'm going to check this in - and we have not even got to this bug's 2nd birthday
Hide
Tim Hunt added a comment -

Fix checked in.

I was also able to apply the patch to 1.6 and 1.7 stable branches, with a small amount of manual merger, so I applied the fix there too.

Thanks for you patience on this Paulo.

To any testers out there, further testing on this would be greatly appreciated.

Show
Tim Hunt added a comment - Fix checked in. I was also able to apply the patch to 1.6 and 1.7 stable branches, with a small amount of manual merger, so I applied the fix there too. Thanks for you patience on this Paulo. To any testers out there, further testing on this would be greatly appreciated.
Hide
Donna Hrynkiw added a comment -

I do not believe this bug is actually fixed as I just experienced this problem.

Backup was made under Moodle v1.9.7 and (attempted) restored to a difference instance, also on Moodle v1.9.7.

Show
Donna Hrynkiw added a comment - I do not believe this bug is actually fixed as I just experienced this problem. Backup was made under Moodle v1.9.7 and (attempted) restored to a difference instance, also on Moodle v1.9.7.
Hide
Donna Hrynkiw added a comment -
Show

## People

• Assignee:
Tim Hunt
Reporter:
Paulo Matos
Tester:
Nobody
Participants: