This commit is contained in:
Yuri Kuznetsov
2024-01-05 11:01:25 +02:00
parent 519784a7c3
commit 2d629eb0c6
3 changed files with 22 additions and 26 deletions

View File

@@ -33,12 +33,8 @@ use Espo\Core\InjectableFactory;
class ImportFactory
{
private $injectableFactory;
public function __construct(InjectableFactory $injectableFactory)
{
$this->injectableFactory = $injectableFactory;
}
public function __construct(private InjectableFactory $injectableFactory)
{}
public function create(): Import
{

View File

@@ -29,31 +29,24 @@
namespace Espo\Tools\Import\Jobs;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Job\Job;
use Espo\Core\Job\Job\Data;
use Espo\Core\Exceptions\Error;
use Espo\Tools\Import\ImportFactory;
use Espo\Tools\Import\Params as ImportParams;
use Espo\ORM\EntityManager;
use Espo\Entities\User;
class RunIdle implements Job
{
private $factory;
private $entityManager;
public function __construct(ImportFactory $factory, EntityManager $entityManager)
{
$this->factory = $factory;
$this->entityManager = $entityManager;
}
public function __construct(
private ImportFactory $factory,
private EntityManager $entityManager
) {}
/**
* @throws \Espo\Core\Exceptions\Forbidden
* @throws Forbidden
* @throws Error
*/
public function run(Data $data): void

View File

@@ -29,6 +29,7 @@
namespace Espo\Tools\Import;
use Exception;
use GuzzleHttp\Psr7\Utils as Psr7Utils;
use Espo\Core\Record\ActionHistory\Action;
@@ -84,7 +85,7 @@ class Service
}
if (!$this->acl->check($entityType, Table::ACTION_CREATE)) {
throw new Forbidden("No create access for '{$entityType}'.");
throw new Forbidden("No create access for '$entityType'.");
}
$result = $this->factory
@@ -124,7 +125,7 @@ class Service
$source = $this->entityManager->getEntityById(ImportEntity::ENTITY_TYPE, $importParamsId);
if (!$source) {
throw new Error("Import '{$importParamsId}' not found.");
throw new Error("Import '$importParamsId' not found.");
}
$entityType = $source->getTargetEntityType();
@@ -154,18 +155,18 @@ class Service
$import = $this->entityManager->getEntity(ImportEntity::ENTITY_TYPE, $id);
if (!$import) {
throw new NotFound("Import '{$id}' not found.");
throw new NotFound("Import '$id' not found.");
}
$status = $import->getStatus();
if ($status !== ImportEntity::STATUS_STANDBY) {
if (!in_array($status, [ImportEntity::STATUS_IN_PROCESS, ImportEntity::STATUS_FAILED])) {
throw new Forbidden("Can't run import with '{$status}' status.");
throw new Forbidden("Can't run import with '$status' status.");
}
if (!$forceResume) {
throw new Forbidden("Import has '{$status}' status. Use -r flag to force resume.");
throw new Forbidden("Import has '$status' status. Use -r flag to force resume.");
}
}
@@ -230,7 +231,13 @@ class Service
if ($createdAt) {
$dtNow = new DateTime();
$createdAtDt = new DateTime($createdAt);
try {
$createdAtDt = new DateTime($createdAt);
}
catch (Exception $e) {
throw new RuntimeException($e->getMessage());
}
$dayDiff = ($dtNow->getTimestamp() - $createdAtDt->getTimestamp()) / 60 / 60 / 24;
@@ -354,7 +361,7 @@ class Service
$import = $this->entityManager->getEntityById(ImportEntity::ENTITY_TYPE, $id);
if (!$import) {
throw new NotFound("Import '{$id}' not found.");
throw new NotFound("Import '$id' not found.");
}
if (!$this->acl->checkEntityDelete($import)) {