Details
Description
While attempting to copy a course via backup/restore I received the error "Could not restore categories and questions!" and was left with a partially restored course. After much digging I found that question_match_qtype::restore_map() returns false when question_match_sub.questiontext contains a trailing space in the database.
Many matching questions have trailing spaces in this course, though they were probably entered long ago. We have had this course prior to Moodle 1.9, and I am not certain how/when these questions were entered into the system. Editing one of these questions, performing no changes, and clicking "Save changes" trims the whitespace correctly.
Despite having so many erroneous questions, the above error was not raised until such a matching question happened to be last in its category. The result of $QTYPES[$question->qtype]->restore_map() is overwritten by following questions without being checked.
http://cvs.moodle.org/moodle/question/restorelib.php?annotate=1.30.2.6&pathrev=MOODLE_19_STABLE#l484
Attached is snippet of the backup that exposed this bug.
Hotfix:
I was able workaround all this by running the following SQL and creating a new course backup:
UPDATE mdl_question_match_sub SET questiontext = trim(questiontext), answertext = trim(answertext)
Possible solution:
1. Results should be checked within question/restorelib.php: restore_questions() to correctly raise errors/notices.
2. Sources other than the Edit Question page (question import?) should be confirmed to properly trim input.
3. The upgrade process should trim question fields that may have been entered before proper trimming took place.
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