Moodle
  1. Moodle
  2. MDL-11211

Deletion of a course with published questions destroys quizzes in other courses that have used those questions.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.6.6, 1.7.3, 1.8.3, 1.9
    • Component/s: Questions, Quiz
    • Labels:
      None
    • Environment:
      Linux (Fedora Core 5), MySQL 4.1.20, PHP 4.3.8
    • Database:
      Any
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE
    • Rank:
      28602

      Description

      How to reproduce this problem (see http://moodle.org/mod/forum/discuss.php?d=61665#p351718) :

      1. Create a course (C1).
      2. Create a quiz (Z1) in C1.
      3. Create a question (Q1) in Default category and add it to Z1.
      4. Publish Q1.
      5. Create a course (C2).
      6. Create a quiz (Z2) in C2.
      7. Add Q1 to Z2.
      8. Delete C2.
      9. View Z1. It will have been destroyed.

      I've been studying this problem for several hours and it seems to me that there is a problem with the data model for quizzes and questions which causes this bug. Of course, I might not have an accurate picture of how the data model works. The use of comma separated question ids in the questions column of the quiz table implies to me that quiz/question relationships are maintained at the application layer instead of in the data model. The quiz_question_instances table implies by name and indicates in documentation (http://docs.moodle.org/en/Quiz_database_structure#quiz_question_instances) that it can be used to link questions to quizzes, but my experimentation has led me to conclude that it is the comma separated values in quiz.questions that define the relationship. If that is the case, I would humbly suggest that we reorganize the data model for quizzes and questions to facilitate relational integrity preservation at the database level, and allow for more efficient queries of quiz/question data. At least we could let quiz_question_instances define the relationships instead of quiz.questions. This would require a substantial amount of code changes, but I think it would be well worth it.

        Issue Links

          Activity

          Hide
          Dean Thayer added a comment -

          MDL-11081 refers to a restore operation, but it is the course deletion part of the restore operation which actually produces the problem.

          Show
          Dean Thayer added a comment - MDL-11081 refers to a restore operation, but it is the course deletion part of the restore operation which actually produces the problem.
          Hide
          Olli Salo added a comment -

          Janne Mikkonen submitted a patch for MDL-11081 last week. Could you check it (see http://tracker.moodle.org/browse/MDL-11081) and tell if his patch would solve this problem, too?

          Show
          Olli Salo added a comment - Janne Mikkonen submitted a patch for MDL-11081 last week. Could you check it (see http://tracker.moodle.org/browse/MDL-11081 ) and tell if his patch would solve this problem, too?
          Hide
          Dean Thayer added a comment -

          I will examine Janne's patch for MDL-11081 soon and report my results.

          Show
          Dean Thayer added a comment - I will examine Janne's patch for MDL-11081 soon and report my results.
          Hide
          Tim Hunt added a comment -

          You are right, the quiz database structure sucks. It has been like that for ages, and any change has to be tested incredibly carefully, therefore, it is almost always safer just to leave it as it is.

          To explain, the questions are linked both through quiz_question_instances, but also through the quiz.questions column. The quiz.questions column additionally contains '0's to indicate the page breaks, and is used to determine the order of the questions in the quiz.

          Show
          Tim Hunt added a comment - You are right, the quiz database structure sucks. It has been like that for ages, and any change has to be tested incredibly carefully, therefore, it is almost always safer just to leave it as it is. To explain, the questions are linked both through quiz_question_instances, but also through the quiz.questions column. The quiz.questions column additionally contains '0's to indicate the page breaks, and is used to determine the order of the questions in the quiz.
          Hide
          Tim Hunt added a comment -

          The patch for MDL-11081, which I have now checked in, should fix this.

          Note that this is no longer a problem in Moodle 1.9. Jamie Pratt's new question bank, which gets rid of the horrible notion of question categories shared between courses, means that this sort of problem is much less likely to arise in the future.

          Please can you upgrade to 1.8.2+, and confirm whether this is fixed for you now, then I will close the bug. Thank you.

          Show
          Tim Hunt added a comment - The patch for MDL-11081 , which I have now checked in, should fix this. Note that this is no longer a problem in Moodle 1.9. Jamie Pratt's new question bank, which gets rid of the horrible notion of question categories shared between courses, means that this sort of problem is much less likely to arise in the future. Please can you upgrade to 1.8.2+, and confirm whether this is fixed for you now, then I will close the bug. Thank you.
          Hide
          Tim Hunt added a comment -

          Any updates on this? If we still have a problem, I would like to fix it. If it is fixed, I would like to resove this issue. Thanks.

          Show
          Tim Hunt added a comment - Any updates on this? If we still have a problem, I would like to fix it. If it is fixed, I would like to resove this issue. Thanks.
          Hide
          Dean Thayer added a comment -

          I just finished deleting 93 courses, and I had no quiz question problems as a result. I would call this problem fixed, but in need of improvement. Perhaps I will start a new issue for the performance aspect.

          Show
          Dean Thayer added a comment - I just finished deleting 93 courses, and I had no quiz question problems as a result. I would call this problem fixed, but in need of improvement. Perhaps I will start a new issue for the performance aspect.
          Hide
          Tim Hunt added a comment -

          Thanks for the testing.

          For the improvement part, please do open a new issue.

          Show
          Tim Hunt added a comment - Thanks for the testing. For the improvement part, please do open a new issue.

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: