mirror of
https://github.com/espocrm/espocrm.git
synced 2026-03-03 03:57:01 +00:00
ConsoleCommand framework
This commit is contained in:
@@ -179,7 +179,7 @@ module.exports = function (grunt) {
|
||||
'upgrade.php',
|
||||
'extension.php',
|
||||
'websocket.php',
|
||||
'auth_token_check.php',
|
||||
'command.php',
|
||||
'index.php',
|
||||
'LICENSE.txt',
|
||||
'.htaccess',
|
||||
|
||||
@@ -212,6 +212,12 @@ class Application
|
||||
$dataManager->clearCache();
|
||||
}
|
||||
|
||||
public function runCommand(string $command)
|
||||
{
|
||||
$consoleCommandManager = $this->getContainer()->get('consoleCommandManager');
|
||||
return $consoleCommandManager->run($command);
|
||||
}
|
||||
|
||||
public function isInstalled()
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
52
application/Espo/Core/Console/CommandManager.php
Normal file
52
application/Espo/Core/Console/CommandManager.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console;
|
||||
|
||||
class CommandManager
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function run(string $command)
|
||||
{
|
||||
$className = '\\Espo\\Core\\Console\\Commands\\' . $command;
|
||||
if (!class_exists($className)) {
|
||||
$msg = "Command '{$command}' does not exist.";
|
||||
echo $msg . "\n";
|
||||
throw new \Espo\Core\Exceptions\Error($msg);
|
||||
}
|
||||
$impl = new $className($this->container);
|
||||
return $impl->run();
|
||||
}
|
||||
}
|
||||
56
application/Espo/Core/Console/Commands/AuthTokenCheck.php
Normal file
56
application/Espo/Core/Console/Commands/AuthTokenCheck.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
class AuthTokenCheck extends Base
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$token = isset($_SERVER['argv'][2]) ? trim($_SERVER['argv'][2]) : null;
|
||||
if (empty($token)) return;
|
||||
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$authToken = $entityManager->getRepository('AuthToken')->where([
|
||||
'token' => $token,
|
||||
'isActive' => true,
|
||||
])->findOne();
|
||||
|
||||
if (!$authToken) return;
|
||||
if (!$authToken->get('userId')) return;
|
||||
|
||||
$userId = $authToken->get('userId');
|
||||
|
||||
$user = $entityManager->getEntity('User', $userId);
|
||||
if (!$user) return;
|
||||
|
||||
return $user->id;
|
||||
}
|
||||
}
|
||||
45
application/Espo/Core/Console/Commands/Base.php
Normal file
45
application/Espo/Core/Console/Commands/Base.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
||||
39
application/Espo/Core/Console/Commands/ClearCache.php
Normal file
39
application/Espo/Core/Console/Commands/ClearCache.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
class ClearCache extends Base
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
echo "Cache has been cleared.\n";
|
||||
}
|
||||
}
|
||||
39
application/Espo/Core/Console/Commands/Rebuild.php
Normal file
39
application/Espo/Core/Console/Commands/Rebuild.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
class Rebuild extends Base
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$this->getContainer()->get('dataManager')->rebuild();
|
||||
echo "Rebuild has been done.\n";
|
||||
}
|
||||
}
|
||||
40
application/Espo/Core/Loaders/ConsoleCommandManager.php
Normal file
40
application/Espo/Core/Loaders/ConsoleCommandManager.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
class ConsoleCommandManager extends Base
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
return new \Espo\Core\Console\CommandManager(
|
||||
$this->getContainer()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class Pusher implements WampServerInterface
|
||||
|
||||
private function getUserIdByAuthToken($authToken)
|
||||
{
|
||||
return shell_exec($this->phpExecutablePath . " auth_token_check.php " . $authToken);
|
||||
return shell_exec($this->phpExecutablePath . " command.php AuthTokenCheck " . $authToken);
|
||||
}
|
||||
|
||||
protected function closeConnection(ConnectionInterface $connection)
|
||||
|
||||
@@ -27,11 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
$sapiName = php_sapi_name();
|
||||
|
||||
if (substr($sapiName, 0, 3) != 'cli') {
|
||||
die("Rebuild can be run only via CLI");
|
||||
}
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('ClearCache can be run only via CLI.');
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
|
||||
@@ -27,33 +27,19 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
ob_start();
|
||||
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') exit;
|
||||
|
||||
$token = isset($_SERVER['argv'][1]) ? trim($_SERVER['argv'][1]) : null;
|
||||
if (empty($token)) exit;
|
||||
ob_start();
|
||||
|
||||
$command = isset($_SERVER['argv'][1]) ? trim($_SERVER['argv'][1]) : null;
|
||||
if (empty($command)) exit;
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
$app = new \Espo\Core\Application();
|
||||
$entityManager = $app->getContainer()->get('entityManager');
|
||||
|
||||
$authToken = $entityManager->getRepository('AuthToken')->where([
|
||||
'token' => $token,
|
||||
'isActive' => true,
|
||||
])->findOne();
|
||||
|
||||
if (!$authToken) exit;
|
||||
if (!$authToken->get('userId')) exit;
|
||||
|
||||
$userId = $authToken->get('userId');
|
||||
|
||||
$user = $entityManager->getEntity('User', $userId);
|
||||
if (!$user) exit;
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
echo $user->id;
|
||||
$result = $app->runCommand($command);
|
||||
|
||||
if (is_string($result)) {
|
||||
ob_end_clean();
|
||||
echo $result;
|
||||
}
|
||||
exit;
|
||||
5
cron.php
5
cron.php
@@ -27,10 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
$sapiName = php_sapi_name();
|
||||
if (substr($sapiName, 0, 3) != 'cli') {
|
||||
die("Daemon can be run only via CLI");
|
||||
}
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('Cron can be run only via CLI.');
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
|
||||
@@ -27,10 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
$sapiName = php_sapi_name();
|
||||
if (substr($sapiName, 0, 3) != 'cli') {
|
||||
die("Cron can be run only via CLI");
|
||||
}
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('Daemon can be run only via CLI.');
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
@@ -27,14 +27,9 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
$sapiName = php_sapi_name();
|
||||
|
||||
if (substr($sapiName, 0, 3) != 'cli') {
|
||||
die("Rebuild can be run only via CLI");
|
||||
}
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('Rebuild can be run only via CLI.');
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
$app = new \Espo\Core\Application();
|
||||
$app->runRebuild();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('Cron can be run only via CLI');
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('WebSocket can be run only via CLI.');
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user