-
Notifications
You must be signed in to change notification settings - Fork 67
Add interpretation-stage events: PreInterpretFileEvent and PreQueueRowEvent #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexbaat
wants to merge
3
commits into
pimcore:2026.x
Choose a base branch
from
alexbaat:improvement/interpreter-stage-events
base: 2026.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This source file is available under the terms of the | ||
| * Pimcore Open Core License (POCL) | ||
| * Full copyright and license information is available in | ||
| * LICENSE.md which is distributed with this source code. | ||
| * | ||
| * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) | ||
| * @license Pimcore Open Core License (POCL) | ||
| */ | ||
|
|
||
| namespace Pimcore\Bundle\DataImporterBundle\Event; | ||
|
|
||
| use Symfony\Contracts\EventDispatcher\Event; | ||
|
|
||
| /** | ||
| * Dispatched before an interpreter starts reading the source file, both for real imports | ||
| * and for the Studio preview. Listeners may replace the file path, e.g. to normalize the | ||
| * file (transcode, strip a report preamble, rewrite delimiters) without replacing the | ||
| * interpreter. Stateful PreQueueRowEvent listeners can also use it as a per-run reset signal. | ||
| */ | ||
| final class PreInterpretFileEvent extends Event | ||
| { | ||
| public function __construct( | ||
| private readonly string $configName, | ||
| private readonly string $executionType, | ||
| private string $path, | ||
| private readonly bool $preview = false, | ||
| ) { | ||
| } | ||
|
|
||
| public function getConfigName(): string | ||
| { | ||
| return $this->configName; | ||
| } | ||
|
|
||
| public function getExecutionType(): string | ||
| { | ||
| return $this->executionType; | ||
| } | ||
|
|
||
| public function getPath(): string | ||
| { | ||
| return $this->path; | ||
| } | ||
|
|
||
| public function setPath(string $path): self | ||
| { | ||
| $this->path = $path; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * True when the file is being read for the Studio preview instead of an actual import. | ||
| */ | ||
| public function isPreview(): bool | ||
| { | ||
| return $this->preview; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This source file is available under the terms of the | ||
| * Pimcore Open Core License (POCL) | ||
| * Full copyright and license information is available in | ||
| * LICENSE.md which is distributed with this source code. | ||
| * | ||
| * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) | ||
| * @license Pimcore Open Core License (POCL) | ||
| */ | ||
|
|
||
| namespace Pimcore\Bundle\DataImporterBundle\Event; | ||
|
|
||
| use Symfony\Contracts\EventDispatcher\Event; | ||
|
|
||
| /** | ||
| * Dispatched for every row an interpreter extracted from the source file, right before the | ||
| * row is added to the processing queue. Listeners can modify the row, skip it, or fan it | ||
| * out into multiple rows (each queued and imported as its own element): | ||
| * | ||
| * - modify: $event->setRows([$changedRow]); | ||
| * - skip: $event->skipRow(); or $event->setRows([]); | ||
| * - fan-out: $event->setRows([$rowA, $rowB, $rowC]); | ||
| * | ||
| * When an import uses an active cleanup strategy, every element whose identifier is not seen | ||
| * during interpretation gets deleted or unpublished. Skipping a row therefore makes the | ||
| * cleanup treat the row's existing element as removed from the source. Use | ||
| * $event->skipRow(keepInCleanupIdentifierCache: true) to skip the row but still register its | ||
| * identifier, so the existing element is left untouched. | ||
| * | ||
| * The same event is dispatched (with isPreview() returning true) when the Studio preview | ||
| * renders the source columns, so columns added by listeners are visible and mappable in the | ||
| * configuration UI. Rows skipped in preview mode are still displayed unmodified. | ||
| */ | ||
| final class PreQueueRowEvent extends Event | ||
| { | ||
| /** | ||
| * @var array<int, array> | ||
| */ | ||
| private array $rows; | ||
|
|
||
| private bool $keepSkippedRowInIdentifierCache = false; | ||
|
|
||
| public function __construct( | ||
| private readonly string $configName, | ||
| private readonly string $executionType, | ||
| private readonly array $originalRow, | ||
| private readonly bool $preview = false, | ||
| ) { | ||
| $this->rows = [$originalRow]; | ||
| } | ||
|
|
||
| public function getConfigName(): string | ||
| { | ||
| return $this->configName; | ||
| } | ||
|
|
||
| public function getExecutionType(): string | ||
| { | ||
| return $this->executionType; | ||
| } | ||
|
|
||
| /** | ||
| * The row as the interpreter extracted it, unaffected by any listener. | ||
| */ | ||
| public function getOriginalRow(): array | ||
| { | ||
| return $this->originalRow; | ||
| } | ||
|
|
||
| /** | ||
| * The rows that will be queued. Initially exactly the original row. | ||
| * | ||
| * @return array<int, array> | ||
| */ | ||
| public function getRows(): array | ||
| { | ||
| return $this->rows; | ||
| } | ||
|
|
||
| /** | ||
| * Replace the rows to queue: one row to modify, an empty array to skip, | ||
| * multiple rows to fan the source row out into multiple elements. | ||
| * | ||
| * @param array<int, array> $rows | ||
| */ | ||
| public function setRows(array $rows): self | ||
| { | ||
| $this->rows = array_values($rows); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Skip this row entirely. With $keepInCleanupIdentifierCache set to true the original | ||
| * row's identifier is still registered, so an active cleanup strategy does not treat the | ||
| * row's existing element as removed from the source. | ||
| */ | ||
| public function skipRow(bool $keepInCleanupIdentifierCache = false): self | ||
| { | ||
| $this->rows = []; | ||
| $this->keepSkippedRowInIdentifierCache = $keepInCleanupIdentifierCache; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function isRowSkipped(): bool | ||
| { | ||
| return $this->rows === []; | ||
| } | ||
|
|
||
| public function shouldKeepSkippedRowInIdentifierCache(): bool | ||
| { | ||
| return $this->keepSkippedRowInIdentifierCache; | ||
| } | ||
|
|
||
| /** | ||
| * True when the row is being read for the Studio preview instead of an actual import. | ||
| */ | ||
| public function isPreview(): bool | ||
| { | ||
| return $this->preview; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.