Skip to content

Commit

Permalink
Merge pull request #180 from synolia/feature/added-missing-batch-asse…
Browse files Browse the repository at this point in the history
…t-command

added missing batch assets command
  • Loading branch information
TheGrimmChester authored Dec 26, 2023
2 parents 5609a7e + 828ef4b commit d7f5fa5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Command/BatchImportAssetsCommand.php
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;
}
}

0 comments on commit d7f5fa5

Please sign in to comment.