diff --git a/app/Jobs/SyncChannelPostsJob.php b/app/Jobs/SyncChannelPostsJob.php index 5754d5c..371db60 100644 --- a/app/Jobs/SyncChannelPostsJob.php +++ b/app/Jobs/SyncChannelPostsJob.php @@ -63,11 +63,11 @@ private function syncLemmyChannelPosts(): void $token = $this->getAuthToken($api, $account); // Get community ID from channel_id or resolve from name - $communityId = $this->channel->channel_id + $platformChannelId = $this->channel->channel_id ? (int) $this->channel->channel_id - : $api->getCommunityId($this->channel->name); + : $api->getCommunityId($this->channel->name, $token); - $api->syncChannelPosts($token, $communityId, $this->channel->name); + $api->syncChannelPosts($token, $platformChannelId, $this->channel->name); LogSaver::info('Channel posts synced successfully', $this->channel); diff --git a/app/Modules/Lemmy/Services/LemmyApiService.php b/app/Modules/Lemmy/Services/LemmyApiService.php index 1d16352..87f75f0 100644 --- a/app/Modules/Lemmy/Services/LemmyApiService.php +++ b/app/Modules/Lemmy/Services/LemmyApiService.php @@ -5,7 +5,6 @@ use App\Enums\PlatformEnum; use App\Models\PlatformChannelPost; use App\Modules\Lemmy\LemmyRequest; -use App\Services\Auth\LemmyAuthService; use Exception; class LemmyApiService @@ -42,10 +41,9 @@ public function login(string $username, string $password): ?string } } - public function getCommunityId(string $communityName): int + public function getCommunityId(string $communityName, string $token): int { try { - $token = LemmyAuthService::getToken(); $request = new LemmyRequest($this->instance, $token); $response = $request->get('community', ['name' => $communityName]); @@ -61,12 +59,12 @@ public function getCommunityId(string $communityName): int } } - public function syncChannelPosts(string $token, int $communityId, string $communityName): void + public function syncChannelPosts(string $token, int $platformChannelId, string $communityName): void { try { $request = new LemmyRequest($this->instance, $token); $response = $request->get('post/list', [ - 'community_id' => $communityId, + 'community_id' => $platformChannelId, 'limit' => 50, 'sort' => 'New' ]); @@ -74,7 +72,7 @@ public function syncChannelPosts(string $token, int $communityId, string $commun if (!$response->successful()) { logger()->warning('Failed to sync channel posts', [ 'status' => $response->status(), - 'community_id' => $communityId + 'platform_channel_id' => $platformChannelId ]); return; } @@ -87,7 +85,7 @@ public function syncChannelPosts(string $token, int $communityId, string $commun PlatformChannelPost::storePost( PlatformEnum::LEMMY, - (string) $communityId, + (string) $platformChannelId, $communityName, (string) $post['id'], $post['url'] ?? null, @@ -97,19 +95,19 @@ public function syncChannelPosts(string $token, int $communityId, string $commun } logger()->info('Synced channel posts', [ - 'community_id' => $communityId, + 'platform_channel_id' => $platformChannelId, 'posts_count' => count($posts) ]); } catch (Exception $e) { logger()->error('Exception while syncing channel posts', [ 'error' => $e->getMessage(), - 'community_id' => $communityId + 'platform_channel_id' => $platformChannelId ]); } } - public function createPost(string $token, string $title, string $body, int $communityId, ?string $url = null, ?string $thumbnail = null, ?int $languageId = null): array + public function createPost(string $token, string $title, string $body, int $platformChannelId, ?string $url = null, ?string $thumbnail = null, ?int $languageId = null): array { try { $request = new LemmyRequest($this->instance, $token); @@ -117,7 +115,7 @@ public function createPost(string $token, string $title, string $body, int $comm $postData = [ 'name' => $title, 'body' => $body, - 'community_id' => $communityId, + 'community_id' => $platformChannelId, ]; if ($url) { diff --git a/composer.json b/composer.json index a7f347a..f165296 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,13 @@ }, "require-dev": { "fakerphp/faker": "^1.23", + "larastan/larastan": "^3.5", "laravel/pail": "^1.2.2", "laravel/pint": "^1.18", "laravel/sail": "^1.43", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", + "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^11.5.3" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b81b702 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +includes: + - vendor/larastan/larastan/extension.neon + +parameters: + level: 0 + paths: + - app/ + - tests/ + + excludePaths: + - bootstrap/*.php + - storage/* \ No newline at end of file