Skip to content

Commit

Permalink
feat: import export bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian ALEXANDRE committed Aug 2, 2024
1 parent 12338af commit 83781eb
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions components/ImportExportBundle/src/lib/Workflow/AbstractWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 83781eb

Please sign in to comment.