koel/app/Console/Commands/SyncPodcastsCommand.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2024-05-19 05:49:42 +00:00
<?php
namespace App\Console\Commands;
use App\Models\Podcast\Podcast;
use App\Services\PodcastService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Throwable;
class SyncPodcastsCommand extends Command
{
protected $signature = 'koel:podcasts:sync';
public function __construct(private readonly PodcastService $podcastService)
{
parent::__construct();
}
public function handle(): int
{
Podcast::query()->get()->each(function (Podcast $podcast): void {
try {
$this->info("Checking \"$podcast->title\" for new content…");
if (!$this->podcastService->isPodcastObsolete($podcast)) {
$this->warn('└── The podcast feed has not been updated recently, skipping.');
return;
}
$this->info('└── Synchronizing episodes…');
$this->podcastService->refreshPodcast($podcast);
} catch (Throwable $e) {
Log::error($e);
}
});
return self::SUCCESS;
}
}