fedi-feed-router/app/Services/SystemStatusService.php
myrmidex 6784af2ff6
Some checks failed
CI / ci (push) Failing after 4m31s
25 - Fix all PHPStan errors and add mockery extension
2026-03-08 14:18:28 +01:00

52 lines
1.4 KiB
PHP

<?php
namespace App\Services;
use App\Models\Feed;
use App\Models\PlatformChannel;
use App\Models\Route;
use App\Models\Setting;
class SystemStatusService
{
/**
* @return array{is_enabled: bool, status: string, status_class: string, reasons: array<int, string>}
*/
public function getSystemStatus(): array
{
$reasons = [];
$isEnabled = true;
if (! Setting::isArticleProcessingEnabled()) {
$isEnabled = false;
$reasons[] = 'Manually disabled by user';
}
if (! Feed::where('is_active', true)->exists()) {
$isEnabled = false;
$reasons[] = 'No active feeds configured';
}
if (! PlatformChannel::where('is_active', true)->exists()) {
$isEnabled = false;
$reasons[] = 'No active platform channels configured';
}
if (! Route::where('is_active', true)->exists()) {
$isEnabled = false;
$reasons[] = 'No active feed-to-channel routes configured';
}
return [
'is_enabled' => $isEnabled,
'status' => $isEnabled ? 'Enabled' : 'Disabled',
'status_class' => $isEnabled ? 'text-green-600' : 'text-red-600',
'reasons' => $reasons,
];
}
public function canProcessArticles(): bool
{
return $this->getSystemStatus()['is_enabled'];
}
}