60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\PlatformEnum;
|
|
use App\Jobs\SyncChannelPostsJob;
|
|
use App\Modules\Lemmy\Services\LemmyApiService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SyncChannelPostsCommand extends Command
|
|
{
|
|
protected $signature = 'channel:sync {platform=lemmy}';
|
|
|
|
protected $description = 'Manually sync channel posts for a platform';
|
|
|
|
public function handle(): int
|
|
{
|
|
$platform = $this->argument('platform');
|
|
|
|
if ($platform === 'lemmy') {
|
|
return $this->syncLemmy();
|
|
}
|
|
|
|
$this->error("Unsupported platform: {$platform}");
|
|
return self::FAILURE;
|
|
}
|
|
|
|
private function syncLemmy(): int
|
|
{
|
|
$communityName = config('lemmy.community');
|
|
|
|
if (!$communityName) {
|
|
$this->error('Missing Lemmy community configuration (lemmy.community)');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
try {
|
|
$this->info("Getting community ID for: {$communityName}");
|
|
|
|
$api = new LemmyApiService(config('lemmy.instance'));
|
|
$communityId = $api->getCommunityId($communityName);
|
|
|
|
$this->info("Running sync job for Lemmy community: {$communityName} (ID: {$communityId})");
|
|
|
|
SyncChannelPostsJob::dispatchSync(
|
|
PlatformEnum::LEMMY,
|
|
(string) $communityId,
|
|
$communityName
|
|
);
|
|
|
|
$this->info('Channel posts synced successfully');
|
|
|
|
return self::SUCCESS;
|
|
|
|
} catch (\Exception $e) {
|
|
$this->error("Failed to sync channel posts: {$e->getMessage()}");
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
}
|