Skip to content

Commit

Permalink
null safe fix (#211)
Browse files Browse the repository at this point in the history
* null safe fix

* Update package.yml
  • Loading branch information
skerbis authored Dec 11, 2024
1 parent 0c8fe81 commit ea0bb4e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
67 changes: 52 additions & 15 deletions lib/stream/rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: feeds
version: '4.2.1'
version: '4.2.2'
author: Friends Of REDAXO
supportpage: https://github.com/FriendsOfREDAXO/feeds

Expand Down

0 comments on commit ea0bb4e

Please sign in to comment.