mirror of
https://github.com/espocrm/espocrm.git
synced 2026-03-03 03:57:01 +00:00
app runners refactoring
This commit is contained in:
@@ -29,4 +29,9 @@
|
||||
|
||||
require_once('../../bootstrap.php');
|
||||
|
||||
(new \Espo\Core\Application())->run('api');
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Api,
|
||||
};
|
||||
|
||||
(new Application())->run(Api::class);
|
||||
|
||||
@@ -29,10 +29,15 @@
|
||||
|
||||
require_once('../../../bootstrap.php');
|
||||
|
||||
use Espo\Core\{
|
||||
Portal\Application,
|
||||
Portal\ApplicationRunners\Api,
|
||||
};
|
||||
|
||||
if (!empty($_GET['portalId'])) {
|
||||
$portalId = $_GET['portalId'];
|
||||
} else {
|
||||
$portalId = explode('/', $_SERVER['REQUEST_URI'])[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
|
||||
}
|
||||
|
||||
(new \Espo\Core\Portal\Application($portalId))->run('api');
|
||||
(new Application($portalId))->run(Api::class);
|
||||
|
||||
@@ -78,15 +78,13 @@ class Application
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an application through a specific runner.
|
||||
* You can find runner classes in `Espo\Core\ApplicationRunners`.
|
||||
* Run a specific application runner.
|
||||
* You can find runner classes at `Espo\Core\ApplicationRunners`.
|
||||
*/
|
||||
public function run(string $runnerName, ?object $params = null)
|
||||
public function run(string $className, ?object $params = null)
|
||||
{
|
||||
$className = $this->getRunnerClassName($runnerName);
|
||||
|
||||
if (!$className) {
|
||||
$this->getLog()->error("Application runner '{$runnerName}' does not exist.");
|
||||
$this->getLog()->error("Application runner '{$className}' does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -94,9 +92,10 @@ class Application
|
||||
|
||||
if ($class->getStaticPropertyValue('cli', false)) {
|
||||
if (substr(php_sapi_name(), 0, 3) !== 'cli') {
|
||||
die("Application runner '{$runnerName}' can be run only via CLI.");
|
||||
die("Can be run only via CLI.");
|
||||
}
|
||||
}
|
||||
|
||||
if ($class->getStaticPropertyValue('setupSystemUser', false)) {
|
||||
$this->setupSystemUser();
|
||||
}
|
||||
@@ -106,20 +105,6 @@ class Application
|
||||
$runner->run($params);
|
||||
}
|
||||
|
||||
protected function getRunnerClassName(string $runnerName) : ?string
|
||||
{
|
||||
$className = 'Espo\\Core\\ApplicationRunners\\' . ucfirst($runnerName);
|
||||
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->getMetadata()->get(['app', 'runners', $runnerName, 'className']);
|
||||
if (!$className || !class_exists($className)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an application is installed.
|
||||
*/
|
||||
|
||||
@@ -99,7 +99,7 @@ class EntryPoint implements ApplicationRunner
|
||||
if ($portalId = $this->detectPortalId()) {
|
||||
$app = new PortalApplication($portalId);
|
||||
$app->setClientBasePath($this->clientManager->getBasePath());
|
||||
$app->run('entryPoint', (object) [
|
||||
$app->run(EntryPoint::class, (object) [
|
||||
'entryPoint' => $entryPoint,
|
||||
'data' => $data,
|
||||
'final' => true,
|
||||
|
||||
@@ -94,17 +94,6 @@ class Application extends BaseApplication
|
||||
return $this->portal;
|
||||
}
|
||||
|
||||
protected function getRunnerClassName(string $runnerName) : ?string
|
||||
{
|
||||
$className = 'Espo\\Core\\Portal\\ApplicationRunners\\' . ucfirst($runnerName);
|
||||
|
||||
if (class_exists($className)) {
|
||||
return $className;
|
||||
}
|
||||
|
||||
return parent::getRunnerClassName($runnerName);
|
||||
}
|
||||
|
||||
protected function initPreloads()
|
||||
{
|
||||
parent::initPreloads();
|
||||
|
||||
@@ -29,9 +29,14 @@
|
||||
|
||||
namespace Espo\Core\Utils\Cron;
|
||||
|
||||
use Espo\Core\Application;
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Job as JobRunner,
|
||||
};
|
||||
|
||||
class JobTask extends \Spatie\Async\Task
|
||||
use Spatie\Async\Task as AsyncTask;
|
||||
|
||||
class JobTask extends AsyncTask
|
||||
{
|
||||
private $jobId;
|
||||
|
||||
@@ -48,7 +53,7 @@ class JobTask extends \Spatie\Async\Task
|
||||
{
|
||||
$app = new Application();
|
||||
try {
|
||||
$app->run('job', (object) [
|
||||
$app->run(JobRunner::class, (object) [
|
||||
'id' => $this->jobId,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
@@ -40,6 +40,7 @@ use Espo\Core\{
|
||||
Utils\ClientManager,
|
||||
Utils\Config,
|
||||
Portal\Application as PortalApplication,
|
||||
Portal\ApplicationRunners\Client,
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
};
|
||||
@@ -84,6 +85,6 @@ class Portal implements EntryPoint
|
||||
|
||||
$application = new PortalApplication($id);
|
||||
$application->setClientBasePath($this->clientManager->getBasePath());
|
||||
$application->run('client');
|
||||
$application->run(Client::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
["app", "templateHelpers"],
|
||||
["app", "appParams"],
|
||||
["app", "cleanup"],
|
||||
["app", "runners"],
|
||||
["app", "auth2FAMethods", "__ANY__", "implementationClassName"],
|
||||
["app", "auth2FAMethods", "__ANY__", "implementationUserClassName"],
|
||||
["authenticationMethods", "__ANY__", "implementationClassName"]
|
||||
|
||||
@@ -29,4 +29,9 @@
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
(new \Espo\Core\Application())->run('clearCache');
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\ClearCache,
|
||||
};
|
||||
|
||||
(new Application())->run(ClearCache::class);
|
||||
|
||||
@@ -29,9 +29,14 @@
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Command,
|
||||
};
|
||||
|
||||
ob_start();
|
||||
|
||||
$result = (new \Espo\Core\Application())->run('command');
|
||||
$result = (new Application())->run(Command::class);
|
||||
|
||||
if (is_string($result)) {
|
||||
ob_end_clean();
|
||||
|
||||
7
cron.php
7
cron.php
@@ -29,4 +29,9 @@
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
(new \Espo\Core\Application())->run('cron');
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Cron,
|
||||
};
|
||||
|
||||
(new Application())->run(Cron::class);
|
||||
|
||||
@@ -29,4 +29,9 @@
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
(new \Espo\Core\Application())->run('daemon');
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Daemon,
|
||||
};
|
||||
|
||||
(new Application())->run(Daemon::class);
|
||||
|
||||
12
index.php
12
index.php
@@ -29,7 +29,13 @@
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
$app = new \Espo\Core\Application();
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Client,
|
||||
ApplicationRunners\EntryPoint,
|
||||
};
|
||||
|
||||
$app = new Application();
|
||||
|
||||
if (!$app->isInstalled()) {
|
||||
header("Location: install/");
|
||||
@@ -37,8 +43,8 @@ if (!$app->isInstalled()) {
|
||||
}
|
||||
|
||||
if (!empty($_GET['entryPoint'])) {
|
||||
$app->run('entryPoint');
|
||||
$app->run(EntryPoint::class);
|
||||
exit;
|
||||
}
|
||||
|
||||
$app->run('client');
|
||||
$app->run(Client::class);
|
||||
|
||||
@@ -29,7 +29,12 @@
|
||||
|
||||
include "../bootstrap.php";
|
||||
|
||||
$app = new \Espo\Core\Application();
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\EntryPoint,
|
||||
};
|
||||
|
||||
$app = new Application();
|
||||
if (!$app->isInstalled()) {
|
||||
exit;
|
||||
}
|
||||
@@ -70,10 +75,10 @@ if (strpos($requestUri, '/') !== false) {
|
||||
}
|
||||
|
||||
if (!empty($_GET['entryPoint'])) {
|
||||
$app->run('entryPoint');
|
||||
$app->run(EntryPoint::class);
|
||||
exit;
|
||||
}
|
||||
|
||||
$app->run('entryPoint', (object) [
|
||||
$app->run(EntryPoint::class, (object) [
|
||||
'entryPoint' => 'portal',
|
||||
]);
|
||||
|
||||
@@ -29,4 +29,9 @@
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
(new \Espo\Core\Application())->run('rebuild');
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Rebuild,
|
||||
};
|
||||
|
||||
(new Application())->run(Rebuild::class);
|
||||
|
||||
Reference in New Issue
Block a user