Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Jul 6, 2021
2 parents 05739db + 9f55ea5 commit 6cb2a28
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 458 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ 8.0, 7.4, 7.3 ]
php: [ 8.0, 7.4 ]
stability: [ prefer-lowest, prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# 3.0.0

- Drop support for PHP 7.4 (minimum required PHP version 7.4).

# 2.2.1

- Fix error when performing a migration rollback.

# 2.2.0

- Update plugin dependencies (minimum required PHP version 7.3)
- Update plugin dependencies (minimum required PHP version 7.3).

# 2.1.0

Expand Down
23 changes: 1 addition & 22 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class Plugin extends PluginBase
{
/**
* {@inheritDoc}
*/
public function pluginDetails(): array
{
return [
Expand All @@ -23,17 +20,11 @@ public function pluginDetails(): array
];
}

/**
* {@inheritDoc}
*/
public function register(): void
{
$this->registerConsoleCommand('Vdlp.RssFetcher', Commands\FetchRssCommand::class);
}

/**
* {@inheritDoc}
*/
public function registerComponents(): array
{
return [
Expand All @@ -43,22 +34,16 @@ public function registerComponents(): array
];
}

/**
* {@inheritDoc}
*/
public function registerReportWidgets(): array
{
return [
ReportWidgets\Headlines::class => [
'label' => 'RSS Headlines',
'code' => 'headlines',
]
],
];
}

/**
* {@inheritDoc}
*/
public function registerPermissions(): array
{
return [
Expand All @@ -81,9 +66,6 @@ public function registerPermissions(): array
];
}

/**
* {@inheritDoc}
*/
public function registerNavigation(): array
{
/** @var BackendHelper $backendHelper */
Expand Down Expand Up @@ -120,9 +102,6 @@ public function registerNavigation(): array
];
}

/**
* {@inheritDoc}
*/
public function registerFormWidgets(): array
{
return [
Expand Down
54 changes: 12 additions & 42 deletions classes/RssFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace Vdlp\RssFetcher\Classes;

use Carbon\Carbon;
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\Facades\Event;
use October\Rain\Support\Traits\Singleton;
use Psr\Log\LoggerInterface;
use stdClass;
Expand All @@ -23,34 +22,18 @@ final class RssFetcher
{
use Singleton;

/**
* @var LoggerInterface
*/
private $log;
private LoggerInterface $log;

/**
* @var Dispatcher
*/
private $dispatcher;

/**
* {@inheritDoc}
*/
protected function init(): void
{
$this->log = resolve(LoggerInterface::class);
$this->dispatcher = resolve(Dispatcher::class);
}

/**
* Run the fetching logic.
*
* @param int|null $sourceId
*/
public function fetch(int $sourceId = null): void
public function fetch(?int $sourceId = null): void
{
$sources = $this->getSourceCollection($sourceId);
$sources->each(function (Source $source) {

$sources->each(function (Source $source): void {
try {
$this->fetchSource($source);
} catch (Throwable $e) {
Expand All @@ -59,10 +42,6 @@ public function fetch(int $sourceId = null): void
});
}

/**
* @param Source $source
* @throws Exception
*/
private function fetchSource(Source $source): void
{
$channel = Reader::import($source->getAttribute('source_url'));
Expand All @@ -77,13 +56,13 @@ private function fetchSource(Source $source): void
$dateCreated = $item->getDateCreated();

$title = $item->getTitle();
$this->dispatcher->fire('vdlp.rssfetcher.item.processTitle', [&$title]);
Event::dispatch('vdlp.rssfetcher.item.processTitle', [&$title]);

$content = $item->getContent();
$this->dispatcher->fire('vdlp.rssfetcher.item.processContent', [&$content]);
Event::dispatch('vdlp.rssfetcher.item.processContent', [&$content]);

$link = $item->getLink();
$this->dispatcher->fire('vdlp.rssfetcher.item.processLink', [&$link]);
Event::dispatch('vdlp.rssfetcher.item.processLink', [&$link]);

$attributes = [
'item_id' => $item->getId(),
Expand All @@ -93,7 +72,7 @@ private function fetchSource(Source $source): void
'description' => $content,
'category' => implode(', ', $item->getCategories()->getValues()),
'comments' => $item->getCommentLink(),
'pub_date' => $dateCreated !== null ? $item->getDateCreated()->format('Y-m-d H:i:s') : null,
'pub_date' => $dateCreated !== null ? $dateCreated->format('Y-m-d H:i:s') : null,
'is_published' => (bool) $source->getAttribute('publish_new_items'),
'author' => $this->getAuthor($channel, $item),
];
Expand Down Expand Up @@ -127,17 +106,12 @@ 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)) {
if ($author === null || count($author) === 0) {
$author = $feed->getAuthor();
}

Expand All @@ -150,11 +124,7 @@ private function getAuthor(FeedInterface $feed, EntryInterface $entry): ?string
return $result;
}

/**
* @param int|null $sourceId
* @return Collection
*/
private function getSourceCollection(int $sourceId = null): Collection
private function getSourceCollection(?int $sourceId = null): Collection
{
$sources = new Collection();

Expand All @@ -164,7 +134,7 @@ private function getSourceCollection(int $sourceId = null): Collection
->where('is_enabled', '=', true)
->first();

if ($source) {
if ($source !== null) {
$sources = new Collection([$source]);
}
} else {
Expand Down
30 changes: 9 additions & 21 deletions commands/FetchRssCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

/* @noinspection PhpMissingParentCallCommonInspection */

declare(strict_types=1);

namespace Vdlp\RssFetcher\Commands;
Expand All @@ -10,33 +8,23 @@
use Symfony\Component\Console\Input\InputArgument;
use Vdlp\RssFetcher\Classes\RssFetcher;

class FetchRssCommand extends Command
final class FetchRssCommand extends Command
{
/**
* {@inheritDoc}
*/
protected $name = 'vdlp:fetch-rss';

/**
* {@inheritDoc}
*/
protected $description = 'Fetches RSS data from various sources.';

/**
* Execute the console command.
*
* @return void
*/
public function __construct()
{
$this->name = 'vdlp:fetch-rss';
$this->description = 'Fetches RSS data from various sources.';

parent::__construct();
}

public function handle(): void
{
$sourceId = (int) $this->argument('source');

RssFetcher::instance()->fetch($sourceId > 0 ? $sourceId : null);
}

/**
* {@inheritDoc}
*/
protected function getArguments(): array
{
return [
Expand Down
27 changes: 3 additions & 24 deletions components/Items.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

/** @noinspection PhpMissingParentCallCommonInspection */

declare(strict_types=1);

namespace Vdlp\RssFetcher\Components;
Expand All @@ -11,16 +9,10 @@
use Throwable;
use Vdlp\RssFetcher\Models\Item;

class Items extends ComponentBase
final class Items extends ComponentBase
{
/**
* @var Collection
*/
public $items;
public ?Collection $items = null;

/**
* {@inheritDoc}
*/
public function componentDetails(): array
{
return [
Expand All @@ -29,9 +21,6 @@ public function componentDetails(): array
];
}

/**
* {@inheritDoc}
*/
public function defineProperties(): array
{
return [
Expand All @@ -48,26 +37,16 @@ public function defineProperties(): array
];
}

/**
* {@inheritDoc}
*/
public function onRun(): void
{
$sourceId = (int) $this->property('sourceId');

$this->items = self::loadItems(
(int) $this->property('maxItems', 10),
(int) $this->property('maxItems', '10'),
$sourceId > 0 ? $sourceId : null
);
}

/**
* Load Items
*
* @param int $maxItems
* @param int $sourceId
* @return array
*/
public static function loadItems(int $maxItems, int $sourceId = null): array
{
try {
Expand Down
Loading

0 comments on commit 6cb2a28

Please sign in to comment.