koel/app/Console/Commands/SyncPodcastsCommand.php

43 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;
2024-05-19 05:49:42 +00:00
use App\Services\PodcastService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Throwable;
class SyncPodcastsCommand extends Command
{
protected $signature = 'koel:podcasts:sync';
2024-06-27 09:33:10 +00:00
protected $description = 'Synchronize podcasts.';
2024-05-19 05:49:42 +00:00
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;
}
}