Skip to content

Commit

Permalink
Release 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-motorny-amasty committed Aug 28, 2023
1 parent f6d74ea commit ef6f4c6
Show file tree
Hide file tree
Showing 17 changed files with 860 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Api/Process/ProcessStatusInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Api\Process;

interface ProcessStatusInterface
{
public function getStatus(): string;

public function setStatus(string $status): void;

public function getProceed(): int;

public function setProceed(int $proceed): void;

public function getTotal(): int;

public function setTotal(int $total): void;

public function getMessages(): array;

public function setMessages(array $messages): void;

public function getError(): string;

public function setError(string $error): void;
}
16 changes: 16 additions & 0 deletions Api/Process/StatusCheckerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Api\Process;

interface StatusCheckerInterface
{
public function check(string $processIdentity): ProcessStatusInterface;
}
35 changes: 35 additions & 0 deletions Api/Profile/ProfileManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Api\Profile;

interface ProfileManagerInterface
{
/**
* @param string $type
* @param int $profileId
* @return \Amasty\ImportExportCore\Api\Profile\RunProfileResponseInterface
* @throws \InvalidArgumentException
*/
public function run(string $type, int $profileId): RunProfileResponseInterface;

/**
* @param string $type
* @param string $identityId
* @return \Amasty\ImportExportCore\Api\Profile\RunProfileResponseInterface
* @throws \InvalidArgumentException
*/
public function checkProfileRunStatus(string $type, string $identityId): RunProfileResponseInterface;

/**
* @return string[]
*/
public function getProfileRunnersList(): array;
}
35 changes: 35 additions & 0 deletions Api/Profile/ProfileRunnerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Api\Profile;

interface ProfileRunnerInterface
{
/**
* @param int $profileId
* @param \Closure|null $profileConfigModifier
* @return string
*/
public function run(int $profileId, \Closure $profileConfigModifier = null): string;

/**
* @param int $profileId
* @param \Closure|null $profileConfigModifier
* @return string
*/
public function manualRun(int $profileId, \Closure $profileConfigModifier = null): string;

/**
* @param int $profileId
* @param \Closure|null $profileConfigModifier
* @return \Magento\Framework\Api\ExtensibleDataInterface
*/
public function prepareProfileConfig(
int $profileId,
\Closure $profileConfigModifier = null
);
}
48 changes: 48 additions & 0 deletions Api/Profile/RunProfileResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Api\Profile;

interface RunProfileResponseInterface
{
public const STATUS_CODE = 'status_code';
public const IDENTITY = 'identity';
public const MESSAGE = 'message';

/**
* @return int|null
*/
public function getStatusCode(): ?int;

/**
* @param int|null $statusCode
* @return void
*/
public function setStatusCode(?int $statusCode): void;

/**
* @return string
*/
public function getIdentity(): string;

/**
* @param string|null $identity
* @return void
*/
public function setIdentity(?string $identity): void;

/**
* @return string
*/
public function getMessage(): string;

/**
* @param string $message
* @return void
*/
public function setMessage(string $message): void;
}
84 changes: 84 additions & 0 deletions Console/Command/CheckProfileStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Console\Command;

use Amasty\ImportExportCore\Api\Profile\ProfileManagerInterface;
use Amasty\ImportExportCore\Api\Profile\RunProfileResponseInterface;
use Amasty\ImportExportCore\Model\Cli\CliAreaFlag;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CheckProfileStatus extends Command
{
public const COMMAND_NAME = 'am-import-export:check-profile-status';
public const INPUT_KEY_TYPE = 'type';
public const INPUT_KEY_IDENTITY = 'identity';

/**
* @var ProfileManagerInterface
*/
private $profileManager;

/**
* @var CliAreaFlag
*/
private $cliAreaFlag;

public function __construct(
ProfileManagerInterface $profileManager,
CliAreaFlag $cliAreaFlag,
string $name = null
) {
parent::__construct($name);
$this->profileManager = $profileManager;
$this->cliAreaFlag = $cliAreaFlag;
}

protected function configure()
{
$this->setName(self::COMMAND_NAME)
->setDescription('Check Import/Export Profile Run Status.');

$this->addArgument(
self::INPUT_KEY_TYPE,
InputArgument::REQUIRED,
'Import/Export profile runner type'
);
$this->addArgument(
self::INPUT_KEY_IDENTITY,
InputArgument::REQUIRED,
'Identity ID'
);

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$type = $input->getArgument(self::INPUT_KEY_TYPE);
$identity = $input->getArgument(self::INPUT_KEY_IDENTITY);

$this->cliAreaFlag->setIsCliArea(true);
$response = $this->profileManager->checkProfileRunStatus($type, $identity);
$this->cliAreaFlag->setIsCliArea(false);
$output->writeln(
sprintf('%s: %d', RunProfileResponseInterface::STATUS_CODE, $response->getStatusCode())
);
$output->writeln(
sprintf('<info>%s</info>', $response->getMessage())
);

return Cli::RETURN_SUCCESS;
}
}
98 changes: 98 additions & 0 deletions Console/Command/RunProfileCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Import-Export Core for Magento 2 (System)
*/

namespace Amasty\ImportExportCore\Console\Command;

use Amasty\ImportExportCore\Api\Profile\ProfileManagerInterface;
use Amasty\ImportExportCore\Api\Profile\RunProfileResponseInterface;
use Amasty\ImportExportCore\Model\Cli\CliAreaFlag;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RunProfileCommand extends Command
{
public const COMMAND_NAME = 'am-import-export:run-profile';
public const INPUT_KEY_TYPE = 'type';
public const INPUT_KEY_PROFILE_ID = 'profile-id';

/**
* @var ProfileManagerInterface
*/
private $profileManager;

/**
* @var CliAreaFlag
*/
private $cliAreaFlag;

public function __construct(
ProfileManagerInterface $profileManager,
CliAreaFlag $cliAreaFlag,
string $name = null
) {
parent::__construct($name);
$this->profileManager = $profileManager;
$this->cliAreaFlag = $cliAreaFlag;
}

protected function configure()
{
$this->setName(self::COMMAND_NAME)
->setDescription('Run Import/Export Profile.');

$this->addArgument(
self::INPUT_KEY_TYPE,
InputArgument::REQUIRED,
'Import/Export profile runner type'
);
$this->addArgument(
self::INPUT_KEY_PROFILE_ID,
InputArgument::REQUIRED,
'Profile ID'
);

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$type = $input->getArgument(self::INPUT_KEY_TYPE);
$profileId = (int) $input->getArgument(self::INPUT_KEY_PROFILE_ID);

$this->cliAreaFlag->setIsCliArea(true);
$response = $this->profileManager->run($type, $profileId);
$this->cliAreaFlag->setIsCliArea(false);

$output->writeln(
sprintf('%s: %d', RunProfileResponseInterface::STATUS_CODE, $response->getStatusCode())
);
$output->writeln(
sprintf('%s: %s', RunProfileResponseInterface::MESSAGE, $response->getMessage())
);
if ($response->getIdentity()) {
$output->writeln(
sprintf('%s: %s', RunProfileResponseInterface::IDENTITY, $response->getIdentity())
);
$output->writeln(
sprintf(
'<comment>You can watch process status by using "%s %s %s" command</comment>',
CheckProfileStatus::COMMAND_NAME,
$type,
$response->getIdentity()
)
);
}

return Cli::RETURN_SUCCESS;
}
}
Loading

0 comments on commit ef6f4c6

Please sign in to comment.