forked from fa/breadcrumb-the-shire
deactivateOrphaned() treated ALL is_system=1 permissions as module-owned. Core seed permissions (users.view, tenants.view, etc.) are also is_system=1, so they were incorrectly deactivated — breaking admin panel access. Fix: scan all module manifests on disk (enabled or not) to build the set of module-owned permission keys. Only deactivate permissions whose key appears in that set. Core seed permissions are never touched. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
/**
|
|
* Synchronizes module-declared permissions into the permissions table.
|
|
*
|
|
* Usage: php bin/module-permissions-sync.php
|
|
*
|
|
* Exit codes:
|
|
* 0 — sync successful
|
|
* 1 — error during sync
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use MintyPHP\App\Module\ModulePermissionSynchronizer;
|
|
use MintyPHP\App\Module\ModuleRegistry;
|
|
use MintyPHP\Repository\Access\PermissionRepository;
|
|
|
|
require_once __DIR__ . '/module-cli-bootstrap.php';
|
|
|
|
function modulePermissionsSyncRun(): int
|
|
{
|
|
return moduleCliRunStep('module-permissions-sync', static function (): int {
|
|
$lockFile = __DIR__ . '/../storage/runtime/.module-permissions-sync.lock';
|
|
|
|
return moduleCliWithFileLock(
|
|
$lockFile,
|
|
'module-permissions-sync: another sync is in progress, skipping.',
|
|
static function (): int {
|
|
$synchronizer = new ModulePermissionSynchronizer(
|
|
app(ModuleRegistry::class),
|
|
app(PermissionRepository::class),
|
|
moduleCliProjectRoot() . '/modules'
|
|
);
|
|
$result = $synchronizer->sync();
|
|
|
|
fwrite(STDOUT, sprintf(
|
|
"module-permissions-sync: created=%d updated=%d unchanged=%d deactivated=%d total=%d\n",
|
|
$result['created'],
|
|
$result['updated'],
|
|
$result['unchanged'],
|
|
$result['deactivated'],
|
|
$result['total']
|
|
));
|
|
|
|
return 0;
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
|
|
fwrite(STDERR, "Hint: prefer `php bin/console module:permissions-sync` instead.\n");
|
|
exit(modulePermissionsSyncRun());
|
|
}
|