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

import_backup_file_silently doesn't load admin to $USER

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 1.9.5
    • 1.9.3
    • Backup
    • None
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE
    • Easy

      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.

            stronk7 Eloy Lafuente (stronk7)
            brodock Gabriel Mazetto
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved:

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