in lib.php [918:971]
public function get_file($reference, $filename = '') {
global $USER;
$caller = '\repository_office365::get_file';
$reference = $this->unpack_reference($reference);
if ($reference['source'] === 'onedrive') {
if ($this->unifiedconfigured === true) {
$sourceclient = $this->get_unified_apiclient();
} else {
$sourceclient = $this->get_onedrive_apiclient();
}
if (empty($sourceclient)) {
utils::debug('Could not construct onedrive api.', $caller);
throw new \moodle_exception('errorwhiledownload', 'repository_office365');
}
$o365userid = utils::get_o365_userid($USER->id);
$file = $sourceclient->get_file_by_id($reference['id'], $o365userid);
} else if ($reference['source'] === 'onedrivegroup') {
if ($this->unifiedconfigured === true) {
$sourceclient = $this->get_unified_apiclient();
} else {
utils::debug('Tried to access a onedrive group file while the graph api is disabled.', $caller);
throw new \moodle_exception('errorwhiledownload', 'repository_office365');
}
$file = $sourceclient->get_group_file_by_id($reference['groupid'], $reference['id']);
} else if ($reference['source'] === 'trendingaround') {
if ($this->unifiedconfigured === true) {
$sourceclient = $this->get_unified_apiclient();
}
if (empty($sourceclient)) {
utils::debug('Could not construct unified api.', $caller);
throw new \moodle_exception('errorwhiledownload', 'repository_office365');
}
$file = $sourceclient->get_file_by_url($reference['url']);
}
if (!empty($file)) {
$path = $this->prepare_file($filename);
if (!empty($path)) {
$result = file_put_contents($path, $file);
}
}
if (empty($result)) {
$errmsg = get_string('errorwhiledownload', 'repository_office365');
$debugdata = [
'reference' => $reference,
'filename' => $filename,
];
utils::debug($errmsg, $caller, $debugdata);
throw new \moodle_exception('errorwhiledownload', 'repository_office365');
}
return ['path' => $path, 'url' => $reference];
}