-
Notifications
You must be signed in to change notification settings - Fork 25
refactor!: migration connection usage #43
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
refactor!: migration connection usage #43
Conversation
diff --git c/phpstan.neon.dist i/phpstan.neon.dist index cfb461f..6eba37f 100644 --- c/phpstan.neon.dist +++ i/phpstan.neon.dist @@ -54,16 +54,6 @@ parameters: paths: - tests/**/*Test.php - - # TODO remove with #11883 - message: '#Strict comparison using === between SwagMigrationAssistant\\Migration\\Connection\\SwagMigrationConnectionEntity and null will always evaluate to false\.#' - paths: - - **/*.php - - - # TODO remove with #11883 - message: '#Strict comparison using !== between SwagMigrationAssistant\\Migration\\Connection\\SwagMigrationConnectionEntity and null will always evaluate to true\.#' - paths: - - **/*.php - rules: # Shopware core rules - Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Deprecation\DeprecatedMethodsThrowDeprecationRule diff --git c/src/Exception/MigrationException.php i/src/Exception/MigrationException.php index c45b3b6..8cf4a07 100644 --- c/src/Exception/MigrationException.php +++ i/src/Exception/MigrationException.php @@ -53,7 +53,6 @@ class MigrationException extends HttpException public const INVALID_FIELD_SERIALIZER = 'SWAG_MIGRATION__INVALID_FIELD_SERIALIZER'; public const INVALID_CONNECTION_AUTHENTICATION = 'SWAG_MIGRATION__INVALID_CONNECTION_AUTHENTICATION'; - public const INVALID_CONNECTION_CREDENTIALS = 'SWAG_MIGRATION__INVALID_CONNECTION_CREDENTIALS'; public const SSL_REQUIRED = 'SWAG_MIGRATION__SSL_REQUIRED'; diff --git c/src/Migration/Converter/Converter.php i/src/Migration/Converter/Converter.php index 5c4ee2c..c5460de 100644 --- c/src/Migration/Converter/Converter.php +++ i/src/Migration/Converter/Converter.php @@ -76,7 +76,8 @@ abstract class Converter implements ConverterInterface $dataSet = $migrationContext->getDataSet(); $connection = $migrationContext->getConnection(); - if ($dataSet === null || $connection === null) { + + if ($dataSet === null) { return; } diff --git c/src/Migration/Converter/ConverterRegistry.php i/src/Migration/Converter/ConverterRegistry.php index 77a3288..86a11f6 100644 --- c/src/Migration/Converter/ConverterRegistry.php +++ i/src/Migration/Converter/ConverterRegistry.php @@ -33,11 +33,6 @@ class ConverterRegistry implements ConverterRegistryInterface } } - $connection = $migrationContext->getConnection(); - if ($connection === null) { - throw MigrationException::migrationContextPropertyMissing('Connection'); - } - - throw MigrationException::converterNotFound($connection->getProfileName()); + throw MigrationException::converterNotFound($migrationContext->getProfile()->getName()); } } diff --git c/src/Migration/Gateway/GatewayRegistry.php i/src/Migration/Gateway/GatewayRegistry.php index e6c209d..87074ed 100644 --- c/src/Migration/Gateway/GatewayRegistry.php +++ i/src/Migration/Gateway/GatewayRegistry.php @@ -40,11 +40,6 @@ class GatewayRegistry implements GatewayRegistryInterface public function getGateway(MigrationContextInterface $migrationContext): GatewayInterface { $connection = $migrationContext->getConnection(); - - if ($connection === null) { - throw MigrationException::migrationContextPropertyMissing('Connection'); - } - $profileName = $connection->getProfileName(); $gatewayName = $connection->getGatewayName(); diff --git c/src/Migration/Media/MediaFileProcessorRegistry.php i/src/Migration/Media/MediaFileProcessorRegistry.php index eb2cd77..44b431f 100644 --- c/src/Migration/Media/MediaFileProcessorRegistry.php +++ i/src/Migration/Media/MediaFileProcessorRegistry.php @@ -9,7 +9,6 @@ namespace SwagMigrationAssistant\Migration\Media; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Exception\MigrationException; -use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity; use SwagMigrationAssistant\Migration\MigrationContextInterface; #[Package('fundamentals@after-sales')] @@ -34,10 +33,10 @@ class MediaFileProcessorRegistry implements MediaFileProcessorRegistryInterface } $connection = $migrationContext->getConnection(); - if ($connection === null) { - throw MigrationException::entityNotExists(SwagMigrationConnectionEntity::class, $migrationContext->getRunUuid()); - } - throw MigrationException::processorNotFound($connection->getProfileName(), $connection->getGatewayName()); + throw MigrationException::processorNotFound( + $connection->getProfileName(), + $connection->getGatewayName() + ); } } diff --git c/src/Migration/MessageQueue/Handler/Processor/AbortingProcessor.php i/src/Migration/MessageQueue/Handler/Processor/AbortingProcessor.php index 467a4c4..bf2a177 100644 --- c/src/Migration/MessageQueue/Handler/Processor/AbortingProcessor.php +++ i/src/Migration/MessageQueue/Handler/Processor/AbortingProcessor.php @@ -10,7 +10,6 @@ namespace SwagMigrationAssistant\Migration\MessageQueue\Handler\Processor; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Log\Package; -use SwagMigrationAssistant\Exception\MigrationException; use SwagMigrationAssistant\Migration\Data\SwagMigrationDataCollection; use SwagMigrationAssistant\Migration\Media\SwagMigrationMediaFileCollection; use SwagMigrationAssistant\Migration\MessageQueue\Message\MigrationProcessMessage; @@ -59,10 +58,6 @@ class AbortingProcessor extends AbstractProcessor MigrationProgress $progress, ): void { $connection = $migrationContext->getConnection(); - if ($connection === null) { - throw MigrationException::noConnectionFound(); - } - $this->runService->cleanupMappingChecksums($connection->getId(), $context); $this->runTransitionService->forceTransitionToRunStep($migrationContext->getRunUuid(), MigrationStep::CLEANUP); diff --git c/src/Migration/Premapping/AbstractPremappingReader.php i/src/Migration/Premapping/AbstractPremappingReader.php index a659af9..fdf173c 100644 --- c/src/Migration/Premapping/AbstractPremappingReader.php +++ i/src/Migration/Premapping/AbstractPremappingReader.php @@ -20,12 +20,8 @@ abstract class AbstractPremappingReader implements PremappingReaderInterface protected function fillConnectionPremappingDictionary(MigrationContextInterface $migrationContext): void { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return; - } + $connectionMapping = $migrationContext->getConnection()->getPremapping(); - $connectionMapping = $connection->getPremapping(); if ($connectionMapping === null) { return; } diff --git c/src/Migration/Service/MigrationDataConverter.php i/src/Migration/Service/MigrationDataConverter.php index 62a0479..12383cd 100644 --- c/src/Migration/Service/MigrationDataConverter.php +++ i/src/Migration/Service/MigrationDataConverter.php @@ -143,14 +143,13 @@ class MigrationDataConverter implements MigrationDataConverterInterface $checksums[$converter->getSourceIdentifier($dataSet)] = \md5(\serialize($dataSet)); } - $connection = $migrationContext->getConnection(); $dataSet = $migrationContext->getDataSet(); - if ($connection === null || $dataSet === null) { + if ($dataSet === null) { return new MappingDeltaResult(); } - $connectionId = $connection->getId(); + $connectionId = $migrationContext->getConnection()->getId(); $entity = $dataSet::getEntity(); $result = $this->mappingService->getMappings($connectionId, $entity, \array_keys($checksums), $context); diff --git c/src/Migration/Service/MigrationDataWriter.php i/src/Migration/Service/MigrationDataWriter.php index 4ed4c23..a0f003e 100644 --- c/src/Migration/Service/MigrationDataWriter.php +++ i/src/Migration/Service/MigrationDataWriter.php @@ -129,9 +129,9 @@ class MigrationDataWriter implements MigrationDataWriterInterface $migrationContext, $context ); - } catch (\Throwable $exception) { + } catch (\Throwable) { // Worst case: something unknown goes wrong (most likely some foreign key constraint that fails) - $this->writePerEntity($converted, $dataSet::getEntity(), $updateWrittenData, $migrationContext, $context); + $this->writePerEntity($converted, $dataSet::getEntity(), $updateWrittenData, $migrationContext); } finally { // Update written-Flag of the entity in the data table $this->entityWriter->update( @@ -196,7 +196,7 @@ class MigrationDataWriter implements MigrationDataWriterInterface try { $currentWriter->writeData($newData, $this->writeContext); } catch (\Throwable) { - $this->writePerEntity($converted, $entityName, $updateWrittenData, $migrationContext, $context); + $this->writePerEntity($converted, $entityName, $updateWrittenData, $migrationContext); } } @@ -228,7 +228,6 @@ class MigrationDataWriter implements MigrationDataWriterInterface string $entityName, array &$updateWrittenData, MigrationContextInterface $migrationContext, - Context $context, ): void { foreach ($converted as $dataId => $entity) { try { diff --git c/src/Migration/Service/PremappingService.php i/src/Migration/Service/PremappingService.php index 71d5a6f..fb34741 100644 --- c/src/Migration/Service/PremappingService.php +++ i/src/Migration/Service/PremappingService.php @@ -68,10 +68,6 @@ class PremappingService implements PremappingServiceInterface $connection = $migrationContext->getConnection(); - if ($connection === null) { - return; - } - foreach ($premapping as $item) { $entity = $item['entity']; @@ -118,13 +114,8 @@ class PremappingService implements PremappingServiceInterface */ private function updateConnectionPremapping(Context $context, MigrationContextInterface $migrationContext, array $premapping): void { - $premapping = $this->updateConnectionPremappingStruct($migrationContext, $premapping); - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - return; - } + $premapping = $this->updateConnectionPremappingStruct($migrationContext, $premapping); $this->connectionRepo->update( [ @@ -144,13 +135,7 @@ class PremappingService implements PremappingServiceInterface */ private function updateConnectionPremappingStruct(MigrationContextInterface $migrationContext, array $premapping): array { - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - return []; - } - - $connectionPremapping = $connection->getPremapping(); + $connectionPremapping = $migrationContext->getConnection()->getPremapping(); if ($connectionPremapping === null) { $connectionPremapping = []; diff --git c/src/Profile/Shopware/Converter/AttributeConverter.php i/src/Profile/Shopware/Converter/AttributeConverter.php index 6293016..c1025b6 100644 --- c/src/Profile/Shopware/Converter/AttributeConverter.php +++ i/src/Profile/Shopware/Converter/AttributeConverter.php @@ -39,12 +39,8 @@ abstract class AttributeConverter extends Converter $converted = []; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - $this->connectionName = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); $mapping = $this->mappingService->getOrCreateMapping( $this->connectionId, diff --git c/src/Profile/Shopware/Converter/CategoryConverter.php i/src/Profile/Shopware/Converter/CategoryConverter.php index e26fea2..6ce1008 100644 --- c/src/Profile/Shopware/Converter/CategoryConverter.php +++ i/src/Profile/Shopware/Converter/CategoryConverter.php @@ -81,12 +81,8 @@ abstract class CategoryConverter extends ShopwareConverter $this->migrationContext = $migrationContext; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - $this->connectionName = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); if (!isset($data['_locale'])) { $this->loggingService->addLogEntry( // TODO: add optional fields diff --git c/src/Profile/Shopware/Converter/CrossSellingConverter.php i/src/Profile/Shopware/Converter/CrossSellingConverter.php index e1df855..a662768 100644 --- c/src/Profile/Shopware/Converter/CrossSellingConverter.php +++ i/src/Profile/Shopware/Converter/CrossSellingConverter.php @@ -36,10 +36,7 @@ abstract class CrossSellingConverter extends ShopwareConverter $this->runId = $migrationContext->getRunUuid(); $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( diff --git c/src/Profile/Shopware/Converter/CurrencyConverter.php i/src/Profile/Shopware/Converter/CurrencyConverter.php index 46fb4df..37244e2 100644 --- c/src/Profile/Shopware/Converter/CurrencyConverter.php +++ i/src/Profile/Shopware/Converter/CurrencyConverter.php @@ -47,10 +47,7 @@ abstract class CurrencyConverter extends ShopwareConverter $this->mainLocale = $data['_locale']; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $currencyUuid = $this->currencyLookup->get($data['currency'], $context); if ($currencyUuid !== null) { diff --git c/src/Profile/Shopware/Converter/CustomerConverter.php i/src/Profile/Shopware/Converter/CustomerConverter.php index eb54715..4663eac 100644 --- c/src/Profile/Shopware/Converter/CustomerConverter.php +++ i/src/Profile/Shopware/Converter/CustomerConverter.php @@ -101,12 +101,8 @@ abstract class CustomerConverter extends ShopwareConverter $this->migrationContext = $migrationContext; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - $this->connectionName = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); diff --git c/src/Profile/Shopware/Converter/CustomerGroupConverter.php i/src/Profile/Shopware/Converter/CustomerGroupConverter.php index b77dcc1..53506e0 100644 --- c/src/Profile/Shopware/Converter/CustomerGroupConverter.php +++ i/src/Profile/Shopware/Converter/CustomerGroupConverter.php @@ -44,12 +44,8 @@ abstract class CustomerGroupConverter extends ShopwareConverter unset($data['_locale']); $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - $this->connectionName = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); $this->mainMapping = $this->mappingService->getOrCreateMapping( $this->connectionId, diff --git c/src/Profile/Shopware/Converter/CustomerWishlistConverter.php i/src/Profile/Shopware/Converter/CustomerWishlistConverter.php index 516cb3d..a19ff0a 100644 --- c/src/Profile/Shopware/Converter/CustomerWishlistConverter.php +++ i/src/Profile/Shopware/Converter/CustomerWishlistConverter.php @@ -27,10 +27,7 @@ abstract class CustomerWishlistConverter extends ShopwareConverter $this->migrationContext = $migrationContext; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $this->mainMapping = $this->mappingService->getOrCreateMapping( $this->connectionId, diff --git c/src/Profile/Shopware/Converter/LanguageConverter.php i/src/Profile/Shopware/Converter/LanguageConverter.php index eba545d..0482206 100644 --- c/src/Profile/Shopware/Converter/LanguageConverter.php +++ i/src/Profile/Shopware/Converter/LanguageConverter.php @@ -46,10 +46,7 @@ abstract class LanguageConverter extends ShopwareConverter $this->context = $context; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $languageUuid = $this->languageLookup->get($data['locale'], $context); if ($languageUuid !== null) { diff --git c/src/Profile/Shopware/Converter/MainVariantRelationConverter.php i/src/Profile/Shopware/Converter/MainVariantRelationConverter.php index ced4000..f76cd71 100644 --- c/src/Profile/Shopware/Converter/MainVariantRelationConverter.php +++ i/src/Profile/Shopware/Converter/MainVariantRelationConverter.php @@ -32,9 +32,7 @@ abstract class MainVariantRelationConverter extends ShopwareConverter $this->generateChecksum($data); $this->context = $context; $connection = $migrationContext->getConnection(); - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); if (!isset($data['id'], $data['ordernumber'])) { return new ConvertStruct(null, $data); diff --git c/src/Profile/Shopware/Converter/MediaConverter.php i/src/Profile/Shopware/Converter/MediaConverter.php index c728518..d6b2e9c 100644 --- c/src/Profile/Shopware/Converter/MediaConverter.php +++ i/src/Profile/Shopware/Converter/MediaConverter.php @@ -57,10 +57,7 @@ abstract class MediaConverter extends ShopwareConverter unset($data['_locale']); $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( diff --git c/src/Profile/Shopware/Converter/MediaFolderConverter.php i/src/Profile/Shopware/Converter/MediaFolderConverter.php index 30b4bdb..d7cc789 100644 --- c/src/Profile/Shopware/Converter/MediaFolderConverter.php +++ i/src/Profile/Shopware/Converter/MediaFolderConverter.php @@ -50,10 +50,7 @@ abstract class MediaFolderConverter extends ShopwareConverter unset($data['_locale']); $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( diff --git c/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php i/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php index 8e755c1..32fc233 100644 --- c/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php +++ i/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php @@ -57,10 +57,7 @@ abstract class NewsletterRecipientConverter extends ShopwareConverter MigrationContextInterface $migrationContext, ): ConvertStruct { $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $this->runId = $migrationContext->getRunUuid(); $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); diff --git c/src/Profile/Shopware/Converter/NumberRangeConverter.php i/src/Profile/Shopware/Converter/NumberRangeConverter.php index 9f75f02..48e3e41 100644 --- c/src/Profile/Shopware/Converter/NumberRangeConverter.php +++ i/src/Profile/Shopware/Converter/NumberRangeConverter.php @@ -69,9 +69,6 @@ abstract class NumberRangeConverter extends ShopwareConverter } $connection = $migrationContext->getConnection(); - if ($connection === null) { - return new ConvertStruct(null, $data); - } $this->connectionId = $connection->getId(); if (!\array_key_exists($data['name'], self::TYPE_MAPPING)) { diff --git c/src/Profile/Shopware/Converter/OrderConverter.php i/src/Profile/Shopware/Converter/OrderConverter.php index bf83762..3a852bc 100644 --- c/src/Profile/Shopware/Converter/OrderConverter.php +++ i/src/Profile/Shopware/Converter/OrderConverter.php @@ -120,12 +120,8 @@ abstract class OrderConverter extends ShopwareConverter $this->migrationContext = $migrationContext; $connection = $migrationContext->getConnection(); - $this->connectionName = ''; - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); if (empty($data['billingaddress']['id'])) { diff --git c/src/Profile/Shopware/Converter/OrderDocumentConverter.php i/src/Profile/Shopware/Converter/OrderDocumentConverter.php index 9745d38..7f1cdc6 100644 --- c/src/Profile/Shopware/Converter/OrderDocumentConverter.php +++ i/src/Profile/Shopware/Converter/OrderDocumentConverter.php @@ -73,12 +73,8 @@ abstract class OrderDocumentConverter extends ShopwareConverter $this->context = $context; $connection = $migrationContext->getConnection(); - $this->connectionName = ''; - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); $oldData = $data; $converted = []; diff --git c/src/Profile/Shopware/Converter/ProductConverter.php i/src/Profile/Shopware/Converter/ProductConverter.php index 7827133..f361f85 100644 --- c/src/Profile/Shopware/Converter/ProductConverter.php +++ i/src/Profile/Shopware/Converter/ProductConverter.php @@ -138,12 +138,8 @@ abstract class ProductConverter extends ShopwareConverter $this->locale = $data['_locale']; $connection = $migrationContext->getConnection(); - $this->connectionName = ''; - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - $this->connectionName = $connection->getName(); - } + $this->connectionId = $connection->getId(); + $this->connectionName = $connection->getName(); $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); if (!empty($fields)) { diff --git c/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php i/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php index 587823a..411860f 100644 --- c/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php +++ i/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php @@ -34,10 +34,7 @@ abstract class ProductOptionRelationConverter extends ShopwareConverter $this->originalData = $data; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $productContainerMapping = $this->mappingService->getMapping( $this->connectionId, diff --git c/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php i/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php index e1b2509..5573706 100644 --- c/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php +++ i/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php @@ -37,10 +37,7 @@ abstract class ProductPropertyRelationConverter extends ShopwareConverter $this->originalData = $data; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $productMapping = $this->mappingService->getMapping( $this->connectionId, diff --git c/src/Profile/Shopware/Converter/PromotionConverter.php i/src/Profile/Shopware/Converter/PromotionConverter.php index 54bf3cc..6e68c4b 100644 --- c/src/Profile/Shopware/Converter/PromotionConverter.php +++ i/src/Profile/Shopware/Converter/PromotionConverter.php @@ -57,10 +57,7 @@ abstract class PromotionConverter extends ShopwareConverter $this->context = $context; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( diff --git c/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php i/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php index 97586f0..f1f1210 100644 --- c/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php +++ i/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php @@ -73,10 +73,7 @@ abstract class PropertyGroupOptionConverter extends ShopwareConverter $this->runId = $migrationContext->getRunUuid(); $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); if (!isset($data['group']['name'])) { $this->loggingService->addLogEntry( // TODO: add optional fields diff --git c/src/Profile/Shopware/Converter/SalesChannelConverter.php i/src/Profile/Shopware/Converter/SalesChannelConverter.php index 4232a65..1e911f6 100644 --- c/src/Profile/Shopware/Converter/SalesChannelConverter.php +++ i/src/Profile/Shopware/Converter/SalesChannelConverter.php @@ -72,10 +72,7 @@ abstract class SalesChannelConverter extends ShopwareConverter $this->oldIdentifier = $data['id']; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( diff --git c/src/Profile/Shopware/Converter/SeoUrlConverter.php i/src/Profile/Shopware/Converter/SeoUrlConverter.php index 3f4099a..565a5c6 100644 --- c/src/Profile/Shopware/Converter/SeoUrlConverter.php +++ i/src/Profile/Shopware/Converter/SeoUrlConverter.php @@ -44,10 +44,7 @@ abstract class SeoUrlConverter extends ShopwareConverter $originalData = $data; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( diff --git c/src/Profile/Shopware/Converter/ShippingMethodConverter.php i/src/Profile/Shopware/Converter/ShippingMethodConverter.php index 1ed8e79..0c71b8c 100644 --- c/src/Profile/Shopware/Converter/ShippingMethodConverter.php +++ i/src/Profile/Shopware/Converter/ShippingMethodConverter.php @@ -90,10 +90,7 @@ abstract class ShippingMethodConverter extends ShopwareConverter public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct { $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); if (empty($data['id'])) { $this->loggingService->addLogEntry( // TODO: add optional fields diff --git c/src/Profile/Shopware/Converter/ShopwareConverter.php i/src/Profile/Shopware/Converter/ShopwareConverter.php index e01821c..b4766d2 100644 --- c/src/Profile/Shopware/Converter/ShopwareConverter.php +++ i/src/Profile/Shopware/Converter/ShopwareConverter.php @@ -148,7 +148,7 @@ abstract class ShopwareConverter extends Converter } $connection = $this->migrationContext->getConnection(); - if ($context !== null && $connection !== null) { + if ($context !== null) { $connectionId = $connection->getId(); $mapping = $this->mappingService->getMapping( $connectionId, diff --git c/src/Profile/Shopware/Converter/TranslationConverter.php i/src/Profile/Shopware/Converter/TranslationConverter.php index ed7d728..abe5d81 100644 --- c/src/Profile/Shopware/Converter/TranslationConverter.php +++ i/src/Profile/Shopware/Converter/TranslationConverter.php @@ -57,10 +57,7 @@ abstract class TranslationConverter extends ShopwareConverter $this->runId = $migrationContext->getRunUuid(); $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); if (!isset($data['locale'])) { $this->loggingService->addLogEntry( // TODO: add optional fields @@ -850,12 +847,11 @@ abstract class TranslationConverter extends ShopwareConverter */ protected function addAttribute(string $entityName, string $key, string $value, array &$translation, array &$objectData): void { - $connection = $this->migrationContext->getConnection(); - - if ($connection === null || $value === '') { + if ($value === '') { return; } + $connection = $this->migrationContext->getConnection(); $connectionName = ConnectionNameSanitizer::sanitize($connection->getName()); $isAttribute = \mb_strpos($key, '__attribute_'); @@ -909,7 +905,7 @@ abstract class TranslationConverter extends ShopwareConverter try { $objectData = \unserialize($objectDataSerialized, ['allowed_classes' => false]); - } catch (\Throwable $error) { + } catch (\Throwable) { $objectData = null; } diff --git c/src/Profile/Shopware/Gateway/Api/ShopwareApiGateway.php i/src/Profile/Shopware/Gateway/Api/ShopwareApiGateway.php index 3ed1fec..cf5dcf0 100644 --- c/src/Profile/Shopware/Gateway/Api/ShopwareApiGateway.php +++ i/src/Profile/Shopware/Gateway/Api/ShopwareApiGateway.php @@ -125,21 +125,7 @@ class ShopwareApiGateway implements ShopwareGatewayInterface $environmentDataArray['defaultShopLanguage'] = \str_replace('_', '-', $environmentDataArray['defaultShopLanguage']); $totals = $this->readTotals($migrationContext, $context); - - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - return new EnvironmentInformation( - $profile->getSourceSystemName(), - $profile->getVersion(), - '', - [], - [], - null - ); - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { return new EnvironmentInformation( diff --git c/src/Profile/Shopware/Gateway/Connection/ConnectionFactory.php i/src/Profile/Shopware/Gateway/Connection/ConnectionFactory.php index fa949b6..bf9792d 100644 --- c/src/Profile/Shopware/Gateway/Connection/ConnectionFactory.php +++ i/src/Profile/Shopware/Gateway/Connection/ConnectionFactory.php @@ -24,13 +24,7 @@ class ConnectionFactory implements ConnectionFactoryInterface, ResetInterface public function createApiClient(MigrationContextInterface $migrationContext): HttpClientInterface { - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - throw MigrationException::noConnectionFound(); - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if (empty($credentials)) { throw MigrationException::invalidConnectionCredentials(); @@ -57,13 +51,7 @@ class ConnectionFactory implements ConnectionFactoryInterface, ResetInterface return $this->externalConnection; } - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - throw MigrationException::noConnectionFound(); - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { throw MigrationException::invalidConnectionCredentials(); diff --git c/src/Profile/Shopware/Media/LocalOrderDocumentProcessor.php i/src/Profile/Shopware/Media/LocalOrderDocumentProcessor.php index 8dffb83..e4d52ec 100644 --- c/src/Profile/Shopware/Media/LocalOrderDocumentProcessor.php +++ i/src/Profile/Shopware/Media/LocalOrderDocumentProcessor.php @@ -66,12 +66,7 @@ class LocalOrderDocumentProcessor extends BaseMediaService implements MediaFileP private function getInstallationRoot(MigrationContextInterface $migrationContext): string { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return ''; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { return ''; diff --git c/src/Profile/Shopware/Media/LocalProductDownloadProcessor.php i/src/Profile/Shopware/Media/LocalProductDownloadProcessor.php index 39527fc..97f6809 100644 --- c/src/Profile/Shopware/Media/LocalProductDownloadProcessor.php +++ i/src/Profile/Shopware/Media/LocalProductDownloadProcessor.php @@ -71,12 +71,7 @@ class LocalProductDownloadProcessor extends BaseMediaService implements MediaFil private function getInstallationRoot(MigrationContextInterface $migrationContext): string { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return ''; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { return ''; diff --git c/src/Profile/Shopware/Media/Strategy/Md5StrategyResolver.php i/src/Profile/Shopware/Media/Strategy/Md5StrategyResolver.php index 0086edc..33bfe46 100644 --- c/src/Profile/Shopware/Media/Strategy/Md5StrategyResolver.php +++ i/src/Profile/Shopware/Media/Strategy/Md5StrategyResolver.php @@ -24,12 +24,7 @@ class Md5StrategyResolver implements StrategyResolverInterface public function resolve(string $path, MigrationContextInterface $migrationContext): string { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return ''; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { return ''; diff --git c/src/Profile/Shopware/Media/Strategy/PlainStrategyResolver.php i/src/Profile/Shopware/Media/Strategy/PlainStrategyResolver.php index 16381b1..31b9784 100644 --- c/src/Profile/Shopware/Media/Strategy/PlainStrategyResolver.php +++ i/src/Profile/Shopware/Media/Strategy/PlainStrategyResolver.php @@ -20,12 +20,7 @@ class PlainStrategyResolver implements StrategyResolverInterface public function resolve(string $path, MigrationContextInterface $migrationContext): string { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return ''; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { return ''; diff --git c/src/Profile/Shopware/Premapping/DefaultShippingAvailabilityRuleReader.php i/src/Profile/Shopware/Premapping/DefaultShippingAvailabilityRuleReader.php index ee326b4..59844bd 100644 --- c/src/Profile/Shopware/Premapping/DefaultShippingAvailabilityRuleReader.php +++ i/src/Profile/Shopware/Premapping/DefaultShippingAvailabilityRuleReader.php @@ -63,12 +63,7 @@ class DefaultShippingAvailabilityRuleReader implements PremappingReaderInterface protected function fillConnectionPremappingValue(MigrationContextInterface $migrationContext): void { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return; - } - - $mappingArray = $connection->getPremapping(); + $mappingArray = $migrationContext->getConnection()->getPremapping(); if ($mappingArray === null) { return; diff --git c/src/Profile/Shopware/Premapping/DeliveryTimeReader.php i/src/Profile/Shopware/Premapping/DeliveryTimeReader.php index fcae802..735fa78 100644 --- c/src/Profile/Shopware/Premapping/DeliveryTimeReader.php +++ i/src/Profile/Shopware/Premapping/DeliveryTimeReader.php @@ -63,12 +63,7 @@ class DeliveryTimeReader extends AbstractPremappingReader protected function fillConnectionPremappingValue(MigrationContextInterface $migrationContext): void { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return; - } - - $mappingArray = $connection->getPremapping(); + $mappingArray = $migrationContext->getConnection()->getPremapping(); if ($mappingArray === null) { return; diff --git c/src/Profile/Shopware/Premapping/NewsletterRecipientStatusReader.php i/src/Profile/Shopware/Premapping/NewsletterRecipientStatusReader.php index 8c75857..bac7f4f 100644 --- c/src/Profile/Shopware/Premapping/NewsletterRecipientStatusReader.php +++ i/src/Profile/Shopware/Premapping/NewsletterRecipientStatusReader.php @@ -47,12 +47,7 @@ class NewsletterRecipientStatusReader extends AbstractPremappingReader protected function fillConnectionPremappingValue(MigrationContextInterface $migrationContext): void { - $connection = $migrationContext->getConnection(); - if ($connection === null) { - return; - } - - $mappingArray = $connection->getPremapping(); + $mappingArray = $migrationContext->getConnection()->getPremapping(); if ($mappingArray === null) { return; diff --git c/src/Profile/Shopware6/Converter/ShopwareConverter.php i/src/Profile/Shopware6/Converter/ShopwareConverter.php index 8499a75..d2dcb8d 100644 --- c/src/Profile/Shopware6/Converter/ShopwareConverter.php +++ i/src/Profile/Shopware6/Converter/ShopwareConverter.php @@ -48,10 +48,7 @@ abstract class ShopwareConverter extends Converter $this->migrationContext = $migrationContext; $connection = $migrationContext->getConnection(); - $this->connectionId = ''; - if ($connection !== null) { - $this->connectionId = $connection->getId(); - } + $this->connectionId = $connection->getId(); $this->runId = $this->migrationContext->getRunUuid(); diff --git c/src/Profile/Shopware6/Gateway/Api/Shopware6ApiGateway.php i/src/Profile/Shopware6/Gateway/Api/Shopware6ApiGateway.php index b1e6cbd..0307360 100644 --- c/src/Profile/Shopware6/Gateway/Api/Shopware6ApiGateway.php +++ i/src/Profile/Shopware6/Gateway/Api/Shopware6ApiGateway.php @@ -84,20 +84,7 @@ class Shopware6ApiGateway implements ShopwareGatewayInterface ); } - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - return new EnvironmentInformation( - $profile->getSourceSystemName(), - $profile->getVersion(), - '', - [], - [], - null - ); - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { return new EnvironmentInformation( diff --git c/src/Profile/Shopware6/Gateway/Connection/AuthClient.php i/src/Profile/Shopware6/Gateway/Connection/AuthClient.php index ebb2849..4f06576 100644 --- c/src/Profile/Shopware6/Gateway/Connection/AuthClient.php +++ i/src/Profile/Shopware6/Gateway/Connection/AuthClient.php @@ -14,6 +14,7 @@ use Psr\Http\Message\ResponseInterface; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Log\Package; +use SwagMigrationAssistant\Exception\MigrationException; use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionCollection; use SwagMigrationAssistant\Migration\Gateway\HttpClientInterface; use SwagMigrationAssistant\Migration\MigrationContext; @@ -95,16 +96,10 @@ class AuthClient implements HttpClientInterface private function renewBearerToken(): void { - $connection = $this->migrationContext->getConnection(); - - if ($connection === null) { - return; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $this->migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { - return; + throw MigrationException::invalidConnectionCredentials(); } $response = $this->apiClient->post('/api/oauth/token', [ @@ -126,25 +121,20 @@ class AuthClient implements HttpClientInterface private function saveBearerToken(): void { $connection = $this->migrationContext->getConnection(); + $credentials = $connection->getCredentialFields(); - if ($connection === null) { - return; - } - - $credentialFields = $connection->getCredentialFields(); - - if ($credentialFields === null) { - return; + if ($credentials === null) { + throw MigrationException::invalidConnectionCredentials(); } $connectionUuid = $connection->getId(); - $credentialFields['bearer_token'] = $this->bearerToken; + $credentials['bearer_token'] = $this->bearerToken; - $this->context->scope(MigrationContext::SOURCE_CONTEXT, function (Context $context) use ($connectionUuid, $credentialFields): void { + $this->context->scope(MigrationContext::SOURCE_CONTEXT, function (Context $context) use ($connectionUuid, $credentials): void { $this->connectionRepository->update([ [ 'id' => $connectionUuid, - 'credentialFields' => $credentialFields, + 'credentialFields' => $credentials, ], ], $context); }); @@ -152,15 +142,7 @@ class AuthClient implements HttpClientInterface private function loadBearerToken(): void { - $connection = $this->migrationContext->getConnection(); - - if ($connection === null) { - $this->renewBearerToken(); - - return; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $this->migrationContext->getConnection()->getCredentialFields(); if ($credentials === null) { $this->renewBearerToken(); diff --git c/src/Profile/Shopware6/Gateway/Connection/ConnectionFactory.php i/src/Profile/Shopware6/Gateway/Connection/ConnectionFactory.php index 67e1078..5c6019c 100644 --- c/src/Profile/Shopware6/Gateway/Connection/ConnectionFactory.php +++ i/src/Profile/Shopware6/Gateway/Connection/ConnectionFactory.php @@ -29,13 +29,7 @@ class ConnectionFactory implements ConnectionFactoryInterface public function createApiClient(MigrationContextInterface $migrationContext): ?HttpClientInterface { - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - return null; - } - - $credentials = $connection->getCredentialFields(); + $credentials = $migrationContext->getConnection()->getCredentialFields(); if (empty($credentials) || !isset($credentials['endpoint'])) { return null; diff --git c/src/Profile/Shopware6/Media/HttpOrderDocumentGenerationService.php i/src/Profile/Shopware6/Media/HttpOrderDocumentGenerationService.php index 267ab7c..dae35f7 100644 --- c/src/Profile/Shopware6/Media/HttpOrderDocumentGenerationService.php +++ i/src/Profile/Shopware6/Media/HttpOrderDocumentGenerationService.php @@ -71,13 +71,7 @@ class HttpOrderDocumentGenerationService extends BaseMediaService implements Med $mappedWorkload = []; $documentIds = []; $runId = $migrationContext->getRunUuid(); - $connection = $migrationContext->getConnection(); - - if ($connection === null) { - return $workload; - } - - $this->connection = $connection; + $this->connection = $migrationContext->getConnection(); foreach ($workload as $work) { $mappedWorkload[$work->getMediaId()] = $work; diff --git c/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php i/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php index c24852f..fe76c80 100644 --- c/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php +++ i/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php @@ -167,13 +167,8 @@ abstract class ShopwareConverterTest extends TestCase protected function loadMapping(array $mappingArray): void { - $connection = $this->migrationContext->getConnection(); + $connectionId = $this->migrationContext->getConnection()->getId(); - if ($connection === null) { - return; - } - - $connectionId = $connection->getId(); foreach ($mappingArray as $mapping) { $mappingConnection = null; if (isset($mapping['connectionId'])) {
501a64f to
f832cef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors migration connection usage by modifying the MigrationContext constructor parameter order and removing null checks for connection entities throughout the codebase. This ensures connections are always required and properly handled.
Key changes include:
- Reordered MigrationContext constructor to place connection first as a required parameter
- Removed null checks for connection entities since they're now guaranteed to exist
- Updated test classes to use the new constructor parameter order
Reviewed Changes
Copilot reviewed 154 out of 154 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Migration/MigrationContext.php | Updated constructor parameter order and removed nullable connection |
| src/Migration/MigrationContextInterface.php | Added setter methods for configuration properties |
| src/Migration/MigrationContextFactory.php | Updated to use new constructor parameter order |
| tests/Profile/Shopware6/Converter/ShopwareConverterTest.php | Removed unnecessary null checks for connection |
| phpstan.neon.dist | Removed PHPStan suppressions for connection null checks |
Comments suppressed due to low confidence (1)
src/Migration/MigrationContext.php:25
- The class is marked as readonly but contains mutable private properties. This is inconsistent - either remove readonly or make properties immutable.
private ?ProfileInterface $profile = null,
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
f832cef to
23e0463
Compare
MalteJanz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 💪 . Just keep in mind that this includes breaking changes, so please document them in the UPGRADE.md.
Additionally it would be nice if you could open a PR on the Magento profile repository as well, so we don't have to adjust to all of these breaking changes later / at once but instead try to keep them compatible as we go 🙂
ennasus4sun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really nice! 💪🏻
|
4213118 to
5cedd46
Compare
638b84d
into
feature/migration-logging-refactor
resolves #11883