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.