-
Notifications
You must be signed in to change notification settings - Fork 25
feat: apply fixes prototype #63
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
Merged
DennisGarding
merged 18 commits into
feature/migration-logging-refactor
from
12365/apply-fixes-prototype
Oct 31, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d6f73ba
Merge branch 'trunk' of github.com:shopware/SwagMigrationAssistant in…
DennisGarding 3cf6d32
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding 728553c
chore: implement apply fixes prototype
DennisGarding 650a3d5
Fix cs and phpstan
DennisGarding cb33d55
Fix tests
DennisGarding 98ed05f
fix typo
DennisGarding 6182e21
break down to essentials
DennisGarding 862ca02
Fix test
DennisGarding 2fb9bdb
Merge branch 'feature/migration-logging-refactor' into 12365/apply-fi…
DennisGarding d7cf096
Remove not existing phpstan rule
DennisGarding 263de3d
Add migration fix applier to the write process
DennisGarding afe2c8b
Fix test
DennisGarding a504dda
Fix test
DennisGarding 92d1806
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding 3a54fc4
Change using new table name
DennisGarding 92da70f
fix cs
DennisGarding 8ad18df
Add comment and rename variable
DennisGarding 2016099
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding 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
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
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,84 @@ | ||
| <?php declare(strict_types=1); | ||
| /* | ||
| * (c) shopware AG <[email protected]> | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace SwagMigrationAssistant\Migration\Writer\MigrationFix; | ||
|
|
||
| use Shopware\Core\Framework\Log\Package; | ||
| use Shopware\Core\Framework\Uuid\Uuid; | ||
| use SwagMigrationAssistant\Exception\MigrationException; | ||
|
|
||
| #[Package('after-sales')] | ||
| class MigrationFix | ||
| { | ||
| private const PATH_SEPARATOR = '.'; | ||
|
|
||
| public function __construct( | ||
| public readonly string $id, | ||
| public readonly string $value, | ||
| public readonly string $path, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string, string> $data | ||
| */ | ||
| public static function fromDatabaseQuery(array $data): self | ||
| { | ||
| $expectedArrayKeys = ['id', 'value', 'path']; | ||
| foreach ($expectedArrayKeys as $expectedKey) { | ||
| if (!\array_key_exists($expectedKey, $data)) { | ||
| throw MigrationException::couldNotConvertFix($expectedKey); | ||
| } | ||
| } | ||
|
|
||
| return new self( | ||
| Uuid::fromBytesToHex($data['id']), | ||
| $data['value'], | ||
| $data['path'], | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string|int, mixed> $item | ||
| */ | ||
| public function apply(array &$item): void | ||
| { | ||
| /* | ||
| * Explode the path to an array | ||
| * Path example: 'category.language.name' | ||
| * Results in an array like: ['category', 'language', 'name'] | ||
| */ | ||
| $pathArray = explode(self::PATH_SEPARATOR, $this->path); | ||
|
|
||
| /* | ||
| * Set current item as pointer | ||
| * Item structure for example has no valid value for name and looks like: | ||
| * [ | ||
| * 'someOtherKeys', | ||
| * ... | ||
| * category => [ | ||
| * ... | ||
| * 'language' => [ | ||
| * ... | ||
| * 'name' => null, | ||
| * ] | ||
| * ] | ||
| * ] | ||
| */ | ||
| $nestedPointer = &$item; | ||
|
|
||
| // Iterating over the path to follow them and set the nested pointer to the last key in pathArray | ||
| // In this example the result pointer is: $item['category']['language']['name'] | ||
| foreach ($pathArray as $key) { | ||
| $nestedPointer = &$nestedPointer[$key]; | ||
| } | ||
|
|
||
| // Now set the value to the pointer like: $item['category']['language']['name'] = 'new Value' | ||
| $nestedPointer = \json_decode($this->value, true, 512, \JSON_THROW_ON_ERROR); | ||
| unset($nestedPointer); | ||
| } | ||
| } |
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,83 @@ | ||
| <?php declare(strict_types=1); | ||
| /* | ||
| * (c) shopware AG <[email protected]> | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace SwagMigrationAssistant\Migration\Writer\MigrationFix; | ||
|
|
||
| use Doctrine\DBAL\ArrayParameterType; | ||
| use Doctrine\DBAL\Connection; | ||
| use Shopware\Core\Framework\Log\Package; | ||
| use Shopware\Core\Framework\Uuid\Uuid; | ||
|
|
||
| #[Package('after-sales')] | ||
| class MigrationFixApplier | ||
| { | ||
| public function __construct( | ||
| private readonly Connection $connection, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int|string, array<int|string, mixed>> $data | ||
| */ | ||
| public function apply(array &$data, string $connectionId): void | ||
| { | ||
| $itemIds = \array_column($data, 'id'); | ||
| $fixes = $this->getMappings($itemIds, $connectionId); | ||
|
|
||
| foreach ($data as &$item) { | ||
| $id = $item['id']; | ||
|
|
||
| if (!\array_key_exists($id, $fixes) || !\is_array($fixes[$id])) { | ||
| continue; | ||
| } | ||
|
|
||
| foreach ($fixes[$id] as $fix) { | ||
| $fix->apply($item); | ||
| } | ||
| } | ||
|
|
||
| unset($item); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int, string> $ids | ||
| * | ||
| * @return array<string, list<MigrationFix>> | ||
| */ | ||
| private function getMappings(array $ids, string $connectionId): array | ||
| { | ||
| $sql = <<<'SQL' | ||
| SELECT mapping.entity_uuid as entityId, fix.id, fix.value, fix.path FROM swag_migration_mapping as mapping | ||
| INNER JOIN swag_migration_fix as fix ON fix.main_mapping_id = mapping.id | ||
| WHERE mapping.entity_uuid IN (:ids) | ||
| AND mapping.connection_id = :connectionId | ||
| SQL; | ||
|
|
||
| $result = $this->connection->fetchAllAssociative( | ||
| $sql, | ||
| [ | ||
| 'ids' => Uuid::fromHexToBytesList($ids), | ||
| 'connectionId' => Uuid::fromHexToBytes($connectionId), | ||
| ], | ||
| [ | ||
| 'ids' => ArrayParameterType::STRING, | ||
| ] | ||
| ); | ||
|
|
||
| $return = []; | ||
| foreach ($result as $row) { | ||
| $entityUuid = Uuid::fromBytesToHex($row['entityId']); | ||
| if (!\array_key_exists($entityUuid, $return)) { | ||
| $return[$entityUuid] = []; | ||
| } | ||
|
|
||
| $return[$entityUuid][] = MigrationFix::fromDatabaseQuery($row); | ||
| } | ||
|
|
||
| return $return; | ||
| } | ||
| } | ||
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.