Uploaded image for project: 'Plugins'
  1. Plugins
  2. CONTRIB-8785

Importing quiz from sharing cart int oa hidden section generates failure under certain circumstances

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 3.11.4
    • Block: Sharing cart
    • None
    • 2021092900 ('3.10, release 8')
    • MOODLE_311_STABLE

      When a test activity is placed in the sharing cart from a source course and import from the sharing cart into a destination course, an "unexpected error" is displayed.

      With debug options turned on, an "invalid course module id" error is visible.

      This happens only if the following 4 criterias are met (if the first is missing the bug still exists, but with less consequences)

      • the test placed in the sharing cart has been configured with an activity completion set to "Student must receive a grade to complete this activity"
      • the source course contains at least one more grade item than thoses in the sharing cart (for instance 2 tests in the source course, then 2 grade items, but only one test in the sharing cart)
      • there is at least one grade already given to students in the destination course
      • the test is imported from sharing cart into a hidden section in the destination course

      After the bug appears ( "invalid course module id" error), if the Moodle script

      admin/cli/fix_course_sequence.php

      is run on the destination course, one "Failed integrity check..." is detected for the course, telling that "...Course module ... is missing from sequence of section ...". This sometime give another "invalid course module id" error when visiting the course gradebook settings page.

       

      Steps to reproduce :

      1. create a 1st course named 'source'
      2. insert 2 test activities inside, named 'q1' and 'q2'
      3. configure q1 with activity completion set as 'Student must receive a grade to complete this activity'
      4. create a second course named 'destination'
      5. create a user 'u1'
      6. manual enrol u1 in destination
      7. in destination, add a test activity named 'q3', with one true/false question
      8. connect as u1
      9. performs q3 (for the course to have one note in the gradebook)
      10. hide one section in destination
      11. install sharing cart plugin
      12. from source, insert q1 into the sharing cart
      13. in destination, import q1 from the sharing cart into the hidden section

      An error message should displays, and if admin/cli/fix_course_sequence.php is run against destination course, integrity problem should be detected

      Some observations from step to step debugging into the code :

      • the bug doesn't appears if the number of grade items in the sharing cart is the same as the one in the source course (as written in `backup/util/dbops/backup_plan_dbops.class.php`, at the end of `require_gradebook_backup()` function ) when activities are placed in the sharing cart. If the condition `$count == 0` returned by this function is false, a gradebook.xml is added in the xml files collection of the sharing cart (in backup_gradebook_structure_step), otherwise it miss. Why ?
      • during import from the sharing cart into the destination course, imported modules are first placed in a (random) section, then suppressed from it and, later, placed in the choosen section. Therefore, there is a small period of time with imported modules existing, but not placed in any course section (section is set in course_module table, but module is missing from sequence field in course_section table).
      • If a module is visible but the choosen section is hidden, then the plugin hide the module in accordance, and it performs this BEFORE placing the module in its definitive choosen section. When it hides the module, it also hide associated grade item. If the field `needupdate` of the grade item of type 'course' for the destination course is set to 1, then it launch grade recalculation and therefore try to get module info, from the list of modules in sequence fields in course_section table records for the destination course. But at this moment the course module is still in between its last section and the choosen section, so in any section. This leads to an invalidcoursemodule exception in

       lib/modinfolib.php:236, course_modinfo->get_cm() * {{}}if a gradeboox.xml file is in the sharing cart, the already mentionned `needupdate` filed is reseted to 0 during the import (in restore_gradebook_structure_step). This prevent recalculation during the critical period of time when the module is in any section and avoid the bug to appears.

      I can reproduce this bug with some Moodle versions :

      • 2021051700.08 (3.11+ (Build: 20210625))
      • 2021051703.10 (3.11.3+ (Build: 20211026)
      • 2021051704.04 (3.11.4+ (Build: 20211123))

      It doesn't seems to exists with Moodle versions :

      • 2020061500.00 (3.9 (Build: 20200615))
      • 2021112300.00 (4.0dev+ (Build: 20211123))

            ver2ons Akio Ohnishi (Inactive)
            didier.cadiou Didier Cadiou
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

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