refactoring

This commit is contained in:
Yuri Kuznetsov
2021-09-05 16:54:24 +03:00
parent 70cc8fb9e3
commit 392748db57
7 changed files with 541 additions and 420 deletions
@@ -29,8 +29,9 @@
namespace Espo\Classes\ConsoleCommands;
use Espo\Tools\Import\Service;
use Espo\Core\{
ServiceFactory,
Console\Command,
Console\Params,
Console\IO,
@@ -40,11 +41,11 @@ use Throwable;
class Import implements Command
{
protected $serviceFactory;
private $service;
public function __construct(ServiceFactory $serviceFactory)
public function __construct(Service $service)
{
$this->serviceFactory = $serviceFactory;
$this->service = $service;
}
public function run(Params $params, IO $io) : void
@@ -56,8 +57,6 @@ class Import implements Command
$forceResume = $params->hasFlag('resume');
$revert = $params->hasFlag('revert');
$service = $this->serviceFactory->create('Import');
if (!$id && $filePath) {
if (!$paramsId) {
$io->writeLine("You need to specify --params-id option.");
@@ -74,7 +73,7 @@ class Import implements Command
$contents = file_get_contents($filePath);
try {
$result = $service->importFileWithParamsId($contents, $paramsId);
$result = $this->service->importContentsWithParamsId($contents, $paramsId);
$resultId = $result->id;
$countCreated = $result->countCreated;
@@ -95,7 +94,7 @@ class Import implements Command
$io->writeLine("Reverting import...");
try {
$service->revert($id);
$this->service->revert($id);
}
catch (Throwable $e) {
$io->writeLine("Error occurred: " . $e->getMessage() . "");
@@ -112,7 +111,7 @@ class Import implements Command
$io->writeLine("Running import, this may take a while...");
try {
$result = $service->importById($id, true, $forceResume);
$result = $this->service->importById($id, true, $forceResume);
}
catch (Throwable $e) {
$io->writeLine("Error occurred: " . $e->getMessage() . "");