Split filter drawer contracts
This commit is contained in:
@@ -16,7 +16,7 @@ final class ModulePermissionSynchronizer
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{created: int, updated: int, unchanged: int, total: int}
|
||||
* @return array{created: int, updated: int, unchanged: int, deactivated: int, total: int}
|
||||
*/
|
||||
public function sync(): array
|
||||
{
|
||||
@@ -66,14 +66,62 @@ final class ModulePermissionSynchronizer
|
||||
$updated++;
|
||||
}
|
||||
|
||||
$deactivated = $this->deactivateOrphaned();
|
||||
|
||||
return [
|
||||
'created' => $created,
|
||||
'updated' => $updated,
|
||||
'unchanged' => $unchanged,
|
||||
'deactivated' => $deactivated,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate system permissions that no active module claims.
|
||||
*
|
||||
* Only touches is_system=1 rows (module-owned). Admin-created permissions
|
||||
* (is_system=0) are never modified. Setting active=0 is reversible — if the
|
||||
* module is re-enabled, the next sync will set active=1 again.
|
||||
*/
|
||||
private function deactivateOrphaned(): int
|
||||
{
|
||||
$activeKeys = $this->moduleRegistry->getPermissionKeys();
|
||||
$systemPermissions = $this->permissionRepository->listSystem();
|
||||
$deactivated = 0;
|
||||
|
||||
foreach ($systemPermissions as $permission) {
|
||||
$key = (string) $permission['key'];
|
||||
$id = (int) $permission['id'];
|
||||
$isActive = (int) $permission['active'];
|
||||
|
||||
if ($key === '' || $id <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Already inactive — nothing to do
|
||||
if ($isActive === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Still claimed by an active module — keep it
|
||||
if (in_array($key, $activeKeys, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Orphaned: system permission not claimed by any active module → deactivate
|
||||
$this->permissionRepository->update($id, [
|
||||
'key' => $key,
|
||||
'description' => (string) $permission['description'],
|
||||
'active' => 0,
|
||||
'is_system' => 1,
|
||||
]);
|
||||
$deactivated++;
|
||||
}
|
||||
|
||||
return $deactivated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $existing
|
||||
* @param array<string, mixed> $desired
|
||||
|
||||
Reference in New Issue
Block a user