concole command changes

This commit is contained in:
yuri
2019-02-12 11:54:08 +02:00
parent 6008f1abb2
commit 7c1144fa2c
4 changed files with 27 additions and 14 deletions
@@ -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);
}
}
@@ -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) {
@@ -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');
@@ -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"
}
}
}