-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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\Category\CategoryPayload; | ||
use Synolia\SyliusAkeneoPlugin\Task\Category\BatchCategoriesTask; | ||
|
||
final class BatchImportCategoriesCommand extends AbstractBatchCommand | ||
{ | ||
protected static $defaultDescription = 'Import batch categories ids from Akeneo PIM.'; | ||
|
||
/** @var string */ | ||
protected static $defaultName = 'akeneo:batch:categories'; | ||
|
||
public function __construct( | ||
private ClientFactoryInterface $clientFactory, | ||
private LoggerInterface $logger, | ||
private BatchCategoriesTask $task, | ||
) { | ||
parent::__construct(self::$defaultName); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute( | ||
InputInterface $input, | ||
OutputInterface $output, | ||
) { | ||
$ids = explode(',', $input->getArgument('ids')); | ||
Check failure on line 36 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 36 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 36 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 6.2.*
|
||
|
||
$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]); | ||
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]); | ||
|
||
$payload = new CategoryPayload($this->clientFactory->createFromApiCredentials()); | ||
$payload->setIds($ids); | ||
|
||
$this->task->__invoke($payload); | ||
Check failure on line 44 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 44 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 44 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 6.2.*
Check failure on line 44 in src/Command/BatchImportCategoriesCommand.php GitHub Actions / PHP 8.2 Symfony 6.2.*
|
||
|
||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Message\Batch; | ||
|
||
class CategoryBatchMessage implements BatchMessageInterface | ||
{ | ||
public function __construct(public array $items) | ||
{ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\MessageHandler\Batch; | ||
|
||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
use Synolia\SyliusAkeneoPlugin\Message\Batch\CategoryBatchMessage; | ||
use Synolia\SyliusAkeneoPlugin\Processor\Resource\Category\CategoryResourceProcessor; | ||
use Synolia\SyliusAkeneoPlugin\Processor\Resource\Exception\MaxResourceProcessorRetryException; | ||
|
||
#[AsMessageHandler] | ||
class CategoryBatchMessageHandler | ||
{ | ||
public function __construct( | ||
private EventDispatcherInterface $dispatcher, | ||
private CategoryResourceProcessor $resourceProcessor, | ||
) { | ||
} | ||
|
||
public function __invoke(CategoryBatchMessage $attributeBatchMessage): void | ||
{ | ||
foreach ($attributeBatchMessage->items as $resource) { | ||
try { | ||
$this->resourceProcessor->process($resource); | ||
} catch (MaxResourceProcessorRetryException) { | ||
// Skip the failing line | ||
$this->dispatcher->dispatch(new CategoryBatchMessage([$resource])); | ||
|
||
continue; | ||
} | ||
} | ||
} | ||
} |