From 83781eb7fac9b4bea6bc39dd3831f712f1802591 Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Fri, 2 Aug 2024 15:58:58 +0200 Subject: [PATCH] feat: import export bundle --- .../src/lib/Workflow/AbstractWorkflow.php | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/components/ImportExportBundle/src/lib/Workflow/AbstractWorkflow.php b/components/ImportExportBundle/src/lib/Workflow/AbstractWorkflow.php index ac7c01d1d..7d18d89d1 100644 --- a/components/ImportExportBundle/src/lib/Workflow/AbstractWorkflow.php +++ b/components/ImportExportBundle/src/lib/Workflow/AbstractWorkflow.php @@ -30,7 +30,7 @@ abstract class AbstractWorkflow implements WorkflowInterface protected ?int $totalItemsCount = null; protected int $offset = 0; protected float $progress = 0; - protected bool $debug = true; + protected bool $debug = false; public function __construct(ReferenceBag $references) { @@ -92,22 +92,7 @@ public function __invoke(int $batchLimit = -1): void foreach ($limitIterator as $index => $item) { $this->logger->setItemIndex($index + 1); $this->referenceBag->resetScope(Reference::SCOPE_ITEM); - try { - foreach ($this->configuration->getProcessors() as $processor) { - $processResult = ($processor)($item); - if (false === $processResult) { - continue 2; - } - if (null !== $processResult) { - $item = $processResult; - } - } - } catch (Throwable $e) { - if ($this->debug) { - throw $e; - } - $this->logger->logException($e); - } + $this->processItem($item); ++$this->offset; $this->dispatchEvent(new WorkflowEvent($this), WorkflowEvent::PROGRESS); } @@ -180,4 +165,27 @@ public function setDebug(bool $debug): void { $this->debug = $debug; } + + /** + * @throws \Throwable + */ + protected function processItem($item): void + { + try { + foreach ($this->configuration->getProcessors() as $processor) { + $processResult = ($processor)($item); + if (false === $processResult) { + return; + } + if (null !== $processResult) { + $item = $processResult; + } + } + } catch (Throwable $procesItemException) { + if ($this->debug) { + throw $procesItemException; + } + $this->logger->logException($procesItemException); + } + } }