diff --git a/app/Http/Controllers/PlatformAccountsController.php b/app/Http/Controllers/PlatformAccountsController.php index 2d3870c..713b022 100644 --- a/app/Http/Controllers/PlatformAccountsController.php +++ b/app/Http/Controllers/PlatformAccountsController.php @@ -100,6 +100,6 @@ public function setActive(PlatformAccount $platformAccount): RedirectResponse $platformAccount->setAsActive(); return redirect()->route('platforms.index') - ->with('success', "Set $platformAccount->username@$platformAccount->instance_url as active for $platformAccount->platform!"); + ->with('success', "Set $platformAccount->username@$platformAccount->instance_url as active for {$platformAccount->platform->value}!"); } } diff --git a/app/Http/Controllers/RoutingController.php b/app/Http/Controllers/RoutingController.php index e39bd2d..1d2db44 100644 --- a/app/Http/Controllers/RoutingController.php +++ b/app/Http/Controllers/RoutingController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Feed; +use App\Models\FeedPlatformChannel; use App\Models\PlatformChannel; use App\Services\RoutingValidationService; use App\Exceptions\RoutingMismatchException; @@ -127,15 +128,15 @@ public function destroy(Feed $feed, PlatformChannel $channel): RedirectResponse public function toggle(Request $request, Feed $feed, PlatformChannel $channel): RedirectResponse { - $routing = $feed->channels() - ->wherePivot('platform_channel_id', $channel->id) + $routing = FeedPlatformChannel::where('feed_id', $feed->id) + ->where('platform_channel_id', $channel->id) ->first(); if (! $routing) { abort(404, 'Routing not found'); } - $newStatus = ! $routing->pivot->is_active; + $newStatus = ! $routing->is_active; $feed->channels()->updateExistingPivot($channel->id, [ 'is_active' => $newStatus, diff --git a/app/Models/PlatformChannel.php b/app/Models/PlatformChannel.php index b9f1a2c..9160496 100644 --- a/app/Models/PlatformChannel.php +++ b/app/Models/PlatformChannel.php @@ -53,6 +53,11 @@ public function platformAccounts(): BelongsToMany ->withTimestamps(); } + public function activePlatformAccounts(): BelongsToMany + { + return $this->platformAccounts()->where('is_active', true); + } + public function getFullNameAttribute(): string { // For Lemmy, use /c/ prefix. Other platforms may use different formats diff --git a/app/Services/Publishing/ArticlePublishingService.php b/app/Services/Publishing/ArticlePublishingService.php index 79e5cc2..a764466 100644 --- a/app/Services/Publishing/ArticlePublishingService.php +++ b/app/Services/Publishing/ArticlePublishingService.php @@ -6,6 +6,7 @@ use App\Exceptions\PublishException; use App\Models\Article; use App\Models\ArticlePublication; +use App\Models\PlatformChannel; use App\Modules\Lemmy\Services\LemmyPublisher; use App\Services\Log\LogSaver; use Exception; @@ -24,10 +25,10 @@ public function publishToRoutedChannels(Article $article, array $extractedData): } $feed = $article->feed; - $activeChannels = $feed->activeChannels()->with(['platformInstance', 'platformAccounts'])->get(); + $activeChannels = $feed->activeChannels()->with(['platformInstance', 'activePlatformAccounts'])->get(); - return $activeChannels->map(function ($channel) use ($article, $extractedData) { - $account = $channel->platformAccounts()->where('is_active', true)->first(); + return $activeChannels->map(function (PlatformChannel $channel) use ($article, $extractedData) { + $account = $channel->activePlatformAccounts()->first(); if (! $account) { LogSaver::warning('No active account for channel', $channel, [ diff --git a/phpstan.neon b/phpstan.neon index b81b702..1a56d53 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,7 +2,7 @@ includes: - vendor/larastan/larastan/extension.neon parameters: - level: 0 + level: 2 paths: - app/ - tests/