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

After deleting a quiz, its question categories and questions remain in database

    Details

    • Testing Instructions:
      Hide

      Test #1 - Deleting an activity

      1. Create a course category.
      2. Create a course
      3. Create a quiz
      4. Create a question for the quiz
        1. Set the question category to "Default for <your quiz>"
      5. Delete the quiz
      6. Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories
        SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>";
        
        • There should be no entries returned.
      7. Create another quiz
      8. Create a question for the quiz
        1. Set the question category to "Default for <your course>"
      9. Delete the course
      10. Open a connection to the database and search for the "Default for <your quiz> & <your course>" entry in mdl_question_categories
        SELECT * FROM mdl_question_categories WHERE name = "Default for <your course>";
        
        • There should be no entries returned.
      11. Create a new course
      12. Create another quiz
      13. Create a question for the quiz
        1. Set the question category to "Default for <your category>"
      14. Delete the course category
      15. Open a connection to the database and search for the "Default for <your quiz> & < your course> & <your category>" entry in mdl_question_categories
        SELECT * FROM mdl_question_categories WHERE name = "Default for <your category>";
        
        • There should be no entries returned.

      Test #2 - CLI delete question

      1. Set up a pre-patch Moodle site:
        1. Create a course category.
        2. Create a course
        3. Create a quiz
        4. Create a question for the quiz
          1. Set the question category to "Default for <your quiz>"
        5. Delete the quiz
        6. Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories
          SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>";
          
          • There should be one result.
      2. Now upgrade the site to have the issue patch:
        1. Now run the admin/cli/fix_orphaned_question_categories.php script.
          • The script should print a list of orphaned categories that it need a clean up.
          • Assuming you used a clean site, there should be just one and it should be "Default for <your quiz>".
        2. Now run the admin/cli/fix_orphaned_question_categories.php script with the --fix option
        3. Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories
          SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>";
          
          • There should be no results.

      Test #3 - CLI rescue question

      1. Set up a pre-patch Moodle site:
        1. Create a course category.
        2. Create a course
        3. Create a quiz (Q1)
        4. Create a question for the quiz
          1. Set the question category to "Default for <your quiz>"
        5. Create a second quiz (Q2)
        6. Access the database
          1. Add a new quiz_slot row to put the question in the second quiz (you may need to adjust the values in the query below if your site is not clean (Table columns are id, slot, quizid, page, requireprevious, questionid, maxmark).
            INSERT INTO mdl_quiz_slots VALUES (2, 1, 2, 1, 0, 1, 1.0);
            
            • Confirm that Q2 now has a question (if it doesn't, double-check the values used for the previous step).
        7. Delete the Q1 quiz
        8. Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories
          SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>";
          
          • There should be one result.
      2. Now upgrade the site to have the issue patch:
        1. Now run the admin/cli/fix_orphaned_question_categories.php script.
          • The script should print a list of orphaned categories that it is cleaning up.
          • Assuming you used a clean site, there should be just one and it should be "Default for <your quiz>".
        2. Now run the admin/cli/fix_orphaned_question_categories.php script with the --fix option
        3. Open a connection to the database
          1. Search for the "Default for <your quiz>" entry in mdl_question_categories
            SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>";
            
          2. Search for the rescue entry in mdl_question_categories
            SELECT * FROM mdl_question_categories WHERE name like "Questions saved%";
            ###* There should be one result.
            
          3. Search for the question you added
            SELECT * FROM mdl_question;
            
            • The question should have it's category id set to the rescue category.
        4. Finally, check the Q2 quiz in the Moodle web interface, it should still have a question.
      Show
      Test #1 - Deleting an activity Create a course category. Create a course Create a quiz Create a question for the quiz Set the question category to "Default for <your quiz>" Delete the quiz Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>" ; There should be no entries returned. Create another quiz Create a question for the quiz Set the question category to "Default for <your course>" Delete the course Open a connection to the database and search for the "Default for <your quiz> & <your course>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your course>" ; There should be no entries returned. Create a new course Create another quiz Create a question for the quiz Set the question category to "Default for <your category>" Delete the course category Open a connection to the database and search for the "Default for <your quiz> & < your course> & <your category>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your category>" ; There should be no entries returned. Test #2 - CLI delete question Set up a pre-patch Moodle site: Create a course category. Create a course Create a quiz Create a question for the quiz Set the question category to "Default for <your quiz>" Delete the quiz Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>" ; There should be one result. Now upgrade the site to have the issue patch: Now run the admin/cli/fix_orphaned_question_categories.php script. The script should print a list of orphaned categories that it need a clean up. Assuming you used a clean site, there should be just one and it should be "Default for <your quiz>". Now run the admin/cli/fix_orphaned_question_categories.php script with the --fix option Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>" ; There should be no results. Test #3 - CLI rescue question Set up a pre-patch Moodle site: Create a course category. Create a course Create a quiz (Q1) Create a question for the quiz Set the question category to "Default for <your quiz>" Create a second quiz (Q2) Access the database Add a new quiz_slot row to put the question in the second quiz (you may need to adjust the values in the query below if your site is not clean (Table columns are id, slot, quizid, page, requireprevious, questionid, maxmark). INSERT INTO mdl_quiz_slots VALUES (2, 1, 2, 1, 0, 1, 1.0); Confirm that Q2 now has a question (if it doesn't, double-check the values used for the previous step). Delete the Q1 quiz Open a connection to the database and search for the "Default for <your quiz>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>" ; There should be one result. Now upgrade the site to have the issue patch: Now run the admin/cli/fix_orphaned_question_categories.php script. The script should print a list of orphaned categories that it is cleaning up. Assuming you used a clean site, there should be just one and it should be "Default for <your quiz>". Now run the admin/cli/fix_orphaned_question_categories.php script with the --fix option Open a connection to the database Search for the "Default for <your quiz>" entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name = "Default for <your quiz>" ; Search for the rescue entry in mdl_question_categories SELECT * FROM mdl_question_categories WHERE name like "Questions saved%" ; ###* There should be one result. Search for the question you added SELECT * FROM mdl_question; The question should have it's category id set to the rescue category. Finally, check the Q2 quiz in the Moodle web interface, it should still have a question.
    • Affected Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE
    • Pull Master Branch:
      MDL-47787-master

      Description

      When a quiz is created, a new question category for that quiz is automatically created. After that quiz is deleted, it's question category and questions in that category remain in database. Problem is that it is not possible to reach those orphaned questions and potentially to move them to some other category.

      Steps to reproduce the bug:

      1. Create a new course
      2. Add a quiz to the course, and name it NewQuiz
      3. Go to Editing quiz page
      4. In Question bank content block choose 'Default to NewQuiz' category
      5. Create a new question (e.g. a Short answer question) in 'Default to NewQuiz'
      6. Navigate to Site administration -> Plugins -> Question types -> Manage question types, and note the number of Short answer questions
      7. Navigate to Site administration -> Reports -> Question instances, choose the Short answer question type, and there should be one question in 'Quiz: NewQuiz' context.
      8. Now, delete the NewQuiz quiz from the course
      9. Navigate to Site administration -> Plugins -> Question types -> Manage question types. Number of Short answer questions has not changed
      10. Navigate to Site administration -> Reports -> Question instances, choose the Short answer question type. The 'Quiz: NewQuiz' context is not listed anymore.

      After deleting a quiz, it's context is deleted, but question category remains and points to nonexistent context. If you perform following query in database, you should be able to see 'Deault to NewQuiz' category:

      SELECT qc.id, qc.name, qc.contextid, qc.parent, ctx.*
      FROM mdl_question_categories qc
      LEFT OUTER JOIN mdl_context ctx ON ctx.id = qc.contextid
      WHERE ctx.id IS NULL;
      

      I would expect to either be able to access questions from deleted quiz, or that those category and questions are deleted together with quiz.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    6/Jul/15