MDL-58823 repository: Fix redirections to external files

We cannot use redirect() because is not compatible with
webservice/pluginfile.php
This script is defined as an AJAX_SCRIPT so redirections are not
allowed by redirect() function.
This commit is contained in:
Juan Leyva 2017-05-05 10:04:51 +02:00
parent 932bc91cb4
commit fcdd7730bd
3 changed files with 6 additions and 3 deletions

View File

@ -845,7 +845,8 @@ function repository_filesystem_pluginfile($course, $cm, $context, $filearea, $ar
// Find stored or generated thumbnail.
if (!($file = $repo->get_thumbnail($filepath, $filearea))) {
// Generation failed, redirect to default icon for file extension.
redirect($OUTPUT->image_url(file_extension_icon($file, 90)));
// Do not use redirect() here because is not compatible with webservice/pluginfile.php.
header('Location: ' . $OUTPUT->image_url(file_extension_icon($file, 90)));
}
// The thumbnails should not be changing much, but maybe the default lifetime is too long.
$lifetime = $CFG->filelifetime;

View File

@ -630,7 +630,8 @@ class repository_googledocs extends repository {
}
send_file($downloaded['path'], $filename, $lifetime, $filter, false, $forcedownload, '', false, $options);
} else if ($source->link) {
redirect($source->link);
// Do not use redirect() here because is not compatible with webservice/pluginfile.php.
header('Location: ' . $source->link);
} else {
$details = 'File is missing source link';
throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);

View File

@ -577,7 +577,8 @@ class repository_onedrive extends repository {
$filename = $storedfile->get_filename();
send_file($downloaded['path'], $filename, $lifetime, $filter, false, $forcedownload, '', false, $options);
} else if ($source->link) {
redirect($source->link);
// Do not use redirect() here because is not compatible with webservice/pluginfile.php.
header('Location: ' . $source->link);
} else {
$details = 'File is missing source link';
throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);