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

Restoring quizzes with random questions while cleanup task runs causes issues

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
    • MOODLE_311_STABLE
    • Hide
      1. Enable asynchronous backups:
        php admin/cli/cfg.php --name='enableasyncbackup' --set=1
      2. Hack your codebase here (for 3.11) and put the following two lines:

            mtrace('Restoring question instance');
            sleep(10);
        

      3. Restore the course from the attached file (backup-moodle2-course-3-test_course_for_mdl-66273-20220829-0446-nu-nf.mbz).
      4. Open two terminals
      5. On the first terminal, run the command to complete course restore:
        php admin/cli/adhoc_task.php --execute
      6. Once Restoring question instance is appeared in the CLI output, run the scheduled task on another terminal:
        php admin/cli/scheduled_task.php --execute='\qtype_random\task\remove_unused_questions'
      7. Confirm, that it prints Detected running async restore. Aborting the task..
      8. Once restore adhoc task is completed access Quiz with random questions in the restored course.
      9. Edit the quiz.
      10. Confirm, that 3 random questions are present.
      11. Run the remove_unused_questions scheduled task again.
      12. Confirm that it completes and is not aborted.
      Show
      Enable asynchronous backups: php admin/cli/cfg.php --name='enableasyncbackup' --set=1 Hack your codebase here (for 3.11) and put the following two lines: mtrace( 'Restoring question instance' ); sleep( 10 ); Restore the course from the attached file ( backup-moodle2-course-3-test_course_for_mdl-66273-20220829-0446-nu-nf.mbz ). Open two terminals On the first terminal, run the command to complete course restore: php admin/cli/adhoc_task.php --execute Once Restoring question instance is appeared in the CLI output, run the scheduled task on another terminal: php admin/cli/scheduled_task.php --execute='\qtype_random\task\remove_unused_questions' Confirm , that it prints Detected running async restore. Aborting the task. . Once restore adhoc task is completed access Quiz with random questions in the restored course. Edit the quiz. Confirm , that 3 random questions are present. Run the remove_unused_questions scheduled task again. Confirm that it completes and is not aborted.

      Note, this is only an issue with Moodle 3.x. It is no longer relevant in 4.x:

      Large course with many quizzes using random questions as the question type

      I back up the course with the quizzes and if I restore course and theĀ \qtype_random\task\remove_unused_questions scheduled task happens to run at the same time that I am restoring, I end up with a course of quizzes that have no questions or have missing questions that say "This question no longer seems to exist".

      I was able to replicate this by backing up my course and then running the cron while it restored. It was deleted unused random questions, while my restore was running. Once my restore was complete, none of my quizzes had any questions in them.

      I can work around this by scheduling that task to run only once a night, but the default for that task is set to run on the 19th minute of every hour, so I could see this causing issues for anyone who happens to leave this on default settings and restores a course during that minute.

      My guess is that the random question records are being created before the restore creates the quiz and associates the records so the cron sees them as unused before the restore can finish.

            mikhailgolenkov Misha Golenkov
            heather.williams Heather Williams
            Dmitrii Metelkin Dmitrii Metelkin
            Jun Pataleta Jun Pataleta
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            23 Vote for this issue
            Watchers:
            29 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 30 minutes
                2h 30m

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