From ea0bb4e145879eb47c3913854af6ad09e0534a8b Mon Sep 17 00:00:00 2001 From: Thomas Skerbis Date: Wed, 11 Dec 2024 16:13:18 +0100 Subject: [PATCH] null safe fix (#211) * null safe fix * Update package.yml --- lib/stream/rss.php | 67 +++++++++++++++++++++++++++++++++++----------- package.yml | 2 +- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/lib/stream/rss.php b/lib/stream/rss.php index 372f894..4fd4aaa 100644 --- a/lib/stream/rss.php +++ b/lib/stream/rss.php @@ -40,24 +40,61 @@ public function fetch() echo rex_view::error($e->getMessage()); return; } + /** @var Item $rssItem */ - foreach ($result->getFeed() as $rssItem) { - $item = new rex_feeds_item($this->streamId, $rssItem->getPublicId()); - $item->setTitle($rssItem->getTitle()); - $item->setContentRaw($rssItem->getContent()); - $item->setContent(strip_tags($rssItem->getContent())); - $item->setUrl($rssItem->getLink()); - if($rssItem->getLastModified()) - { - $item->setDate($rssItem->getLastModified()); - } - $item->setAuthor($rssItem->getAuthor()->getName()); - if ($rssItem->getMedias() && isset($rssItem->getMedias()[0])) { - $item->setMedia($rssItem->getMedias()[0]->getUrl()); + foreach ($result->getFeed() as $rssItem) { + try { + // Sichere Extraktion der PublicId + $publicId = $rssItem->getPublicId(); + if (empty($publicId)) { + // Generiere eine eindeutige ID wenn keine vorhanden + $publicId = uniqid('feed_', true); + } + + $item = new rex_feeds_item($this->streamId, $publicId); + + // Titel mit Fallback + $title = $rssItem->getTitle(); + $item->setTitle($title ?: ''); + + // Content mit Fallback + $content = $rssItem->getContent(); + $item->setContentRaw($content ?: ''); + $item->setContent($content ? strip_tags($content) : ''); + + // URL/Link mit Fallback + $link = $rssItem->getLink(); + $item->setUrl($link ?: ''); + + // Datum mit Null-Check + $lastModified = $rssItem->getLastModified(); + if ($lastModified) { + $item->setDate($lastModified); + } + + // Author mit Null-Check + $author = $rssItem->getAuthor(); + $authorName = ($author && method_exists($author, 'getName')) ? $author->getName() : ''; + $item->setAuthor($authorName); + + // Media mit mehrfacher Null-Check + $medias = $rssItem->getMedias(); + if ($medias && !empty($medias) && isset($medias[0])) { + $mediaUrl = $medias[0]->getUrl(); + if ($mediaUrl) { + $item->setMedia($mediaUrl); + } + } + + $this->updateCount($item); + $item->save(); + } catch (Exception $e) { + // Logge Fehler für einzelne Items, aber fahre mit dem nächsten fort + rex_logger::logException($e); + continue; } - $this->updateCount($item); - $item->save(); } + self::registerExtensionPoint($this->streamId); } } diff --git a/package.yml b/package.yml index 9016c12..6e2806f 100644 --- a/package.yml +++ b/package.yml @@ -1,5 +1,5 @@ package: feeds -version: '4.2.1' +version: '4.2.2' author: Friends Of REDAXO supportpage: https://github.com/FriendsOfREDAXO/feeds