Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83272

Deleting a question bank category can orphan questions and break quizzes

XMLWordPrintable

      The question bank category screen has logic that prevents you from deleting a question category with questions in it. This logic requires you to move the questions to another category before the delete will process. For instance, if "Category A" has a question in it, you must first move the question to another category before you can delete category A.

      During the move phase, however, the interface presents the category you are deleting in the "move" pulldown. If you select that category, Moodle will delete the category, leaving the questions that were in it in an orphaned state. 

      Here are steps to reproduce the issue.

      1. From the course home page, choose more / question bank.
      2. Choose categories from the pulldown
      3. Add a new question category under TOP, calling it "Category A"
      4. Choose questions from the pulldown 
      5. Click "Create a new question". Create a question and put it into "Category A"
      6. Choose categories from the pulldown
      7. Confirm that "Category A" has 1 question in it.
      8. Delete "Category A". You will get a message asking you to move the questions to a different category.
      9. Choose "Category A" and click "Save in Category"
      10. The main question category screen will reappear. "Category A" will be gone.
      11. Go to questions, choose "top for (course)", check "also show questions from subcategories", click "apply filters"
      12. The question you created in Category A will not appear.

      Note that in the example above, if the question in "Category A" was used in a quiz, that quiz would not be usable by the end of the process. Going into to the quiz would yield a "Cant find data record in database" error. 

      Note that if you go into the database after running through the process above, the category record (mdl_question_categories) will no longer exist, but the following tables WILL still have records referencing the question that was in the category : mdl_question, mdl_question_bank_entries, mdl_question_versions. Also note that the questioncategoryid field of the mdl_question_bank_entries record will now reference a non-existent question category. So another negative consequence of this behavior is that it produces orphan records.

      The behavior that I would expect is as follows:

      A. The category you are deleting should not appear in the move pulldown
      B. There should be logic that executes immediately before the deletion of a category that stops the deletion if there are still questions in the category.

        1. MDL-83272.png
          MDL-83272.png
          162 kB
        2. qbankissue.mp4
          6.03 MB

            marxjohnson Mark Johnson
            jcoughli John Coughlin
            Luca Bösch Luca Bösch
            Tim Hunt Tim Hunt
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            1 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 10 minutes
                2h 10m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.