Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d6f73ba
Merge branch 'trunk' of github.com:shopware/SwagMigrationAssistant in…
DennisGarding Sep 23, 2025
3cf6d32
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Sep 24, 2025
5ad6e0a
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 23, 2025
0bc9d86
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 28, 2025
be1132a
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 31, 2025
fe40fa5
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 31, 2025
73e7c29
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Nov 3, 2025
71e3bc8
Chore: Adjust swag_migration_fix table.
DennisGarding Nov 5, 2025
173e9e1
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Nov 6, 2025
a446a3b
Chore: Adjust swag_migration_mapping
DennisGarding Nov 6, 2025
460a5b6
fix cs
DennisGarding Nov 6, 2025
8cda6be
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Nov 7, 2025
65a7137
remove debug code
DennisGarding Nov 7, 2025
6fe88d3
Fix plugin uninstall
DennisGarding Nov 7, 2025
37c88a2
Remove strange files
DennisGarding Nov 7, 2025
5f7b1af
Fix tests
DennisGarding Nov 7, 2025
fe90e0b
fix: remove comment
larskemper Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Migration1757598733AddMigrationFixesTable extends MigrationStep
'main_mapping_id' => 'BINARY(16) NOT NULL',
'value' => 'JSON NOT NULL',
'path' => 'VARCHAR(255) NOT NULL',
'entity_name' => 'VARCHAR(255) NULL',
'entity_id' => 'BINARY(16) NULL',
'created_at' => 'DATETIME(3) NOT NULL',
'updated_at' => 'DATETIME(3) NULL',
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Core\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Migration\ColumnExistsTrait;
use Shopware\Core\Framework\Migration\MigrationStep;

/**
* @internal
*/
#[Package('after-sales')]
class Migration1762346793RenameColumnOfMappingTable extends MigrationStep
{
use ColumnExistsTrait;

public function getCreationTimestamp(): int
{
return 1762346793;
}

public function update(Connection $connection): void
{
if ($this->columnExists($connection, 'swag_migration_mapping', 'entity_id')) {
return;
}

if (!$this->columnExists($connection, 'swag_migration_mapping', 'entity_uuid')) {
return;
}

$connection->executeStatement('ALTER TABLE `swag_migration_mapping` CHANGE `entity_uuid` `entity_id` BINARY(16)');
}
}
2 changes: 1 addition & 1 deletion src/Migration/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class Converter implements ConverterInterface
protected LoggingServiceInterface $loggingService;

/**
* @var ?array{id: string, connectionId: string, oldIdentifier: ?string, entityUuid: ?string, entityValue: ?string, checksum: ?string, additionalData: ?array<mixed>}
* @var ?array{id: string, connectionId: string, oldIdentifier: ?string, entityId: ?string, entityValue: ?string, checksum: ?string, additionalData: ?array<mixed>}
*/
protected ?array $mainMapping = null;

Expand Down
52 changes: 26 additions & 26 deletions src/Migration/Mapping/MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getOrCreateMapping(
}

if ($uuid !== null) {
$mapping['entityUuid'] = $uuid;
$mapping['entityId'] = $uuid;
}

if ($entityValue !== null) {
Expand Down Expand Up @@ -120,7 +120,7 @@ public function getMapping(
connection_id AS connectionId,
entity,
old_identifier AS oldIdentifier,
entity_uuid AS entityUuid,
entity_id AS entityId,
entity_value AS entityValue,
checksum,
additional_data AS additionalData
Expand All @@ -135,7 +135,7 @@ public function getMapping(

$mapping['id'] = Uuid::fromBytesToHex($mapping['id']);
$mapping['connectionId'] = Uuid::fromBytesToHex($mapping['connectionId']);
$mapping['entityUuid'] = $mapping['entityUuid'] === null ? null : Uuid::fromBytesToHex($mapping['entityUuid']);
$mapping['entityId'] = $mapping['entityId'] === null ? null : Uuid::fromBytesToHex($mapping['entityId']);
if (!empty($mapping['additionalData'])) {
$mapping['additionalData'] = \json_decode($mapping['additionalData'], true, 512, \JSON_THROW_ON_ERROR);
} else {
Expand All @@ -161,14 +161,14 @@ public function createMapping(
?string $uuid = null,
?string $entityValue = null,
): array {
$fallbackEntityUuid = $entityValue !== null ? null : Uuid::randomHex();
$fallbackEntityId = $entityValue !== null ? null : Uuid::randomHex();

$mapping = [
'id' => Uuid::randomHex(),
'connectionId' => $connectionId,
'entity' => $entityName,
'oldIdentifier' => $oldIdentifier,
'entityUuid' => $uuid ?? $fallbackEntityUuid,
'entityId' => $uuid ?? $fallbackEntityId,
'entityValue' => $entityValue,
'checksum' => $checksum,
'additionalData' => $additionalData,
Expand All @@ -194,7 +194,7 @@ public function updateMapping(
$oldIdentifier,
$updateData['checksum'] ?? null,
$updateData['additionalData'] ?? null,
$updateData['entityUuid'] ?? null
$updateData['entityId'] ?? null
);
}

Expand All @@ -214,13 +214,13 @@ public function getMappings(string $connectionId, string $entityName, array $ids
return $this->migrationMappingRepo->search($criteria, $context);
}

public function hasValidMappingByEntityUuid(string $connectionId, string $entityName, string $entityUuid, Context $context): bool
public function hasValidMappingByEntityUuid(string $connectionId, string $entityName, string $entityId, Context $context): bool
{
$criteria = new Criteria();
$criteria->addFilter(
new EqualsFilter('connectionId', $connectionId),
new EqualsFilter('entity', $entityName),
new EqualsFilter('entityUuid', $entityUuid),
new EqualsFilter('entityId', $entityId),
new NotFilter(MultiFilter::CONNECTION_AND, [
new EqualsFilter('oldIdentifier', null),
]),
Expand Down Expand Up @@ -248,7 +248,7 @@ public function preloadMappings(array $mappingIds, Context $context): void
'connectionId' => $mapping->getConnectionId(),
'entity' => $entityName,
'oldIdentifier' => $oldIdentifier,
'entityUuid' => $mapping->getEntityUuid(),
'entityId' => $mapping->getEntityId(),
'entityValue' => $mapping->getEntityValue(),
'checksum' => $mapping->getChecksum(),
'additionalData' => $mapping->getAdditionalData(),
Expand All @@ -266,12 +266,12 @@ public function getUuidsByEntity(string $connectionId, string $entityName, Conte

$entities = $this->migrationMappingRepo->search($criteria, $context)->getEntities();

$entityUuids = [];
$entityIds = [];
foreach ($entities as $entity) {
$entityUuids[] = $entity->getEntityUuid();
$entityIds[] = $entity->getEntityId();
}

return $entityUuids;
return $entityIds;
}

public function getValue(string $connectionId, string $entityName, string $oldIdentifier, Context $context): ?string
Expand Down Expand Up @@ -303,7 +303,7 @@ public function getValue(string $connectionId, string $entityName, string $oldId
'connectionId' => $element->getConnectionId(),
'entity' => $element->getEntity(),
'oldIdentifier' => $element->getOldIdentifier(),
'entityUuid' => $element->getEntityUuid(),
'entityId' => $element->getEntityId(),
'entityValue' => $value,
'checksum' => $element->getChecksum(),
'additionalData' => $element->getAdditionalData(),
Expand All @@ -316,10 +316,10 @@ public function getValue(string $connectionId, string $entityName, string $oldId
return null;
}

public function deleteMapping(string $entityUuid, string $connectionId, Context $context): void
public function deleteMapping(string $entityId, string $connectionId, Context $context): void
{
foreach ($this->writeArray as $key => $writeMapping) {
if ($writeMapping['connectionId'] === $connectionId && $writeMapping['entityUuid'] === $entityUuid) {
if ($writeMapping['connectionId'] === $connectionId && $writeMapping['entityId'] === $entityId) {
unset($this->writeArray[$key]);
$this->writeArray = \array_values($this->writeArray);

Expand All @@ -328,13 +328,13 @@ public function deleteMapping(string $entityUuid, string $connectionId, Context
}

foreach ($this->mappings as $hash => $mapping) {
if (isset($mapping['entityUuid']) && $mapping['entityUuid'] === $entityUuid) {
if (isset($mapping['entityId']) && $mapping['entityId'] === $entityId) {
unset($this->mappings[$hash]);
}
}

$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('entityUuid', $entityUuid));
$criteria->addFilter(new EqualsFilter('entityId', $entityId));
$criteria->addFilter(new EqualsFilter('connectionId', $connectionId));
$criteria->setLimit(1);

Expand All @@ -353,12 +353,12 @@ public function writeMapping(): void

try {
$isFirstInsert = true;
$insertSql = 'INSERT INTO swag_migration_mapping (id, connection_id, entity, old_identifier, entity_uuid, entity_value, checksum, additional_data, created_at) VALUES ';
$insertSql = 'INSERT INTO swag_migration_mapping (id, connection_id, entity, old_identifier, entity_id, entity_value, checksum, additional_data, created_at) VALUES ';
$insertParams = [];
$updateSql = ' ON DUPLICATE KEY
UPDATE entity = VALUES(entity),
old_identifier = VALUES(old_identifier),
entity_uuid = VALUES(entity_uuid),
entity_id = VALUES(entity_id),
entity_value = VALUES(entity_value),
checksum = VALUES(checksum),
additional_data = VALUES(additional_data),
Expand All @@ -370,13 +370,13 @@ public function writeMapping(): void
$insertSql .= ', ';
}

$insertSql .= \sprintf('(:id%d, :connectionId%d, :entity%d, :oldIdentifier%d, :entityUuid%d, :entityValue%d, :checksum%d, :additionalData%d, :createdAt%d)', $index, $index, $index, $index, $index, $index, $index, $index, $index);
$insertSql .= \sprintf('(:id%d, :connectionId%d, :entity%d, :oldIdentifier%d, :entityId%d, :entityValue%d, :checksum%d, :additionalData%d, :createdAt%d)', $index, $index, $index, $index, $index, $index, $index, $index, $index);

$insertParams['id' . $index] = Uuid::fromHexToBytes($writeMapping['id']);
$insertParams['connectionId' . $index] = Uuid::fromHexToBytes($writeMapping['connectionId']);
$insertParams['entity' . $index] = $writeMapping['entity'];
$insertParams['oldIdentifier' . $index] = $writeMapping['oldIdentifier'];
$insertParams['entityUuid' . $index] = $writeMapping['entityUuid'] === null ? null : Uuid::fromHexToBytes($writeMapping['entityUuid']);
$insertParams['entityId' . $index] = $writeMapping['entityId'] === null ? null : Uuid::fromHexToBytes($writeMapping['entityId']);
$insertParams['entityValue' . $index] = $writeMapping['entityValue'];
$insertParams['checksum' . $index] = $writeMapping['checksum'];
$insertParams['additionalData' . $index] = \json_encode($writeMapping['additionalData']);
Expand Down Expand Up @@ -408,7 +408,7 @@ public function getMigratedSalesChannelUuids(string $connectionId, Context $cont

$uuids = [];
foreach ($result as $swagMigrationMappingEntity) {
$uuid = $swagMigrationMappingEntity->getEntityUuid();
$uuid = $swagMigrationMappingEntity->getEntityId();

if ($uuid === null) {
continue;
Expand Down Expand Up @@ -441,12 +441,12 @@ private function writePerEntry(): void
{
foreach ($this->writeArray as $mapping) {
try {
$insertSql = 'INSERT INTO swag_migration_mapping (id, connection_id, entity, old_identifier, entity_uuid, entity_value, checksum, additional_data, created_at)
VALUES (:id, :connectionId, :entity, :oldIdentifier, :entityUuid, :entityValue, :checksum, :additionalData, :createdAt)
$insertSql = 'INSERT INTO swag_migration_mapping (id, connection_id, entity, old_identifier, entity_id, entity_value, checksum, additional_data, created_at)
VALUES (:id, :connectionId, :entity, :oldIdentifier, :entityId, :entityValue, :checksum, :additionalData, :createdAt)
ON DUPLICATE KEY
UPDATE entity = VALUES(entity),
old_identifier = VALUES(old_identifier),
entity_uuid = VALUES(entity_uuid),
entity_id = VALUES(entity_id),
entity_value = VALUES(entity_value),
checksum = VALUES(checksum),
additional_data = VALUES(additional_data),
Expand All @@ -457,7 +457,7 @@ private function writePerEntry(): void
$insertParams['connectionId'] = Uuid::fromHexToBytes($mapping['connectionId']);
$insertParams['entity'] = $mapping['entity'];
$insertParams['oldIdentifier'] = $mapping['oldIdentifier'];
$insertParams['entityUuid'] = $mapping['entityUuid'] === null ? null : Uuid::fromHexToBytes($mapping['entityUuid']);
$insertParams['entityId'] = $mapping['entityId'] === null ? null : Uuid::fromHexToBytes($mapping['entityId']);
$insertParams['entityValue'] = $mapping['entityValue'];
$insertParams['checksum'] = $mapping['checksum'];
$insertParams['additionalData'] = \json_encode($mapping['additionalData']);
Expand Down
6 changes: 3 additions & 3 deletions src/Migration/Mapping/MappingServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Shopware\Core\Framework\Log\Package;

/**
* @phpstan-type MappingStruct array{id: string, connectionId: string, oldIdentifier: ?string, entityUuid: ?string, entityValue: ?string, checksum: ?string, additionalData: ?array<mixed>}
* @phpstan-type MappingStruct array{id: string, connectionId: string, oldIdentifier: ?string, entityId: ?string, entityValue: ?string, checksum: ?string, additionalData: ?array<mixed>}
*/
#[Package('fundamentals@after-sales')]
interface MappingServiceInterface
Expand Down Expand Up @@ -75,7 +75,7 @@ public function updateMapping(
*/
public function getMigratedSalesChannelUuids(string $connectionId, Context $context): array;

public function deleteMapping(string $entityUuid, string $connectionId, Context $context): void;
public function deleteMapping(string $entityId, string $connectionId, Context $context): void;

public function writeMapping(): void;

Expand All @@ -84,7 +84,7 @@ public function writeMapping(): void;
*/
public function getMappings(string $connectionId, string $entityName, array $ids, Context $context): EntitySearchResult;

public function hasValidMappingByEntityUuid(string $connectionId, string $entityName, string $entityUuid, Context $context): bool;
public function hasValidMappingByEntityUuid(string $connectionId, string $entityName, string $entityId, Context $context): bool;

public function preloadMappings(array $mappingIds, Context $context): void;
}
2 changes: 1 addition & 1 deletion src/Migration/Mapping/SwagMigrationMappingDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function defineFields(): FieldCollection
(new FkField('connection_id', 'connectionId', SwagMigrationConnectionDefinition::class))->addFlags(new Required()),
(new StringField('entity', 'entity'))->addFlags(new Required()),
new StringField('old_identifier', 'oldIdentifier'),
new IdField('entity_uuid', 'entityUuid'),
new IdField('entity_id', 'entityId'),
new StringField('entity_value', 'entityValue'),
new StringField('checksum', 'checksum'),
new JsonField('additional_data', 'additionalData'),
Expand Down
10 changes: 5 additions & 5 deletions src/Migration/Mapping/SwagMigrationMappingEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SwagMigrationMappingEntity extends Entity

protected ?string $oldIdentifier;

protected ?string $entityUuid;
protected ?string $entityId;

protected ?string $entityValue;

Expand Down Expand Up @@ -76,14 +76,14 @@ public function setOldIdentifier(string $oldIdentifier): void
$this->oldIdentifier = $oldIdentifier;
}

public function getEntityUuid(): ?string
public function getEntityId(): ?string
{
return $this->entityUuid;
return $this->entityId;
}

public function setEntityUuid(string $entityUuid): void
public function setEntityId(string $entityId): void
{
$this->entityUuid = $entityUuid;
$this->entityId = $entityId;
}

public function getEntityValue(): ?string
Expand Down
12 changes: 6 additions & 6 deletions src/Migration/Writer/MigrationFix/MigrationFixApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function apply(array &$data, string $connectionId): void
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
SELECT mapping.entity_id 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)
WHERE mapping.entity_id IN (:ids)
AND mapping.connection_id = :connectionId
SQL;

Expand All @@ -70,12 +70,12 @@ private function getMappings(array $ids, string $connectionId): array

$return = [];
foreach ($result as $row) {
$entityUuid = Uuid::fromBytesToHex($row['entityId']);
if (!\array_key_exists($entityUuid, $return)) {
$return[$entityUuid] = [];
$entityId = Uuid::fromBytesToHex($row['entityId']);
if (!\array_key_exists($entityId, $return)) {
$return[$entityId] = [];
}

$return[$entityUuid][] = MigrationFix::fromDatabaseQuery($row);
$return[$entityId][] = MigrationFix::fromDatabaseQuery($row);
}

return $return;
Expand Down
6 changes: 3 additions & 3 deletions src/Profile/Shopware/Converter/AttributeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function convert(array $data, Context $context, MigrationContextInterface
$this->getCustomFieldEntityName() . 'CustomFieldSet',
$context
);
$converted['id'] = $mapping['entityUuid'];
$converted['id'] = $mapping['entityId'];
$this->mappingIds[] = $mapping['id'];

$connectionName = ConnectionNameSanitizer::sanitize($this->connectionName);
Expand All @@ -70,7 +70,7 @@ public function convert(array $data, Context $context, MigrationContextInterface

$converted['relations'] = [
[
'id' => $mapping['entityUuid'],
'id' => $mapping['entityId'],
'entityName' => $this->getCustomFieldEntityName(),
],
];
Expand All @@ -91,7 +91,7 @@ public function convert(array $data, Context $context, MigrationContextInterface

$converted['customFields'] = [
[
'id' => $this->mainMapping['entityUuid'],
'id' => $this->mainMapping['entityId'],
'name' => $converted['name'] . '_' . $data['name'],
'type' => $this->getCustomFieldType($data),
'config' => $this->getCustomFieldConfiguration($data),
Expand Down
Loading
Loading