From c26dce0e793059fc4cac73da8d4cd67abff42a04 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sun, 27 Aug 2017 16:19:08 +0800 Subject: [PATCH] Fixed exception being thrown when deleted image is selected --- element/image/classes/element.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/element/image/classes/element.php b/element/image/classes/element.php index 7458beb..6025b83 100644 --- a/element/image/classes/element.php +++ b/element/image/classes/element.php @@ -151,14 +151,15 @@ class element extends \mod_customcert\element { if (!empty($data->fileid)) { // Array of data we will be storing in the database. $fs = get_file_storage(); - $file = $fs->get_file_by_id($data->fileid); - $arrtostore += [ - 'contextid' => $file->get_contextid(), - 'filearea' => $file->get_filearea(), - 'itemid' => $file->get_itemid(), - 'filepath' => $file->get_filepath(), - 'filename' => $file->get_filename(), - ]; + if ($file = $fs->get_file_by_id($data->fileid)) { + $arrtostore += [ + 'contextid' => $file->get_contextid(), + 'filearea' => $file->get_filearea(), + 'itemid' => $file->get_itemid(), + 'filepath' => $file->get_filepath(), + 'filename' => $file->get_filename(), + ]; + } } return json_encode($arrtostore);