Refactor bin scripts: shared CLI bootstrap, robust module migrate, and runtime locking
This commit is contained in:
@@ -21,33 +21,31 @@ require_once __DIR__ . '/module-cli-bootstrap.php';
|
||||
|
||||
function modulePermissionsSyncRun(): int
|
||||
{
|
||||
$warningsBefore = moduleCliVendorWarningsIgnoredTotal();
|
||||
moduleCliBootstrapApp();
|
||||
return moduleCliRunStep('module-permissions-sync', static function (): int {
|
||||
$lockFile = __DIR__ . '/../storage/runtime/.module-permissions-sync.lock';
|
||||
|
||||
$exitCode = 0;
|
||||
try {
|
||||
$synchronizer = new ModulePermissionSynchronizer(
|
||||
app(ModuleRegistry::class),
|
||||
app(PermissionRepository::class)
|
||||
return moduleCliWithFileLock(
|
||||
$lockFile,
|
||||
'module-permissions-sync: another sync is in progress, skipping.',
|
||||
static function (): int {
|
||||
$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']
|
||||
));
|
||||
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
$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__) {
|
||||
|
||||
Reference in New Issue
Block a user