From 0a115a3603e3577fa44b2cd141b05e504fcc60c3 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 4 Apr 2024 20:53:33 +0300 Subject: [PATCH] command noSystemUser param --- .../Espo/Core/ApplicationRunners/Command.php | 1 - .../Espo/Core/Console/CommandManager.php | 21 +++++++++++++++-- .../metadata/app/consoleCommands.json | 23 +++++++++++++++---- schema/metadata/app/consoleCommands.json | 4 ++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/application/Espo/Core/ApplicationRunners/Command.php b/application/Espo/Core/ApplicationRunners/Command.php index bd54556606..c83f132c6a 100644 --- a/application/Espo/Core/ApplicationRunners/Command.php +++ b/application/Espo/Core/ApplicationRunners/Command.php @@ -40,7 +40,6 @@ use Exception; class Command implements Runner { use Cli; - use SetupSystemUser; public function __construct(private ConsoleCommandManager $commandManager) {} diff --git a/application/Espo/Core/Console/CommandManager.php b/application/Espo/Core/Console/CommandManager.php index 48c3a48ba8..37c2c329fa 100644 --- a/application/Espo/Core/Console/CommandManager.php +++ b/application/Espo/Core/Console/CommandManager.php @@ -29,6 +29,7 @@ namespace Espo\Core\Console; +use Espo\Core\ApplicationUser; use Espo\Core\InjectableFactory; use Espo\Core\Utils\Metadata; use Espo\Core\Utils\Util; @@ -44,8 +45,11 @@ class CommandManager private const DEFAULT_COMMAND = 'Help'; private const DEFAULT_COMMAND_FLAG = 'help'; - public function __construct(private InjectableFactory $injectableFactory, private Metadata $metadata) - {} + public function __construct( + private InjectableFactory $injectableFactory, + private Metadata $metadata, + private ApplicationUser $applicationUser + ) {} /** * @param array $argv @@ -75,6 +79,8 @@ class CommandManager $io = new IO(); + $this->setupUser($command); + $commandObj = $this->createCommand($command); if (!$commandObj instanceof Command) { @@ -146,4 +152,15 @@ class CommandManager { return Params::fromArgs(array_slice($argv, 1)); } + + private function setupUser(string $command): void + { + $noSystemUser = $this->metadata->get(['app', 'consoleCommands', lcfirst($command), 'noSystemUser']); + + if ($noSystemUser) { + return; + } + + $this->applicationUser->setupSystemUser(); + } } diff --git a/application/Espo/Resources/metadata/app/consoleCommands.json b/application/Espo/Resources/metadata/app/consoleCommands.json index 321f9f89e6..c34ebea896 100644 --- a/application/Espo/Resources/metadata/app/consoleCommands.json +++ b/application/Espo/Resources/metadata/app/consoleCommands.json @@ -4,13 +4,16 @@ "listed": true }, "clearCache": { - "listed": true + "listed": true, + "noSystemUser": true }, "rebuild": { - "listed": true + "listed": true, + "noSystemUser": true }, "updateAppTimestamp": { - "listed": true + "listed": true, + "noSystemUser": true }, "appInfo": { "listed": true @@ -28,7 +31,8 @@ "listed": true }, "version": { - "listed": true + "listed": true, + "noSystemUser": true }, "createAdminUser": { "className": "Espo\\Classes\\ConsoleCommands\\CreateAdminUser", @@ -48,6 +52,15 @@ }, "checkFilePermissions": { "className": "Espo\\Classes\\ConsoleCommands\\CheckFilePermissions", - "listed": true + "listed": true, + "noSystemUser": true + }, + "migrate": { + "listed": true, + "noSystemUser": true + }, + "migrationVersionStep": { + "listed": false, + "noSystemUser": true } } diff --git a/schema/metadata/app/consoleCommands.json b/schema/metadata/app/consoleCommands.json index 8a9ac44140..5563cce1ee 100644 --- a/schema/metadata/app/consoleCommands.json +++ b/schema/metadata/app/consoleCommands.json @@ -15,6 +15,10 @@ "listed": { "type": "boolean", "description": "Whether the command is listed when running bin/command." + }, + "noSystemUser": { + "type": "boolean", + "description": "Do not load the system user." } } }