Moodle

Unable to restore recent backup of old matching questions

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.9.3
  • Fix Version/s: None
  • Component/s: Backup, Questions
  • Labels:
    None
  • Environment:
    Moodle 1.9.3+ (Build: 20090122)
    PostgreSQL 8.1.4
  • Database:
    PostgreSQL
  • Affected Branches:
    MOODLE_19_STABLE

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.

Activity

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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: