fix: gracefully handle missing images

This commit is contained in:
Will Rossiter 2022-07-05 13:27:32 +12:00 committed by GitHub
parent 6adb11b5bf
commit cb56ac11d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\Tab; use SilverStripe\Forms\Tab;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use Throwable;
class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
{ {
@ -142,11 +143,15 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
if (singleton($type) instanceof Image) { if (singleton($type) instanceof Image) {
$image = $this->owner->getComponent($field); $image = $this->owner->getComponent($field);
try {
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) { if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
$cachedImages[$image->ID] = true; $cachedImages[$image->ID] = true;
$list->push($image); $list->push($image);
} }
} catch (Throwable $e) {
//
}
} }
} }
@ -155,11 +160,15 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
$images = $this->owner->getComponents($field); $images = $this->owner->getComponents($field);
foreach ($images as $image) { foreach ($images as $image) {
try {
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) { if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
$cachedImages[$image->ID] = true; $cachedImages[$image->ID] = true;
$list->push($image); $list->push($image);
} }
} catch (Throwable $e) {
//
}
} }
} }
} }
@ -185,11 +194,15 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
$images = $this->owner->$field(); $images = $this->owner->$field();
foreach ($images as $image) { foreach ($images as $image) {
try {
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) { if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
$cachedImages[$image->ID] = true; $cachedImages[$image->ID] = true;
$list->push($image); $list->push($image);
} }
} catch (Throwable $e) {
//
}
} }
} }
} }