From 004c25ac4b293dc5b0eee696113ed5c8267438ec Mon Sep 17 00:00:00 2001 From: fs Date: Sun, 26 Apr 2026 19:28:12 +0200 Subject: [PATCH] refactor(user-lifecycle-audit): drop unused filterOptions / listFilterOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to commits 144d841 (Embed user lifecycle audit into settings page) + 8c07c2c (Revert "fix(user-lifecycle-panel): restore filter-options population"). The audit page move turned the user-lifecycle list-page into a slot template included by pages/admin/settings/user-lifecycle. Slot templates run during the view phase, where MintyPHP forbids DB calls ("Database can only be used in MintyPHP action", DB.php). The populated actor / action / status / trigger filter dropdowns — previously fed by UserLifecycleAuditService::filterOptions() during the action phase of the now-deleted index().php — therefore had to go away and were not replaced. The service method and its underlying UserLifecycleAuditRepository::listFilterOptions() became dead code in the same commit but were kept; this cleans them up. Removed: * UserLifecycleAuditService::filterOptions(int) — single caller was the deleted index() action. * UserLifecycleAuditRepository::listFilterOptions(int) — single caller was the service method above. * Stale phpstan-baseline.neon entry for the service method. * Now-unused RepositoryArrayHelper import in the repository. Sister services (Api / System / Import) still use their own filterOptions() — their list-pages remain action-driven and can populate dropdowns from the DB. The constant FILTER_OPTIONS_LIMIT_MAX in UserLifecycleAuditRepository is kept; listPaged() reuses it as a generic upper bound for multi-value filter inputs. The reduced-fidelity actor filter in the settings panel (URL-pinned IDs only, no DB-side enumeration) is the architecturally correct trade-off for the slot-based isolation. A future provider mechanism on the slot manifest could restore richer filter population without breaking module isolation, but that is out of scope here. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../UserLifecycleAuditRepository.php | 125 ------------------ .../Service/UserLifecycleAuditService.php | 5 - phpstan-baseline.neon | 6 - 3 files changed, 136 deletions(-) diff --git a/modules/audit/lib/Module/Audit/Repository/UserLifecycleAuditRepository.php b/modules/audit/lib/Module/Audit/Repository/UserLifecycleAuditRepository.php index dca8262..da84dab 100644 --- a/modules/audit/lib/Module/Audit/Repository/UserLifecycleAuditRepository.php +++ b/modules/audit/lib/Module/Audit/Repository/UserLifecycleAuditRepository.php @@ -7,7 +7,6 @@ use MintyPHP\Module\Audit\Domain\UserLifecycleAction; use MintyPHP\Module\Audit\Domain\UserLifecycleStatus; use MintyPHP\Module\Audit\Domain\UserLifecycleTriggerType; use MintyPHP\Repository\Support\RepoQuery; -use MintyPHP\Repository\Support\RepositoryArrayHelper; /** Records user lifecycle transitions (deactivation, deletion, restore) with reason codes and snapshots. */ class UserLifecycleAuditRepository @@ -185,130 +184,6 @@ class UserLifecycleAuditRepository return ['total' => $total, 'rows' => $normalized]; } - public function listFilterOptions(int $limit = self::FILTER_OPTIONS_LIMIT_MAX): array - { - $limit = max(1, min(self::FILTER_OPTIONS_LIMIT_MAX, $limit)); - - $actionRows = DB::select( - 'select - user_lifecycle_audit_log.action, - max(user_lifecycle_audit_log.created_at) as last_used_at - from user_lifecycle_audit_log - where user_lifecycle_audit_log.action is not null - and user_lifecycle_audit_log.action <> \'\' - group by user_lifecycle_audit_log.action - order by last_used_at desc - limit ?', - (string) $limit - ); - - $actions = []; - if (is_array($actionRows)) { - foreach ($actionRows as $row) { - $flat = RepositoryArrayHelper::flattenRow($row); - $action = strtolower(trim((string) ($flat['action'] ?? ''))); - if (UserLifecycleAction::tryNormalize($action) === null) { - continue; - } - $actions[] = $action; - } - } - $actions = array_values(array_unique($actions)); - - $statusRows = DB::select( - 'select - user_lifecycle_audit_log.status, - max(user_lifecycle_audit_log.created_at) as last_used_at - from user_lifecycle_audit_log - where user_lifecycle_audit_log.status is not null - and user_lifecycle_audit_log.status <> \'\' - group by user_lifecycle_audit_log.status - order by last_used_at desc - limit ?', - (string) $limit - ); - - $statuses = []; - if (is_array($statusRows)) { - foreach ($statusRows as $row) { - $flat = RepositoryArrayHelper::flattenRow($row); - $status = strtolower(trim((string) ($flat['status'] ?? ''))); - if (UserLifecycleStatus::tryNormalize($status) === null) { - continue; - } - $statuses[] = $status; - } - } - $statuses = array_values(array_unique($statuses)); - - $triggerRows = DB::select( - 'select - user_lifecycle_audit_log.trigger_type, - max(user_lifecycle_audit_log.created_at) as last_used_at - from user_lifecycle_audit_log - where user_lifecycle_audit_log.trigger_type is not null - and user_lifecycle_audit_log.trigger_type <> \'\' - group by user_lifecycle_audit_log.trigger_type - order by last_used_at desc - limit ?', - (string) $limit - ); - - $triggerTypes = []; - if (is_array($triggerRows)) { - foreach ($triggerRows as $row) { - $flat = RepositoryArrayHelper::flattenRow($row); - $triggerType = strtolower(trim((string) ($flat['trigger_type'] ?? ''))); - if (UserLifecycleTriggerType::tryNormalize($triggerType) === null) { - continue; - } - $triggerTypes[] = $triggerType; - } - } - $triggerTypes = array_values(array_unique($triggerTypes)); - - $actorRows = DB::select( - 'select - user_lifecycle_audit_log.actor_user_id, - max(user_lifecycle_audit_log.created_at) as last_used_at, - max(actor_user.id) as actor_user_exists_id, - max(actor_user.display_name) as actor_user_display_name, - max(actor_user.email) as actor_user_email - from user_lifecycle_audit_log - left join users actor_user on actor_user.id = user_lifecycle_audit_log.actor_user_id - where user_lifecycle_audit_log.actor_user_id is not null - and user_lifecycle_audit_log.actor_user_id > 0 - group by user_lifecycle_audit_log.actor_user_id - order by last_used_at desc - limit ?', - (string) $limit - ); - - $actors = []; - if (is_array($actorRows)) { - foreach ($actorRows as $row) { - $flat = RepositoryArrayHelper::flattenRow($row); - $id = (int) ($flat['actor_user_id'] ?? 0); - if ($id <= 0) { - continue; - } - $actors[] = [ - 'id' => $id, - 'display_name' => trim((string) ($flat['actor_user_display_name'] ?? '')), - 'email' => trim((string) ($flat['actor_user_email'] ?? '')), - 'exists' => (int) ($flat['actor_user_exists_id'] ?? 0) > 0, - ]; - } - } - - return [ - 'actions' => $actions, - 'statuses' => $statuses, - 'trigger_types' => $triggerTypes, - 'actors' => $actors, - ]; - } - public function find(int $id): ?array { if ($id <= 0) { diff --git a/modules/audit/lib/Module/Audit/Service/UserLifecycleAuditService.php b/modules/audit/lib/Module/Audit/Service/UserLifecycleAuditService.php index 8d1a99e..e73dfb2 100644 --- a/modules/audit/lib/Module/Audit/Service/UserLifecycleAuditService.php +++ b/modules/audit/lib/Module/Audit/Service/UserLifecycleAuditService.php @@ -171,11 +171,6 @@ class UserLifecycleAuditService implements UserLifecycleAuditInterface return $this->userLifecycleAuditRepository->find($id); } - public function filterOptions(int $limit = 200): array - { - return $this->userLifecycleAuditRepository->listFilterOptions($limit); - } - public function findDeleteEventForRestore(int $id, bool $forUpdate = false): ?array { return $this->userLifecycleAuditRepository->findDeleteEventForRestore($id, $forUpdate); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4394a53..a9aa975 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1536,12 +1536,6 @@ parameters: count: 1 path: modules/audit/lib/Module/Audit/Service/SystemAuditService.php - - - message: '#^Public method "MintyPHP\\Module\\Audit\\Service\\UserLifecycleAuditService\:\:filterOptions\(\)" is never used$#' - identifier: public.method.unused - count: 1 - path: modules/audit/lib/Module/Audit/Service/UserLifecycleAuditService.php - - message: '#^Public method "MintyPHP\\Module\\Audit\\Service\\UserLifecycleAuditService\:\:find\(\)" is never used$#' identifier: public.method.unused