Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed Jan 5, 2024
1 parent 519784a commit 2d629eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
8 changes: 2 additions & 6 deletions application/Espo/Tools/Import/ImportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@

class ImportFactory
{
private $injectableFactory;

public function __construct(InjectableFactory $injectableFactory)
{
$this->injectableFactory = $injectableFactory;
}
public function __construct(private InjectableFactory $injectableFactory)
{}

public function create(): Import
{
Expand Down
19 changes: 6 additions & 13 deletions application/Espo/Tools/Import/Jobs/RunIdle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions application/Espo/Tools/Import/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

namespace Espo\Tools\Import;

use Exception;
use GuzzleHttp\Psr7\Utils as Psr7Utils;

use Espo\Core\Record\ActionHistory\Action;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function import(
}

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
Expand Down Expand Up @@ -124,7 +125,7 @@ public function importContentsWithParamsId(string $contents, string $importParam
$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();
Expand Down Expand Up @@ -154,18 +155,18 @@ public function importById(string $id, bool $startFromLastIndex = false, bool $f
$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.");
}
}

Expand Down Expand Up @@ -230,7 +231,13 @@ public function revert(string $id): void

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;

Expand Down Expand Up @@ -354,7 +361,7 @@ public function removeDuplicates(string $id): void
$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)) {
Expand Down

0 comments on commit 2d629eb

Please sign in to comment.