Moodle
  1. Moodle
  2. MDL-15605

Convert question bank consistency checks described in MoodleDocs to health centre checks

    Details

    • Type: Task Task
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 1.7.6, 1.8.7, 1.9.3, 2.0
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE

      Gliffy Diagrams

        Activity

        Hide
        Tim Hunt added a comment -

        Not all of the checks apply before 1.9, so the back-porting was selective.

        Show
        Tim Hunt added a comment - Not all of the checks apply before 1.9, so the back-porting was selective.
        Hide
        Matthew Davidson added a comment -

        fixed some SQL problems in a solution for questions and categories without valid contexts. example(in MySQL the EXISTS function is misspelled as EXIST and it cannot work in a DELETE statement). Also sensed if questions exist in these orphaned categories and gave the SQL to delete these questions before deleting the categories. See attached .diff

        Show
        Matthew Davidson added a comment - fixed some SQL problems in a solution for questions and categories without valid contexts. example(in MySQL the EXISTS function is misspelled as EXIST and it cannot work in a DELETE statement). Also sensed if questions exist in these orphaned categories and gave the SQL to delete these questions before deleting the categories. See attached .diff
        Hide
        Matthew Davidson added a comment -

        fix

        Show
        Matthew Davidson added a comment - fix
        Hide
        Tim Hunt added a comment -

        Reopening so I can apply the fix.

        Matthew, you cannot delete questions like that. Look at the delete_question function in lib/questionlib.php to see some of the issues involved. In particular, note that it does not actually delete questions if they are still in use by a quiz, because that would break the display of past quiz results, which would be a very bad thing in an educational context.

        It is better to put up with lack of referential integrity in the database than to do that. For categories with questions, it would be better to move them to a valid category, and maybe change the category name or info to explain what happened. Have a look at the logic in question_save_from_deletion, which is called from question_delete_course_category if you really want to go at fixing this issue properly.

        Show
        Tim Hunt added a comment - Reopening so I can apply the fix. Matthew, you cannot delete questions like that. Look at the delete_question function in lib/questionlib.php to see some of the issues involved. In particular, note that it does not actually delete questions if they are still in use by a quiz, because that would break the display of past quiz results, which would be a very bad thing in an educational context. It is better to put up with lack of referential integrity in the database than to do that. For categories with questions, it would be better to move them to a valid category, and maybe change the category name or info to explain what happened. Have a look at the logic in question_save_from_deletion, which is called from question_delete_course_category if you really want to go at fixing this issue properly.
        Hide
        Matthew Davidson added a comment -

        Tim can I ask how a question or a category can lose it's context and still be used somewhere? I don't understand how this situation could happen. Also, a small amount of my fix should still apply since the SQL that I posted works and the previous SQL solution didn't.

        Show
        Matthew Davidson added a comment - Tim can I ask how a question or a category can lose it's context and still be used somewhere? I don't understand how this situation could happen. Also, a small amount of my fix should still apply since the SQL that I posted works and the previous SQL solution didn't.
        Hide
        Tim Hunt added a comment -

        For storing and organising questions, the key links are question -> question_category -> context.

        However, when questions are used, you get links quiz -> quiz_question_instances -> questions. And when random questions are involved, you get really hard-to-find links, which is something that has to be improved some day.

        Also, it is, unfortunately, possible to add questions to a quiz in one course, the move things around in the question bank, so the question ends up in somewhere unrelated to the quiz. That nasty possibility is something that was only realised recently: MDL-14802.

        However, I will apply the SQL syntax fix. Thanks for that.

        Show
        Tim Hunt added a comment - For storing and organising questions, the key links are question -> question_category -> context. However, when questions are used, you get links quiz -> quiz_question_instances -> questions. And when random questions are involved, you get really hard-to-find links, which is something that has to be improved some day. Also, it is, unfortunately, possible to add questions to a quiz in one course, the move things around in the question bank, so the question ends up in somewhere unrelated to the quiz. That nasty possibility is something that was only realised recently: MDL-14802 . However, I will apply the SQL syntax fix. Thanks for that.
        Hide
        Tim Hunt added a comment -

        By the way, what diff format is that? It would be much easier if you could generate standard unified diffs. http://docs.moodle.org/en/Development:How_to_create_a_patch. Don't worry about regenerating this patch, but in future ...

        Show
        Tim Hunt added a comment - By the way, what diff format is that? It would be much easier if you could generate standard unified diffs. http://docs.moodle.org/en/Development:How_to_create_a_patch . Don't worry about regenerating this patch, but in future ...
        Hide
        Tim Hunt added a comment -

        SQL fix applied. Thanks.

        Show
        Tim Hunt added a comment - SQL fix applied. Thanks.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: