Skip to content

Commit

Permalink
Issue #31: Handle missing files better
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Peterburnett committed Jan 24, 2022
1 parent f14204d commit c63dd3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion block_carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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)) {
Expand Down
9 changes: 7 additions & 2 deletions classes/cache/slide_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c63dd3a

Please sign in to comment.