56 lines
1.6 KiB
PHP
56 lines
1.6 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
|
||
|
|
{
|
||
|
|
$warningsBefore = moduleCliVendorWarningsIgnoredTotal();
|
||
|
|
moduleCliBootstrapApp();
|
||
|
|
|
||
|
|
$exitCode = 0;
|
||
|
|
try {
|
||
|
|
$synchronizer = new ModulePermissionSynchronizer(
|
||
|
|
app(ModuleRegistry::class),
|
||
|
|
app(PermissionRepository::class)
|
||
|
|
);
|
||
|
|
$result = $synchronizer->sync();
|
||
|
|
|
||
|
|
fwrite(STDOUT, sprintf(
|
||
|
|
"module-permissions-sync: created=%d updated=%d unchanged=%d total=%d\n",
|
||
|
|
$result['created'],
|
||
|
|
$result['updated'],
|
||
|
|
$result['unchanged'],
|
||
|
|
$result['total']
|
||
|
|
));
|
||
|
|
} catch (Throwable $exception) {
|
||
|
|
fwrite(STDERR, sprintf("module-permissions-sync: FAILED: %s\n", $exception->getMessage()));
|
||
|
|
$exitCode = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
$vendorWarningsIgnored = moduleCliVendorWarningsIgnoredSince($warningsBefore);
|
||
|
|
fwrite(STDOUT, sprintf("module-permissions-sync: vendor_warnings_ignored=%d\n", $vendorWarningsIgnored));
|
||
|
|
|
||
|
|
return $exitCode;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
|
||
|
|
exit(modulePermissionsSyncRun());
|
||
|
|
}
|