From c63dd3aaa1a9b27d9567e3a36453b058fd7e30fc Mon Sep 17 00:00:00 2001 From: Peter Burnett Date: Mon, 24 Jan 2022 15:16:44 +1000 Subject: [PATCH] Issue #31: Handle missing files better The slide cache will still emit warnings for missing files that are configured to be there, but the carousel will no longer emit constant warnings for bad slide definitions. --- block_carousel.php | 7 ++++++- classes/cache/slide_cache.php | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/block_carousel.php b/block_carousel.php index 6069788..5e1001d 100644 --- a/block_carousel.php +++ b/block_carousel.php @@ -126,7 +126,7 @@ public function get_content() { if ($slides > 1) { $firstslide = reset($data); $height = $firstslide['heightres']; - if ($height === 0) { + if ($height === 0 || $height === null) { $ratio = 1; } else { $ratio = ($firstslide['widthres'] / $firstslide['heightres']); @@ -143,6 +143,11 @@ public function get_content() { continue; } + // Filter any files that are not present or broken. + if ($data->heightres === null && $data->widthres === null && $data->contenttype === 'image') { + continue; + } + // Check release timing. if ((!empty($data->timedstart) && time() < $data->timedstart) || (!empty($data->timedend) && time() > $data->timedend)) { diff --git a/classes/cache/slide_cache.php b/classes/cache/slide_cache.php index 796bbb7..a3d51cb 100644 --- a/classes/cache/slide_cache.php +++ b/classes/cache/slide_cache.php @@ -141,8 +141,13 @@ public function load_for_cache($key) { $data['widthres'] = 0; } else if ($record->contenttype === 'image') { $imageinfo = $selectedfile->get_imageinfo(); - $data['heightres'] = $imageinfo['height']; - $data['widthres'] = $imageinfo['width']; + if (!$imageinfo) { + $data['heightres'] = null; + $data['widthres'] = null; + } else { + $data['heightres'] = $imageinfo['height']; + $data['widthres'] = $imageinfo['width']; + } } else { // Use FFMpeg to get resolution. $path = $selectedfile->copy_content_to_temp();