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

32 lines
744 B
PHP
Raw Normal View History

2025-06-29 20:16:25 +02:00
<?php
namespace App\Console\Commands;
use App\Models\Article;
2025-06-29 21:20:45 +02:00
use App\Modules\Lemmy\Services\LemmyPublisher;
use App\Services\Article\ArticleFetcher;
use Exception;
2025-06-29 20:16:25 +02:00
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();
2025-06-29 21:20:45 +02:00
$this->info('Publishing article: ' . $article->url);
try {
LemmyPublisher::fromConfig()->publish($article, ArticleFetcher::fetchArticle($article));
} catch (Exception) {
return self::FAILURE;
}
2025-06-29 20:16:25 +02:00
return self::SUCCESS;
}
}