From 1f07688881b771cf98e22fd3a1a986b246433459 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 8 Sep 2020 12:03:19 +0300 Subject: [PATCH] import console command in classes --- .../Commands => Classes/ConsoleCommands}/Import.php | 7 +++++-- application/Espo/Core/Console/CommandManager.php | 4 +++- .../Espo/Resources/metadata/app/consoleCommands.json | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) rename application/Espo/{Core/Console/Commands => Classes/ConsoleCommands}/Import.php (97%) diff --git a/application/Espo/Core/Console/Commands/Import.php b/application/Espo/Classes/ConsoleCommands/Import.php similarity index 97% rename from application/Espo/Core/Console/Commands/Import.php rename to application/Espo/Classes/ConsoleCommands/Import.php index 7777865289..d2d8e2e5f6 100644 --- a/application/Espo/Core/Console/Commands/Import.php +++ b/application/Espo/Classes/ConsoleCommands/Import.php @@ -27,9 +27,12 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Core\Console\Commands; +namespace Espo\Classes\ConsoleCommands; -use Espo\Core\ServiceFactory; +use Espo\Core\{ + ServiceFactory, + Console\Commands\Command, +}; use Throwable; diff --git a/application/Espo/Core/Console/CommandManager.php b/application/Espo/Core/Console/CommandManager.php index 18138ead0b..9e244c50e0 100644 --- a/application/Espo/Core/Console/CommandManager.php +++ b/application/Espo/Core/Console/CommandManager.php @@ -79,12 +79,14 @@ class CommandManager protected function getClassName(string $command) : string { $className = - $this->metadata->get(['app', 'consoleCommands', $command, 'className']) ?? + $this->metadata->get(['app', 'consoleCommands', lcfirst($command), 'className']) ?? 'Espo\\Core\\Console\\Commands\\' . $command; if (!class_exists($className)) { $msg = "Command '{$command}' does not exist."; + echo $msg . "\n"; + throw new Error($msg); } diff --git a/application/Espo/Resources/metadata/app/consoleCommands.json b/application/Espo/Resources/metadata/app/consoleCommands.json index 9e26dfeeb6..6ea597a950 100644 --- a/application/Espo/Resources/metadata/app/consoleCommands.json +++ b/application/Espo/Resources/metadata/app/consoleCommands.json @@ -1 +1,5 @@ -{} \ No newline at end of file +{ + "import": { + "className": "Espo\\Classes\\ConsoleCommands\\Import" + } +} \ No newline at end of file