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

Backup fails with deleted users in course

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 2.4
    • 2.4
    • Backup
    • MOODLE_24_STABLE
    • MOODLE_24_STABLE
    • MDL-34872-master
    • Hide

      Test pre-requisites

      • A student enrolled in a course
      • A forum activity where the student can post

      Test steps

      1. As the student, post to the forum
      2. As the admin, delete the student from the website
      3. Backup the course
      4. Make sure the backup is correct and no exceptions are raised during the process
      Show
      Test pre-requisites A student enrolled in a course A forum activity where the student can post Test steps As the student, post to the forum As the admin, delete the student from the website Backup the course Make sure the backup is correct and no exceptions are raised during the process

      When running the CLI to create backups, an exception was raised 'invaliduser'.

      After digging a bit, I think this is a regression caused by MDL-33061.

      This seem to fix the issue:

      diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php
      index 24d7da9..78c0a45 100644
      --- a/backup/moodle2/backup_stepslib.php
      +++ b/backup/moodle2/backup_stepslib.php
      @@ -1835,7 +1835,7 @@ class backup_annotate_all_user_files extends backup_execution_step {
                   'backupid' => $this->get_backupid(), 'itemname' => 'userfinal'));
               foreach ($rs as $record) {
                   $userid = $record->itemid;
      -            $userctx = context_user::instance($userid);
      +            $userctx = context_user::instance($userid, IGNORE_MISSING);
                   if (!$userctx) {
                       continue; // User has not context, sure it's a deleted user, so cannot have files
                   }

      I did not test those replication steps, but they should work:

      1. Create a course and enrol users in them
      2. Delete one of those users
      3. Run `php admin/cli/automated_backups.php`

      Expected:

      • The course is backed up

      Actual:

      • An exception is raised, the course and the following are not backed up

            fred Frédéric Massart
            fred Frédéric Massart
            Aparup Banerjee Aparup Banerjee
            Dan Poltawski Dan Poltawski
            Jason Fowler Jason Fowler
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

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