mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
application runner refactoring
This commit is contained in:
@@ -43,6 +43,7 @@ use Espo\Core\{
|
||||
};
|
||||
|
||||
use ReflectionClass;
|
||||
use StdClass;
|
||||
|
||||
/**
|
||||
* A central access point of the application.
|
||||
@@ -68,7 +69,7 @@ class Application
|
||||
/**
|
||||
* Run a specific application runner.
|
||||
*/
|
||||
public function run(string $className, ?object $params = null)
|
||||
public function run(string $className, ?StdClass $params = null)
|
||||
{
|
||||
if (!$className || !class_exists($className)) {
|
||||
$this->getLog()->error("Application runner '{$className}' does not exist.");
|
||||
@@ -88,9 +89,11 @@ class Application
|
||||
$this->setupSystemUser();
|
||||
}
|
||||
|
||||
$runner = $this->getInjectableFactory()->create($className);
|
||||
$runner = $this->getInjectableFactory()->createWith($className, [
|
||||
'params' => $params,
|
||||
]);
|
||||
|
||||
$runner->run($params);
|
||||
$runner->run();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,4 +34,5 @@ namespace Espo\Core\ApplicationRunners;
|
||||
*/
|
||||
interface ApplicationRunner
|
||||
{
|
||||
public function run();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ use Exception;
|
||||
*/
|
||||
class EntryPoint implements ApplicationRunner
|
||||
{
|
||||
protected $params;
|
||||
|
||||
protected $injectableFactory;
|
||||
protected $entryPointManager;
|
||||
protected $entityManager;
|
||||
@@ -73,7 +75,8 @@ class EntryPoint implements ApplicationRunner
|
||||
EntityManager $entityManager,
|
||||
ClientManager $clientManager,
|
||||
ApplicationUser $applicationUser,
|
||||
AuthTokenManager $authTokenManager
|
||||
AuthTokenManager $authTokenManager,
|
||||
?StdClass $params = null
|
||||
) {
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
$this->entryPointManager = $entryPointManager;
|
||||
@@ -81,16 +84,16 @@ class EntryPoint implements ApplicationRunner
|
||||
$this->clientManager = $clientManager;
|
||||
$this->applicationUser = $applicationUser;
|
||||
$this->authTokenManager = $authTokenManager;
|
||||
|
||||
$this->params = $params ?? (object) [];
|
||||
}
|
||||
|
||||
public function run(?StdClass $params = null)
|
||||
public function run()
|
||||
{
|
||||
$params = $params ?? (object) [];
|
||||
$entryPoint = $this->params->entryPoint ?? $_GET['entryPoint'];
|
||||
|
||||
$entryPoint = $params->entryPoint ?? $_GET['entryPoint'];
|
||||
|
||||
$final = $params->final ?? false;
|
||||
$data = $params->data ?? null;
|
||||
$final = $this->params->final ?? false;
|
||||
$data = $this->params->data ?? null;
|
||||
|
||||
if (!$entryPoint) {
|
||||
throw new Error();
|
||||
|
||||
@@ -43,15 +43,19 @@ class Job implements ApplicationRunner
|
||||
use Cli;
|
||||
use SetupSystemUser;
|
||||
|
||||
protected $params;
|
||||
|
||||
protected $cronManager;
|
||||
|
||||
public function __construct(CronManager $cronManager)
|
||||
public function __construct(CronManager $cronManager, StdClass $params)
|
||||
{
|
||||
$this->cronManager = $cronManager;
|
||||
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function run(StdClass $params)
|
||||
public function run()
|
||||
{
|
||||
$this->cronManager->runJobById($params->id);
|
||||
$this->cronManager->runJobById($this->params->id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user