Skip to content

Commit

Permalink
MDL-35290 files: File manager reports files which can't be read
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Aug 29, 2017
1 parent af12901 commit 67fa4b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions lang/en/error.php
Expand Up @@ -506,6 +506,7 @@
$string['storedfilecannotcreatefile'] = 'Can not create local file pool file, please verify permissions in dataroot and available disk space.';
$string['storedfilecannotcreatefiledirs'] = 'Can not create local file pool directories, please verify permissions in dataroot.';
$string['storedfilecannotread'] = 'Cannot read file. Either the file does not exist or there is a permission problem.';
$string['storedfilecannotreadfile'] = 'Cannot read file \'{$a}\'. Either the file does not exist or there is a permission problem.';
$string['storedfilenotcreated'] = 'Can not create file "{$a->contextid}/{$a->component}/{$a->filearea}/{$a->itemid}{$a->filepath}{$a->filename}"';
$string['storedfileproblem'] = 'Unknown exception related to local files ({$a})';
$string['tagdisabled'] = 'Tags are disabled!';
Expand Down
21 changes: 16 additions & 5 deletions lib/filelib.php
Expand Up @@ -707,11 +707,22 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
$item->url = $itemurl->out();
$item->icon = $OUTPUT->image_url(file_file_icon($file, 24))->out(false);
$item->thumbnail = $OUTPUT->image_url(file_file_icon($file, 90))->out(false);
if ($imageinfo = $file->get_imageinfo()) {
$item->realthumbnail = $itemurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
$item->realicon = $itemurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
$item->image_width = $imageinfo['width'];
$item->image_height = $imageinfo['height'];

// The call to $file->get_imageinfo() fails with an exception if the file can't be read on the file system.
// We still want to add such files to the list, so the owner can view and delete them if needed. So, we only call
// get_imageinfo() on files that can be read, and we also spoof the file status based on whether it was found.
// We'll use the same status types used by stored_file->get_status(), where 0 = OK. 1 = problem, as these will be
// used by the widget to display a warning about the problem files.
// The value of stored_file->get_status(), and the file record are unaffected by this. It's only superficially set.
$item->status = $fs->get_file_system()->is_file_readable_remotely_by_storedfile($file) ? 0 : 1;
if ($item->status == 0) {
if ($imageinfo = $file->get_imageinfo()) {
$item->realthumbnail = $itemurl->out(false, array('preview' => 'thumb',
'oid' => $file->get_timemodified()));
$item->realicon = $itemurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
$item->image_width = $imageinfo['width'];
$item->image_height = $imageinfo['height'];
}
}
}
$list[] = $item;
Expand Down
21 changes: 21 additions & 0 deletions repository/filepicker.js
Expand Up @@ -427,6 +427,27 @@ YUI.add('moodle-core_filepicker', function(Y) {
}
}

// Notify the user if any of the files has a problem status.
var problemFiles = [];
fileslist.forEach(function(file) {
if (!file_is_folder(file) && file.hasOwnProperty('status') && file.status != 0) {
problemFiles.push(file);
}
});
if (problemFiles.length > 0) {
require(["core/notification", "core/str"], function(Notification, Str) {
problemFiles.forEach(function(problemFile) {
Str.get_string('storedfilecannotreadfile', 'error', problemFile.fullname).then(function(string) {
Notification.addNotification({
message: string,
type: "error"
});
return;
}).catch(Notification.exception);
});
});
}

// If table view, need some additional properties
// before passing fileslist to the YUI tableview
if (options.viewmode == 3) {
Expand Down

0 comments on commit 67fa4b5

Please sign in to comment.