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

quiz_statistics ad-hoc task should not set a userid: prevents quiz submission if main admin is nologin

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-79747_401
    • MDL-79747_402
    • MDL-79747_403
    • Hide

      I think the most important thing to test is that with this change, computing stats for the question bank still works. So, copied from part of the MDL-78580 tests

      Real-world tests

      If you have a large enough quiz enough attempts that the statistics calculation takes a significant length of time, you can do a more realistic test. If you don't have one you can set one up with the following steps, which resulted in a 30 second calculation process on my machine, although it takes a long time to generate the data.

      Set up

      • Go to Site Administration > Development > Make test course.
      • Create an L-size course (this takes a while).
      • Restore the attached 10-question-quiz.mbz to the course and make a note of the cmid.
      • Place the attached test_big_stats_calc.php in the root of your moodle codebase, and run `php test_big_stats_calc.php --quizcmid=cmid --attempts=10000`. This will generate 10000 attempts at the quiz. This takes a long time.
      • You may want to create a snapshot of your database at this point so you can roll back to re-run the tests. You can also re-attempt the quiz as any student before each test scenario to trigger the recalculation.

      Test 1 - Question bank

      1. If needed, reset the database or re-attempt the quiz.
      2. Navigate to the quiz
      3. Go to the "Question bank" tab.
        1. The page should load immediately, and show an empty or N/A result in the "Needs checking?", "Facility index" and "Discriminative efficiency" statistics columns.
      4. In the terminal run `php admin/cli/adhoc_task.php "--execute=\quiz_statistics\task\recalculate"`
      5. Wait until you see the message for your quiz, "'...re-calculating statistics for xxx attempts".
      6. Reload the Question bank page.
        1. The page should load immediately, and show an empty or N/A result in the statistics columns.
      7. Wait for the scheduled task to complete.
      8. Reload the Question bank page.
        1. The page should load immediately, and show 0.00% in the "Facility index" column. If you've used a real quiz with actual answers in the attempts, you may see some real statistics here instead.
      Show
      I think the most important thing to test is that with this change, computing stats for the question bank still works. So, copied from part of the MDL-78580 tests Real-world tests If you have a large enough quiz enough attempts that the statistics calculation takes a significant length of time, you can do a more realistic test. If you don't have one you can set one up with the following steps, which resulted in a 30 second calculation process on my machine, although it takes a long time to generate the data. Set up Go to Site Administration > Development > Make test course. Create an L-size course (this takes a while). Restore the attached 10-question-quiz.mbz to the course and make a note of the cmid. Place the attached test_big_stats_calc.php in the root of your moodle codebase, and run `php test_big_stats_calc.php --quizcmid= cmid --attempts=10000`. This will generate 10000 attempts at the quiz. This takes a long time. You may want to create a snapshot of your database at this point so you can roll back to re-run the tests. You can also re-attempt the quiz as any student before each test scenario to trigger the recalculation. Test 1 - Question bank If needed, reset the database or re-attempt the quiz. Navigate to the quiz Go to the "Question bank" tab. The page should load immediately, and show an empty or N/A result in the "Needs checking?", "Facility index" and "Discriminative efficiency" statistics columns. In the terminal run `php admin/cli/adhoc_task.php "--execute=\quiz_statistics\task\recalculate"` Wait until you see the message for your quiz, "'...re-calculating statistics for xxx attempts". Reload the Question bank page. The page should load immediately, and show an empty or N/A result in the statistics columns. Wait for the scheduled task to complete. Reload the Question bank page. The page should load immediately, and show 0.00% in the "Facility index" column. If you've used a real quiz with actual answers in the attempts, you may see some real statistics here instead.

      Steps to reproduce:

      1. Ensure you have at least two admins for your Moodle site, and that you are not the main admin.
      2. Edit the main admin account, and set it to auth: nologin.
      3. Log in as a student, and attempt any quiz.
      4. Submit your quiz attempt.

      Expected result: it works

      Actual result:

      Exception encountered in event observer '\quiz_statistics\event\observer\attempt_submitted::process': Suspended account

      line 223 of /lib/classes/task/manager.php: call to core_user::require_active_user()
      line 45 of /mod/quiz/report/statistics/classes/event/observer/attempt_submitted.php: call to core\task\manager::queue_adhoc_task()
      line ? of unknownfile: call to quiz_statistics\event\observer\attempt_submitted::process()
      line 155 of /lib/classes/event/manager.php: call to call_user_func()
      line 75 of /lib/classes/event/manager.php: call to core\event\manager::process_buffers()
      line 795 of /lib/classes/event/base.php: call to core\event\manager::dispatch()
      line 1907 of /mod/quiz/classes/quiz_attempt.php: call to core\event\base->trigger()
      line 1777 of /mod/quiz/classes/quiz_attempt.php: call to mod_quiz\quiz_attempt->fire_state_transition_event()
      line 2088 of /mod/quiz/classes/quiz_attempt.php: call to mod_quiz\quiz_attempt->process_finish()
      line 96 of /mod/quiz/processattempt.php: call to mod_quiz\quiz_attempt->process_attempt()

      Analysis: \quiz_statistics\task\recalculate is doing $task->set_userid(get_admin()->id);, but this is wrong. If you want the task to run as admin, you just just leave userid set to null.

      (As far as I can see, in core, $task->set_userid is only ever used to set userid to a real user who the task is running for, e.g. the user doing a backup.)

      Patch coming up.

        1. test_big_stats_calc_41.php
          4 kB
        2. MDL-79747 - master - step 8 .png
          MDL-79747 - master - step 8 .png
          119 kB
        3. MDL-79747 - master -  empty or na.png
          MDL-79747 - master - empty or na.png
          130 kB
        4. MDL-79747 - master - Adhoc task.png
          MDL-79747 - master - Adhoc task.png
          111 kB
        5. MDL-79747 - 403 - step 8.png
          MDL-79747 - 403 - step 8.png
          138 kB
        6. MDL-79747 - 403 -  empty or na.png
          MDL-79747 - 403 - empty or na.png
          119 kB
        7. MDL-79747 - 403 - Adhoc task.png
          MDL-79747 - 403 - Adhoc task.png
          118 kB
        8. MDL-79747 - 402 - step 8.png
          MDL-79747 - 402 - step 8.png
          167 kB
        9. MDL-79747 - 402 -  empty or na.png
          MDL-79747 - 402 - empty or na.png
          165 kB
        10. MDL-79747 - 402 - Adhoc task.png
          MDL-79747 - 402 - Adhoc task.png
          109 kB
        11. MDL-79747 - 401 - step 8.png
          MDL-79747 - 401 - step 8.png
          178 kB
        12. MDL-79747 - 401 -  empty or na.png
          MDL-79747 - 401 - empty or na.png
          160 kB
        13. MDL-79747 - 401 - Adhoc task.png
          MDL-79747 - 401 - Adhoc task.png
          43 kB
        14. 10-question-quiz.mbz
          6 kB

            timhunt Tim Hunt
            timhunt Tim Hunt
            Paul Holden Paul Holden
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Carlos Escobedo Carlos Escobedo
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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