Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Mar 26, 2020
2 parents 6453cd4 + d83f95e commit 29ac803
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
32 changes: 27 additions & 5 deletions classes/RssFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Exception;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Collection;
use Laminas\Feed\Reader\Entry\EntryInterface;
use Laminas\Feed\Reader\Entry\Rss;
use Laminas\Feed\Reader\Feed\FeedInterface;
use Laminas\Feed\Reader\Reader;
use October\Rain\Support\Traits\Singleton;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -92,7 +94,8 @@ private function fetchSource(Source $source): void
'category' => implode(', ', $item->getCategories()->getValues()),
'comments' => $item->getCommentLink(),
'pub_date' => $dateCreated !== null ? $item->getDateCreated()->format('Y-m-d H:i:s') : null,
'is_published' => (bool) $source->getAttribute('publish_new_items')
'is_published' => (bool) $source->getAttribute('publish_new_items'),
'author' => $this->getAuthor($channel, $item),
];

$enclosure = $item->getEnclosure();
Expand All @@ -103,10 +106,6 @@ private function fetchSource(Source $source): void
$attributes['enclosure_type'] = $enclosure->type ?? null;
}

if ($item->getAuthors() !== null && is_array($item->getAuthors())) {
$attributes['author'] = implode(', ', $item->getAuthors());
}

try {
Item::query()->updateOrCreate(
[
Expand All @@ -128,6 +127,29 @@ private function fetchSource(Source $source): void
$source->save();
}

/**
* @param FeedInterface $feed
* @param EntryInterface $entry
* @return string|null
*/
private function getAuthor(FeedInterface $feed, EntryInterface $entry): ?string
{
$result = null;
$author = $entry->getAuthor();

if ($author === null || empty($author)) {
$author = $feed->getAuthor();
}

if (is_array($author)) {
$result = $author['name'] ?? null;
} elseif (is_string($author)) {
$result = $author;
}

return $result;
}

/**
* @param int|null $sourceId
* @return Collection
Expand Down
1 change: 1 addition & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
- 20200206_0006_remove_unique_constraint_from_items.php
2.0.0:
- "Replace Zend Framework with Laminas and added events"
2.1.0: "Fix Author parsing for Atom/RSS feeds"

0 comments on commit 29ac803

Please sign in to comment.