Quiz broke when upgrading to 1.4

Quiz broke when upgrading to 1.4

by Héctor González Jaime -
Number of replies: 4
We upgraded moodle to 1.4 a couple of days back, and checking a course today shows some students notes changed.  If we review the student's answers we get this after the same question always:

Fatal error
: Call to a member function on a non-object in .../moodle/mod/quiz/lib.php on line 1005
This line is:
$nextquestionnumber = $QUIZ_QTYPES[$question->qtype]->print_question
($nextquestionnumber, $quiz, $question, $readonly, $details);

We edited the quiz after that, and found that the question couldn't be moved, editing the question fixed that, but the Fatal error remains at the same place.  After the error happens the question can't be moved again.

The upgrade went smoothly, as always, and the tables were upgraded.

This is on a GNU/Linux system (Debian woody) with PHP 4.1.2, which has been running moodle and upgrading since 1.2.0

Average of ratings: -
In reply to Héctor González Jaime

Re: Quiz broke when upgrading to 1.4

by Janne Mikkonen -
I got the same error message as well (php version 4.3.4), no problems at the upgrage process...
In reply to Janne Mikkonen

Re: Quiz broke when upgrading to 1.4

by Janne Mikkonen -
I only have one quiz that gives this error. Fortunately this course has just started and there is not much in it yet.

So I made a little chewing-gum fix:

  1. Dug up the backups of the older version's (1.3.3) database.
  2. Made a clone site of that older version
  3. In clone site I backed up the problematic course (there was only one quiz where this error appeared).
  4. Then I restored that backup as a new course to our upgraded (1.4+) installation.
  5. Renamed the old one with new name and renamed the restored one with the course's old name.
  6. Crossed my fingers and toes and hope that the teacher and students doesn't ever find out the difference...

- Janne -
In reply to Janne Mikkonen

Re: Quiz broke when upgrading to 1.4

by Héctor González Jaime -
Well, it was just one quiz here too, what is weird is we can move questions around, but it always breaks at question #8.

Guess it is a database value that is wrong.

Unfortunately this course is active and I can't try your fix. We have backups, but from previous reports it seems the quiz was damaged before, and 1.4.0 reacts to this quiz in a different way.  (it gives different totals depending on the page you are watching).

No other quiz has shown this problem so far.

In reply to Héctor González Jaime

Re: Quiz broke when upgrading to 1.4

by David Lamotte -

I have just been bitten by the same "Fatal error: Call to a member function on a non-object in .../mod/quiz/lib.php on line 1005".  From the code it looked like it was  trying to access a non-existant question. 

As it turns it was only happening on a quizz that we knew was corrupted.  When the quizz was being set up, I added but then deleted again 30 questions.  Looking at the database tables, the question details had been removed, but their question numbers had not been deleted (ie they were listed in quizz.questions, but not in quizz_questions.id).

I fixed my problem by removing the missing questions from the questions field of the quizz table.

BTW, we first noticed that we had a corrupt quizz as the marks were all being scaled out of 70, when we only had 40 questions.  It was then that we found the 30 phantom questions.

Hope this helps,

David