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

Fix orphaned questions script no longer works

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 3.8.2
    • Questions, Quiz
    • None
    • MOODLE_38_STABLE

      We were trying to run the script admin/cli/fix_orphaned_question_categories.php because we seem to have 10k> orphaned categories on our system.

      When run with --fix, it eventually stops on a category giving an error like this:

      Found orphaned category: Default for Q4 R&J A3
      Cleaning...!!! Can't find data record in database table context. !!!
      !! SELECT * FROM {context} WHERE id = ?
      [array (
        0 => '284088',
      )]
      Error code: invalidrecord !!
      !! Stack trace: * line 1562 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
      * line 1538 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
      * line 5213 of /lib/accesslib.php: call to moodle_database->get_record()
      * line 221 of /lib/classes/event/base.php: call to context::instance_by_id()
      * line 125 of /lib/classes/event/question_base.php: call to core\event\base::create()
      * line 383 of /lib/questionlib.php: call to core\event\question_base::create_from_question_instance()
      * line 271 of /lib/questionlib.php: call to question_delete_question()
      * line 87 of /admin/cli/fix_orphaned_question_categories.php: call to question_category_delete_safe()
       !!
      

      Pretty sure this is when it gets to the first category that has questions in it it needs to deal with. I haven't looked deep into it yet, but from the trace it seems pretty clear that it is attempting to fire an event for deleting a question, but the context doesn't exist (since this tool is exactly looking for categories in non-existent contexts...)

       

            Unassigned Unassigned
            emerrill Eric Merrill
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 15 minutes
                15m

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