diff --git a/lang/en/error.php b/lang/en/error.php index 27c5d8a21ad..2c1e61e3ab4 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -506,6 +506,7 @@ $string['statsnodata'] = 'There is no available data for that combination of cou $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!'; diff --git a/lib/filebrowser/file_info_stored.php b/lib/filebrowser/file_info_stored.php index 8c1069b65e0..5dd21509f2f 100644 --- a/lib/filebrowser/file_info_stored.php +++ b/lib/filebrowser/file_info_stored.php @@ -234,7 +234,11 @@ class file_info_stored extends file_info { * @return array|false */ public function get_imageinfo() { - return $this->lf->get_imageinfo(); + $fs = get_file_storage(); + if ($fs->content_exists($this->lf->get_contenthash())) { + return $this->lf->get_imageinfo(); + } + return false; } /** diff --git a/lib/filelib.php b/lib/filelib.php index 1988d4744ef..2b269bb0d05 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -421,7 +421,10 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare $original->filename = $file->get_filename(); $original->filepath = $file->get_filepath(); $newsourcefield->original = file_storage::pack_reference($original); - $draftfile->set_source(serialize($newsourcefield)); + // Check we can read the file before we update it. + if ($fs->content_exists($file->get_contenthash())) { + $draftfile->set_source(serialize($newsourcefield)); + } // End of file manager hack } } @@ -707,11 +710,22 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') { $item->url = $itemurl->out(); $item->icon = $OUTPUT->pix_url(file_file_icon($file, 24))->out(false); $item->thumbnail = $OUTPUT->pix_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->content_exists($file->get_contenthash()) ? 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; diff --git a/repository/filepicker.js b/repository/filepicker.js index 386a6abcd17..31067b7c749 100644 --- a/repository/filepicker.js +++ b/repository/filepicker.js @@ -426,6 +426,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) {