ImportExecutor
in package
Live import write: walks the file in batches and orchestrates validator and writer.
- ImportValidator::begin(): code lists (id maps),
<settings>diff, run context; - per batch of BATCH_SIZE cards: ImportValidator::validateChunk() (matching in one
query + a verdict per card; rules are not duplicated, see ImportItemVerdict) →
ImportProductWriter::write() per card →
em->clear()→ callback$afterBatch(job progress + cron lock renewal); - ImportValidator::finish(): reserved tags, accessory targets, log counts.
The execute phase log (jsonl, ImportLogWriter) thus holds both the reasons of hard and
soft errors (written by the validator in the same pass) and the write results (written by the
writer).
IMPORTANT: nothing is deferred transactionally: every manager save is its own commit, so the order of writes and activation last are handled by the writer, not by this class.
stopOnError: the first hard error (blocked item or write failure) stops the run
(summary->stopped, the job ends as failed). Without it the run continues and the job ends as
done even with errors.
Code lists need no reload after em->clear(): they are id maps without entities
(ImportCodebooks); auto-created producers and categories are registered incrementally by
the writer. Target entities are loaded fresh by id in every item (writer) and never held across
a batch.
Table of Contents
Constants
- BATCH_SIZE : int = 20
- Cards per batch; the flush has already happened (every save commits), then progress and clear follow.
Properties
- $bundleWriter : ImportBundleWriter
- $unitOfWorkReset : UnitOfWorkReset
- $validator : ImportValidator
- $writer : ImportProductWriter
Methods
- __construct() : mixed
- execute() : ImportExecutionSummary
- countBlocked() : int
- hasBlockedItem() : bool
- runBatch() : void
Constants
BATCH_SIZE
Cards per batch; the flush has already happened (every save commits), then progress and clear follow.
public
int
BATCH_SIZE
= 20
Properties
$bundleWriter read-only
private
ImportBundleWriter
$bundleWriter
$unitOfWorkReset read-only
private
UnitOfWorkReset
$unitOfWorkReset
$validator read-only
private
ImportValidator
$validator
$writer read-only
private
ImportProductWriter
$writer
Methods
__construct()
public
__construct(ImportValidator $validator, ImportProductWriter $writer, ImportBundleWriter $bundleWriter, UnitOfWorkReset $unitOfWorkReset) : mixed
Parameters
- $validator : ImportValidator
- $writer : ImportProductWriter
- $bundleWriter : ImportBundleWriter
- $unitOfWorkReset : UnitOfWorkReset
execute()
public
execute(ImportDto $dto, ImportSettingsDto $settings, ImportLogWriter $log[, callable(ImportExecutionSummary): void|null $afterBatch = null ][, int|null $jobId = null ][, int|null $userId = null ][, ImportExecutionSummary|null $summary = null ]) : ImportExecutionSummary
Parameters
- $dto : ImportDto
- $settings : ImportSettingsDto
- $log : ImportLogWriter
- $afterBatch : callable(ImportExecutionSummary): void|null = null
-
called after every batch (and once at the end): job progress, lock renewal
- $jobId : int|null = null
-
job id for the note of the stock document
- $userId : int|null = null
-
job author for the stock document
- $summary : ImportExecutionSummary|null = null
-
accumulator of the caller. The worker (ProductImportManager::run()) creates it and passes it here, so that an exception anywhere inside (matching of the next batch,
em->clear(), accessories second pass, parser failure in the middle of the stream) leaves it with the accepted counts andtouchedSetIdsfor the final reindex. An exception from this method therefore does not mean nothing was written: the summary in the passed object is the true state up to the failure.
Return values
ImportExecutionSummarycountBlocked()
private
countBlocked(ImportProductVerdict $verdict) : int
Parameters
- $verdict : ImportProductVerdict
Return values
inthasBlockedItem()
private
hasBlockedItem(ImportProductVerdict $verdict) : bool
Parameters
- $verdict : ImportProductVerdict
Return values
boolrunBatch()
private
runBatch(array<int, ImportProductDto> $products, ImportExecutionContext $context, callable(ImportExecutionSummary): void|null $afterBatch) : void
Parameters
- $products : array<int, ImportProductDto>
- $context : ImportExecutionContext
- $afterBatch : callable(ImportExecutionSummary): void|null