31 lines
748 B
PHP
31 lines
748 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::fetchArticleData($article));
|
|
} catch (Exception) {
|
|
return self::FAILURE;
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|