fedi-feed-router/app/Console/Commands/PublishToLemmyCommand.php

31 lines
744 B
PHP

<?php
namespace App\Console\Commands;
use App\Models\Article;
use App\Modules\Lemmy\Services\LemmyPublisher;
use App\Services\Article\ArticleFetcher;
use Exception;
use Illuminate\Console\Command;
class PublishToLemmyCommand extends Command
{
protected $signature = 'article:publish-to-lemmy';
protected $description = 'Publish an article to Lemmy';
public function handle(): int
{
$article = Article::all()->firstOrFail();
$this->info('Publishing article: ' . $article->url);
try {
LemmyPublisher::fromConfig()->publish($article, ArticleFetcher::fetchArticle($article));
} catch (Exception) {
return self::FAILURE;
}
return self::SUCCESS;
}
}