mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
fix: gracefully handle missing images
This commit is contained in:
parent
6adb11b5bf
commit
cb56ac11d9
@ -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,10 +143,14 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
if (singleton($type) instanceof Image) {
|
if (singleton($type) instanceof Image) {
|
||||||
$image = $this->owner->getComponent($field);
|
$image = $this->owner->getComponent($field);
|
||||||
|
|
||||||
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
try {
|
||||||
$cachedImages[$image->ID] = true;
|
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
||||||
|
$cachedImages[$image->ID] = true;
|
||||||
|
|
||||||
$list->push($image);
|
$list->push($image);
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,18 +160,22 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
$images = $this->owner->getComponents($field);
|
$images = $this->owner->getComponents($field);
|
||||||
|
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
try {
|
||||||
$cachedImages[$image->ID] = true;
|
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
||||||
|
$cachedImages[$image->ID] = true;
|
||||||
|
|
||||||
$list->push($image);
|
$list->push($image);
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->owner->manyMany() as $field => $type) {
|
foreach ($this->owner->manyMany() as $field => $type) {
|
||||||
$image = false;
|
$image = false;
|
||||||
|
|
||||||
if (is_array($type) && isset($type['through'])) {
|
if (is_array($type) && isset($type['through'])) {
|
||||||
if (singleton($type['through']) instanceof Image) {
|
if (singleton($type['through']) instanceof Image) {
|
||||||
$image = true;
|
$image = true;
|
||||||
@ -175,7 +184,7 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
if (strpos($type, '.') !== false) {
|
if (strpos($type, '.') !== false) {
|
||||||
$type = explode('.', $type)[0];
|
$type = explode('.', $type)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (singleton($type) instanceof Image) {
|
if (singleton($type) instanceof Image) {
|
||||||
$image = true;
|
$image = true;
|
||||||
}
|
}
|
||||||
@ -185,10 +194,14 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
$images = $this->owner->$field();
|
$images = $this->owner->$field();
|
||||||
|
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
try {
|
||||||
$cachedImages[$image->ID] = true;
|
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
||||||
|
$cachedImages[$image->ID] = true;
|
||||||
|
|
||||||
$list->push($image);
|
$list->push($image);
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user