-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from synolia/feature/added-missing-batch-asse…
…t-command added missing batch assets command
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Command; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Synolia\SyliusAkeneoPlugin\Client\ClientFactoryInterface; | ||
use Synolia\SyliusAkeneoPlugin\Payload\Asset\AssetPayload; | ||
use Synolia\SyliusAkeneoPlugin\Task\Asset\BatchAssetTask; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class BatchImportAssetsCommand extends AbstractBatchCommand | ||
{ | ||
protected static $defaultDescription = 'Import batch assets ids from Akeneo PIM.'; | ||
|
||
/** @var string */ | ||
public static $defaultName = 'akeneo:batch:assets'; | ||
|
||
public function __construct( | ||
private ClientFactoryInterface $clientFactory, | ||
private LoggerInterface $logger, | ||
private BatchAssetTask $batchAssetTask, | ||
) { | ||
parent::__construct(self::$defaultName); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute( | ||
InputInterface $input, | ||
OutputInterface $output, | ||
) { | ||
Assert::string($input->getArgument('ids')); | ||
$ids = explode(',', $input->getArgument('ids')); | ||
|
||
$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]); | ||
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]); | ||
|
||
$batchPayload = new AssetPayload($this->clientFactory->createFromApiCredentials()); | ||
$batchPayload->setIds($ids); | ||
|
||
$this->batchAssetTask->__invoke($batchPayload); | ||
|
||
return 0; | ||
} | ||
} |