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

import_backup_file_silently doesn't load admin to $USER

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.3
    • Fix Version/s: 1.9.5
    • Component/s: Backup
    • Labels:
      None
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      I was creating a tool to restore backups to an specific discipline. As it's is an standalone php class, i was importing the following files:

      require('config.php');
      require($CFG->dirroot.'/backup/lib.php');
      require($CFG->dirroot.'/backup/restorelib.php');

      and i was using the following function:

      import_backup_file_silently($pathtofile, $destinationcourse, true);

      With this environment conditions, i have and empty $USER object with just an id property without value, so get_admin is never executed.

      Because of that, i get an error notice printed to console regarding problems with roles_capabilitites:

      <div class="notifytiny" style="text-align:center">Either userid or groupid must be provided<ul style="text-align:left"><li>line 2809 of lib/accesslib.php: call to debugging()</li><li>line 8188 of backup/restorelib.php: call to role_assign()</li><li>line 742 of backup/lib.php: call to restore_execute()</li><li>line 31 of sandbox.php: call to import_backup_file_silently()</li><li>line 20 of sandbox.php: call to Sandbox->restore_course()</li><li>line 7 of sandbox.php: call to Sandbox->__construct()</li></ul></div>

      So i suggest the attached patch to solve this issue.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/May/09