From 7c1144fa2ca1da1659074c9bb06562cfc2c9dbc3 Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 12 Feb 2019 11:54:08 +0200 Subject: [PATCH] concole command changes --- .../Espo/Core/Console/CommandManager.php | 18 +++++++++++++++++- .../Espo/Core/Console/Commands/AclCheck.php | 17 +++++++---------- .../Core/Console/Commands/AuthTokenCheck.php | 4 ++-- .../Espo/Resources/metadata/app/webSocket.json | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/application/Espo/Core/Console/CommandManager.php b/application/Espo/Core/Console/CommandManager.php index bc069061b4..9601fd599f 100644 --- a/application/Espo/Core/Console/CommandManager.php +++ b/application/Espo/Core/Console/CommandManager.php @@ -42,6 +42,22 @@ class CommandManager { $command = ucfirst(\Espo\Core\Utils\Util::hyphenToCamelCase($command)); + $argumentList = []; + $options = []; + $flagList = []; + + foreach ($_SERVER['argv'] as $i => $item) { + if ($i < 2) continue; + $argumentList[] = $item; + + if (strpos($item, '--') === 0 && strpos($item, '=') > 2) { + list($name, $value) = explode('=', substr($item, 2)); + $options[$name] = $value; + } else if (strpos($item, '-') === 0) { + $flagList[] = substr($item, 1); + } + } + $className = '\\Espo\\Core\\Console\\Commands\\' . $command; $className = $this->container->get('metadata')->get(['app', 'consoleCommands', $command, 'className'], $className); if (!class_exists($className)) { @@ -50,6 +66,6 @@ class CommandManager throw new \Espo\Core\Exceptions\Error($msg); } $impl = new $className($this->container); - return $impl->run(); + return $impl->run($options, $flagList, $argumentList); } } diff --git a/application/Espo/Core/Console/Commands/AclCheck.php b/application/Espo/Core/Console/Commands/AclCheck.php index 1512976f91..7ef91cad42 100644 --- a/application/Espo/Core/Console/Commands/AclCheck.php +++ b/application/Espo/Core/Console/Commands/AclCheck.php @@ -31,21 +31,18 @@ namespace Espo\Core\Console\Commands; class AclCheck extends Base { - public function run() + public function run($options) { - $userId = isset($_SERVER['argv'][2]) ? trim($_SERVER['argv'][2]) : null; + $userId = $options['userId'] ?? null; + $scope = $options['scope'] ?? null; + $id = $options['id'] ?? null; + $action = $options['action'] ?? null; + $portalId = $options['portalId'] ?? null; + if (empty($userId)) return; - - $scope = isset($_SERVER['argv'][3]) ? trim($_SERVER['argv'][3]) : null; if (empty($scope)) return; - - $id = isset($_SERVER['argv'][4]) ? trim($_SERVER['argv'][4]) : null; if (empty($id)) return; - $action = isset($_SERVER['argv'][5]) ? trim($_SERVER['argv'][5]) : null; - - $portalId = isset($_SERVER['argv'][6]) ? trim($_SERVER['argv'][6]) : null; - $container = $this->getContainer(); if ($portalId) { diff --git a/application/Espo/Core/Console/Commands/AuthTokenCheck.php b/application/Espo/Core/Console/Commands/AuthTokenCheck.php index d1187a31aa..415b7620dc 100644 --- a/application/Espo/Core/Console/Commands/AuthTokenCheck.php +++ b/application/Espo/Core/Console/Commands/AuthTokenCheck.php @@ -31,9 +31,9 @@ namespace Espo\Core\Console\Commands; class AuthTokenCheck extends Base { - public function run() + public function run($options, $flagList, $argumentList) { - $token = isset($_SERVER['argv'][2]) ? trim($_SERVER['argv'][2]) : null; + $token = $argumentList[0] ?? null; if (empty($token)) return; $entityManager = $this->getContainer()->get('entityManager'); diff --git a/application/Espo/Resources/metadata/app/webSocket.json b/application/Espo/Resources/metadata/app/webSocket.json index 0abe89ee01..cfa455fffa 100644 --- a/application/Espo/Resources/metadata/app/webSocket.json +++ b/application/Espo/Resources/metadata/app/webSocket.json @@ -3,7 +3,7 @@ "newNotification": {}, "streamUpdate": { "paramList": ["scope", "id", "portalId"], - "accessCheckCommand": "AclCheck :userId :scope :id stream :portalId" + "accessCheckCommand": "AclCheck --userId=:userId --scope=:scope --id=:id --action=stream --portalId=:portalId" } } }