-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6d74ea
commit ef6f4c6
Showing
17 changed files
with
860 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.