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

[After fix MDL-79073] fix_orphaned_question_categories.php --fix trigger an exception

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.6, 4.3.9, 4.5.1
    • Questions
    • None
    • MOODLE_401_STABLE, MOODLE_403_STABLE, MOODLE_405_STABLE
    • MDL-79339-404
    • MDL-79339-405
    • MDL-79339-main
    • Hide
      1. Log in as admin
      2. Create a course
      3. Add a quiz
        • Name: My quiz
      4. From quiz navigation, choose Question bank
      5. From Select a category choose Top for My quiz
      6. Create a new question, e.g. True/False
      7. Add this new question to the quiz My Quiz
      8. Make an attempt with a student's account (Make sure the question is in used)
      9. From quiz navigation, choose Filters
        • Make a note of the ?contextid=<CONTEXTID> parameter in the URL
      10. Execute the following in your local DB (to simulate missing context)

        DELETE FROM moodle.m_context WHERE id = <CONTEXTID>;
        

      11. Execute the following:

        $ php admin/cli/fix_orphaned_question_categories.php --fix
        

      12. Confirm no exceptions were thrown
      Show
      Log in as admin Create a course Add a quiz Name: My quiz From quiz navigation, choose Question bank From Select a category choose Top for My quiz Create a new question, e.g. True/False Add this new question to the quiz My Quiz Make an attempt with a student's account (Make sure the question is in used) From quiz navigation, choose Filters Make a note of the ?contextid=<CONTEXTID> parameter in the URL Execute the following in your local DB (to simulate missing context) DELETE FROM moodle.m_context WHERE id = <CONTEXTID>; Execute the following: $ php admin/cli/fix_orphaned_question_categories.php --fix Confirm no exceptions were thrown
    • Hide

      Code verified against automated checks.

      Checked MDL-79339 using repository: https://github.com/StudiUM/moodle.git

      More information about this report

      Built on: Mon Mar 17 19:48:22 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-79339 using repository: https://github.com/StudiUM/moodle.git MOODLE_404_STABLE (0 errors / 0 warnings) [branch: MDL-79339-404 | CI Job ] MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-79339-405 | CI Job ] main (0 errors / 0 warnings) [branch: MDL-79339-main | CI Job ] More information about this report Built on: Mon Mar 17 19:48:22 UTC 2025

      Thank you for the correction in the MDL-79073.

      I tested your fix on my environment yesterday in preparation of the next migration. 
      It worked for a few records but after fixing some question_categories, I unfortunately had the same issue.
      Here are the logs I got:

      == Checking for orphaned categories ==
      Found orphaned category: Défaut pour test diff
      Cleaning...!!! Impossible de trouver l'enregistrement de données dans la table context de la base de données. !!!
      !! SELECT * FROM {context} WHERE id = ?
      [array (
        0 => '8040805',
      )]
      Error code: invalidrecord !!
      !! Stack trace: * line 1654 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
      * line 1630 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
      * line 5429 of /lib/accesslib.php: call to moodle_database->get_record()
      * line 751 of /lib/questionlib.php: call to context::instance_by_id()
      * line 522 of /lib/questionlib.php: call to question_move_questions_to_category()
      * line 272 of /lib/questionlib.php: call to question_save_from_deletion()
      * line 87 of /admin/cli/fix_orphaned_question_categories.php: call to question_category_delete_safe()
       !!

      I tried to execute this following command line:

      php admin/cli/fix_orphaned_question_categories.php --fix

       

        1. 79339 peer review - 404.png
          28 kB
          Andrew Gosali
        2. 79339 peer review - 405.png
          57 kB
          Andrew Gosali
        3. 79339 peer review - main.png
          39 kB
          Andrew Gosali

            binhdv83 Van Binh Dang
            Gurvan Gurvan Giboire
            Andrew Gosali Andrew Gosali
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 30 minutes
                1h 30m

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