forked from fa/breadcrumb-the-shire
refactor(system-info): reduce to Stripe-style status page
Reduce admin/system-info to a single focused status view: overall status banner, components list from existing health checks, and an environment meta table. Drops the Modules and Permissions tabs — those were dev-diagnostics already available via CLI. - Remove SystemInfoService + its test; wire the action directly to SystemHealthService and build meta inline - Extend SystemHealthService with per-check label + description so the UI speaks in customer terms while the CLI doctor path stays compatible - Rebuild the view on existing app-stats-table + app-empty-state primitives; add a small app-status-banner component for the headline signal - Align help-center nav label and i18n keys (de/en) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,6 @@ use MintyPHP\Service\Security\RateLimiterService;
|
||||
use MintyPHP\Service\Security\SecurityServicesFactory;
|
||||
use MintyPHP\Service\Stats\AdminStatsViewDataService;
|
||||
use MintyPHP\Service\System\SystemHealthService;
|
||||
use MintyPHP\Service\System\SystemInfoService;
|
||||
|
||||
final class AppServicesRegistrar implements ContainerRegistrar
|
||||
{
|
||||
@@ -56,11 +55,6 @@ final class AppServicesRegistrar implements ContainerRegistrar
|
||||
$container->set(SystemHealthService::class, static fn (AppContainer $c): SystemHealthService => new SystemHealthService(
|
||||
$c->get(SystemHealthRepository::class)
|
||||
));
|
||||
$container->set(SystemInfoService::class, static fn (AppContainer $c): SystemInfoService => new SystemInfoService(
|
||||
$c->get(SystemHealthService::class),
|
||||
$c->get(SystemHealthRepository::class),
|
||||
$c->has(ModuleRegistry::class) ? $c->get(ModuleRegistry::class) : null
|
||||
));
|
||||
$container->set(SearchDataService::class, static fn (AppContainer $c): SearchDataService => new SearchDataService(
|
||||
$c->get(PermissionService::class),
|
||||
$c->get(UserTenantRepository::class),
|
||||
|
||||
@@ -36,7 +36,7 @@ class SystemHealthService
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{status: string, name: string, message: string}>
|
||||
* @return list<array{status: string, name: string, message: string, label: string, description: string}>
|
||||
*/
|
||||
public function runAll(): array
|
||||
{
|
||||
@@ -51,10 +51,13 @@ class SystemHealthService
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, name: string, message: string}
|
||||
* @return array{status: string, name: string, message: string, label: string, description: string}
|
||||
*/
|
||||
public function checkDatabase(): array
|
||||
{
|
||||
$label = 'Database';
|
||||
$okDescription = 'Connection established';
|
||||
|
||||
try {
|
||||
$ok = $this->repository->checkDatabaseConnectivity();
|
||||
|
||||
@@ -62,21 +65,27 @@ class SystemHealthService
|
||||
'status' => $ok ? 'ok' : 'fail',
|
||||
'name' => 'Database connectivity',
|
||||
'message' => $ok ? 'connection established' : 'select 1 did not return expected value',
|
||||
'label' => $label,
|
||||
'description' => $ok ? $okDescription : 'Database did not return the expected response',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'name' => 'Database connectivity',
|
||||
'message' => 'check failed',
|
||||
'label' => $label,
|
||||
'description' => 'Database check could not be executed',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, name: string, message: string}
|
||||
* @return array{status: string, name: string, message: string, label: string, description: string}
|
||||
*/
|
||||
public function checkDatabaseSchema(): array
|
||||
{
|
||||
$label = 'Database schema';
|
||||
|
||||
try {
|
||||
$present = $this->repository->listPresentTables(self::REQUIRED_TABLES);
|
||||
sort($present, SORT_STRING);
|
||||
@@ -87,6 +96,8 @@ class SystemHealthService
|
||||
'status' => 'fail',
|
||||
'name' => 'Database schema',
|
||||
'message' => 'missing tables: ' . implode(', ', $missing),
|
||||
'label' => $label,
|
||||
'description' => 'Required core tables are missing',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -94,21 +105,27 @@ class SystemHealthService
|
||||
'status' => 'ok',
|
||||
'name' => 'Database schema',
|
||||
'message' => sprintf('%d core tables present', count(self::REQUIRED_TABLES)),
|
||||
'label' => $label,
|
||||
'description' => 'All required core tables are present',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'name' => 'Database schema',
|
||||
'message' => 'check failed',
|
||||
'label' => $label,
|
||||
'description' => 'Schema check could not be executed',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, name: string, message: string}
|
||||
* @return array{status: string, name: string, message: string, label: string, description: string}
|
||||
*/
|
||||
public function checkStorageWriteability(): array
|
||||
{
|
||||
$label = 'Storage';
|
||||
|
||||
try {
|
||||
$storagePath = defined('APP_STORAGE_PATH') && APP_STORAGE_PATH
|
||||
? rtrim((string) APP_STORAGE_PATH, '/')
|
||||
@@ -119,6 +136,8 @@ class SystemHealthService
|
||||
'status' => 'fail',
|
||||
'name' => 'Storage writeability',
|
||||
'message' => 'storage directory not found',
|
||||
'label' => $label,
|
||||
'description' => 'Storage directory is missing',
|
||||
];
|
||||
}
|
||||
if (!is_writable($storagePath)) {
|
||||
@@ -126,6 +145,8 @@ class SystemHealthService
|
||||
'status' => 'fail',
|
||||
'name' => 'Storage writeability',
|
||||
'message' => 'storage directory not writable',
|
||||
'label' => $label,
|
||||
'description' => 'Storage directory is not writable',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -136,6 +157,8 @@ class SystemHealthService
|
||||
'status' => 'fail',
|
||||
'name' => 'Storage writeability',
|
||||
'message' => 'write probe failed',
|
||||
'label' => $label,
|
||||
'description' => 'Storage write probe failed',
|
||||
];
|
||||
}
|
||||
@unlink($probeFile);
|
||||
@@ -144,21 +167,27 @@ class SystemHealthService
|
||||
'status' => 'ok',
|
||||
'name' => 'Storage writeability',
|
||||
'message' => 'storage path is writable',
|
||||
'label' => $label,
|
||||
'description' => 'Storage path is writable',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'name' => 'Storage writeability',
|
||||
'message' => 'check failed',
|
||||
'label' => $label,
|
||||
'description' => 'Storage check could not be executed',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, name: string, message: string}
|
||||
* @return array{status: string, name: string, message: string, label: string, description: string}
|
||||
*/
|
||||
public function checkRbacBaseline(): array
|
||||
{
|
||||
$label = 'Permissions';
|
||||
|
||||
try {
|
||||
$present = $this->repository->listActivePermissionKeys(self::REQUIRED_PERMISSIONS);
|
||||
sort($present, SORT_STRING);
|
||||
@@ -169,6 +198,8 @@ class SystemHealthService
|
||||
'status' => 'fail',
|
||||
'name' => 'RBAC baseline',
|
||||
'message' => 'missing active permissions: ' . implode(', ', $missing),
|
||||
'label' => $label,
|
||||
'description' => 'Baseline permissions are missing',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -176,21 +207,27 @@ class SystemHealthService
|
||||
'status' => 'ok',
|
||||
'name' => 'RBAC baseline',
|
||||
'message' => sprintf('%d baseline permissions active', count(self::REQUIRED_PERMISSIONS)),
|
||||
'label' => $label,
|
||||
'description' => 'Baseline permissions are present',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'name' => 'RBAC baseline',
|
||||
'message' => 'check failed',
|
||||
'label' => $label,
|
||||
'description' => 'Permission check could not be executed',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, name: string, message: string}
|
||||
* @return array{status: string, name: string, message: string, label: string, description: string}
|
||||
*/
|
||||
public function checkAdminRoleAssignment(): array
|
||||
{
|
||||
$label = 'Administrators';
|
||||
|
||||
try {
|
||||
$count = $this->repository->countAdminUsers();
|
||||
|
||||
@@ -199,6 +236,8 @@ class SystemHealthService
|
||||
'status' => 'fail',
|
||||
'name' => 'Admin role assignment',
|
||||
'message' => 'no active user assigned to Admin/Administrator role',
|
||||
'label' => $label,
|
||||
'description' => 'No active user has the administrator role',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -206,21 +245,27 @@ class SystemHealthService
|
||||
'status' => 'ok',
|
||||
'name' => 'Admin role assignment',
|
||||
'message' => sprintf('%d admin user(s) assigned', $count),
|
||||
'label' => $label,
|
||||
'description' => 'At least one administrator is active',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'name' => 'Admin role assignment',
|
||||
'message' => 'check failed',
|
||||
'label' => $label,
|
||||
'description' => 'Administrator check could not be executed',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, name: string, message: string}
|
||||
* @return array{status: string, name: string, message: string, label: string, description: string}
|
||||
*/
|
||||
public function checkSchedulerHeartbeat(): array
|
||||
{
|
||||
$label = 'Scheduler';
|
||||
|
||||
try {
|
||||
$status = $this->repository->getSchedulerStatus();
|
||||
|
||||
@@ -229,6 +274,8 @@ class SystemHealthService
|
||||
'status' => 'warn',
|
||||
'name' => 'Scheduler heartbeat',
|
||||
'message' => 'no scheduler runtime status row found yet',
|
||||
'label' => $label,
|
||||
'description' => 'Scheduler has not reported yet',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -241,22 +288,29 @@ class SystemHealthService
|
||||
'status' => 'warn',
|
||||
'name' => 'Scheduler heartbeat',
|
||||
'message' => 'scheduler heartbeat is empty',
|
||||
'label' => $label,
|
||||
'description' => 'Scheduler heartbeat is empty',
|
||||
];
|
||||
}
|
||||
|
||||
$seconds = max(0, time() - strtotime($heartbeat . ' UTC'));
|
||||
$detail = "last heartbeat {$seconds}s ago (result={$result}" . ($errorCode !== '' ? ", error={$errorCode}" : '') . ')';
|
||||
$stale = $seconds > self::SCHEDULER_STALE_THRESHOLD_SECONDS;
|
||||
|
||||
return [
|
||||
'status' => $seconds > self::SCHEDULER_STALE_THRESHOLD_SECONDS ? 'warn' : 'ok',
|
||||
'status' => $stale ? 'warn' : 'ok',
|
||||
'name' => 'Scheduler heartbeat',
|
||||
'message' => $detail,
|
||||
'label' => $label,
|
||||
'description' => $stale ? 'Scheduler heartbeat is outdated' : 'Scheduler is running on schedule',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'name' => 'Scheduler heartbeat',
|
||||
'message' => 'check failed',
|
||||
'label' => $label,
|
||||
'description' => 'Scheduler check could not be executed',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\System;
|
||||
|
||||
use MintyPHP\App\Module\ModuleRegistry;
|
||||
use MintyPHP\Repository\System\SystemHealthRepositoryInterface;
|
||||
|
||||
class SystemInfoService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SystemHealthService $healthService,
|
||||
private readonly SystemHealthRepositoryInterface $healthRepository,
|
||||
private readonly ?ModuleRegistry $moduleRegistry = null
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function buildPageData(): array
|
||||
{
|
||||
return [
|
||||
'overview' => $this->buildOverview(),
|
||||
'modules' => $this->buildModuleInventory(),
|
||||
'permissions' => $this->buildPermissionSummary(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function buildOverview(): array
|
||||
{
|
||||
return [
|
||||
'php_version' => PHP_VERSION,
|
||||
'php_sapi' => PHP_SAPI,
|
||||
'app_environment' => $this->resolveEnvironment(),
|
||||
'health_checks' => $this->healthService->runAll(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{id: string, version: string, enabled_by_default: bool, requires: list<string>, permissions_count: int}>
|
||||
*/
|
||||
private function buildModuleInventory(): array
|
||||
{
|
||||
if ($this->moduleRegistry === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$modules = [];
|
||||
foreach ($this->moduleRegistry->getModules() as $manifest) {
|
||||
$modules[] = [
|
||||
'id' => $manifest->id,
|
||||
'version' => $manifest->version,
|
||||
'enabled_by_default' => $manifest->enabledByDefault,
|
||||
'requires' => $manifest->requires,
|
||||
'permissions_count' => count($manifest->permissions),
|
||||
];
|
||||
}
|
||||
|
||||
usort($modules, static fn (array $a, array $b): int => strcmp($a['id'], $b['id']));
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{active_count: int, inactive_count: int, by_source: array<string, int>}
|
||||
*/
|
||||
private function buildPermissionSummary(): array
|
||||
{
|
||||
$activeKeys = $this->healthRepository->listAllActivePermissionKeys();
|
||||
$bySource = $this->derivePermissionsBySource($activeKeys);
|
||||
|
||||
return [
|
||||
'active_count' => $this->healthRepository->countActivePermissions(),
|
||||
'inactive_count' => $this->healthRepository->countInactivePermissions(),
|
||||
'by_source' => $bySource,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $activeKeys
|
||||
* @return array<string, int>
|
||||
*/
|
||||
private function derivePermissionsBySource(array $activeKeys): array
|
||||
{
|
||||
$moduleKeys = [];
|
||||
if ($this->moduleRegistry !== null) {
|
||||
foreach ($this->moduleRegistry->getModules() as $manifest) {
|
||||
foreach ($manifest->permissions as $perm) {
|
||||
$key = $perm['key'];
|
||||
if ($key !== '') {
|
||||
$moduleKeys[$key] = $manifest->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
foreach ($activeKeys as $key) {
|
||||
$source = $moduleKeys[$key] ?? 'core';
|
||||
$counts[$source] = ($counts[$source] ?? 0) + 1;
|
||||
}
|
||||
|
||||
ksort($counts);
|
||||
|
||||
return $counts;
|
||||
}
|
||||
|
||||
private function resolveEnvironment(): string
|
||||
{
|
||||
if (defined('APP_ENV')) {
|
||||
return (string) constant('APP_ENV');
|
||||
}
|
||||
|
||||
$env = getenv('APP_ENV');
|
||||
|
||||
return is_string($env) && $env !== '' ? $env : 'unknown';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user