diff --git a/src/DependencyInjection/shopware.xml b/src/DependencyInjection/shopware.xml index b893496aa..77f6e4503 100644 --- a/src/DependencyInjection/shopware.xml +++ b/src/DependencyInjection/shopware.xml @@ -212,8 +212,8 @@ - + $data */ - public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct; + public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ?ConvertStruct; public function writeMapping(Context $context): void; } diff --git a/src/Migration/Logging/Log/MainVariantRelationNotConverted.php b/src/Migration/Logging/Log/MainVariantRelationNotConverted.php new file mode 100644 index 000000000..f1c391502 --- /dev/null +++ b/src/Migration/Logging/Log/MainVariantRelationNotConverted.php @@ -0,0 +1,30 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationAssistant\Migration\Logging\Log; + +use Shopware\Core\Framework\Log\Package; +use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry; + +#[Package('after-sales')] +readonly class MainVariantRelationNotConverted extends AbstractMigrationLogEntry +{ + public function getLevel(): string + { + return self::LOG_LEVEL_ERROR; + } + + public function getCode(): string + { + return 'SWAG_MIGRATION__MAIN_VARIANT_RELATION_NOT_CONVERTED'; + } + + public function isUserFixable(): bool + { + return false; + } +} diff --git a/src/Migration/Logging/Log/NotConvertedLog.php b/src/Migration/Logging/Log/NotConvertedLog.php new file mode 100644 index 000000000..064de37f9 --- /dev/null +++ b/src/Migration/Logging/Log/NotConvertedLog.php @@ -0,0 +1,30 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationAssistant\Migration\Logging\Log; + +use Shopware\Core\Framework\Log\Package; +use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry; + +#[Package('after-sales')] +readonly class NotConvertedLog extends AbstractMigrationLogEntry +{ + public function getLevel(): string + { + return self::LOG_LEVEL_INFO; + } + + public function getCode(): string + { + return 'SWAG_MIGRATION__ENTITY_NOT_CONVERTED'; + } + + public function isUserFixable(): bool + { + return false; + } +} diff --git a/src/Migration/Service/MigrationDataConverter.php b/src/Migration/Service/MigrationDataConverter.php index 5a009daaa..8f3a39687 100644 --- a/src/Migration/Service/MigrationDataConverter.php +++ b/src/Migration/Service/MigrationDataConverter.php @@ -15,9 +15,11 @@ use Shopware\Core\Framework\Util\Hasher; use SwagMigrationAssistant\Migration\Converter\ConverterInterface; use SwagMigrationAssistant\Migration\Converter\ConverterRegistryInterface; +use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\Log\ExceptionRunLog; +use SwagMigrationAssistant\Migration\Logging\Log\NotConvertedLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\MappingDeltaResult; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; @@ -96,6 +98,17 @@ private function convertData( foreach ($data as $item) { try { $convertStruct = $converter->convert($item, $context, $migrationContext); + if (!$convertStruct instanceof ConvertStruct) { + $this->loggingService->addLogEntry( + MigrationLogBuilder::fromMigrationContext($migrationContext) + ->withSourceData($item) + ->withEntityName($dataSet::getEntity()) + ->build(NotConvertedLog::class) + ); + + continue; + } + $convertFailureFlag = empty($convertStruct->getConverted()); $this->validationService->validate( diff --git a/src/Profile/Shopware/Converter/CategoryConverter.php b/src/Profile/Shopware/Converter/CategoryConverter.php index 9a610ebf7..dfacd188a 100644 --- a/src/Profile/Shopware/Converter/CategoryConverter.php +++ b/src/Profile/Shopware/Converter/CategoryConverter.php @@ -14,8 +14,6 @@ use SwagMigrationAssistant\Exception\MigrationException; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\DefaultCmsPageLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; @@ -37,7 +35,7 @@ abstract class CategoryConverter extends ShopwareConverter protected string $oldCategoryId; - protected string $locale; + protected ?string $locale = null; protected string $runId; @@ -84,19 +82,13 @@ public function convert( $this->connectionId = $connection->getId(); $this->connectionName = $connection->getName(); - if (!isset($data['_locale'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(CategoryDefinition::ENTITY_NAME) - ->withFieldSourcePath('_locale') - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); + $converted = []; - return new ConvertStruct(null, $data); + if (isset($data['_locale'])) { + $this->locale = $data['_locale']; + } else { + $this->locale = null; } - $this->locale = $data['_locale']; - $converted = []; $cmsPageUuid = $this->defaultCmsPageLookup->get($context); if ($cmsPageUuid !== null) { @@ -244,8 +236,7 @@ protected function setGivenCategoryTranslation(array &$data, array &$converted): } $locale = $language->getLocale(); - - if ($locale === null || $locale->getCode() === $data['_locale']) { + if (!isset($data['_locale']) || $locale?->getCode() === $data['_locale']) { return; } @@ -364,10 +355,12 @@ protected function addMediaTranslation(array &$media, array $data): void $localeTranslation['id'] = $mapping['entityId']; $this->mappingIds[] = $mapping['id']; - $languageUuid = $this->languageLookup->get($this->locale, $this->context); - if ($languageUuid !== null) { - $localeTranslation['languageId'] = $languageUuid; - $media['translations'][$languageUuid] = $localeTranslation; + if ($this->locale !== null) { + $languageUuid = $this->languageLookup->get($this->locale, $this->context); + if ($languageUuid !== null) { + $localeTranslation['languageId'] = $languageUuid; + $media['translations'][$languageUuid] = $localeTranslation; + } } } } diff --git a/src/Profile/Shopware/Converter/CrossSellingConverter.php b/src/Profile/Shopware/Converter/CrossSellingConverter.php index 4211f935a..d4e202570 100644 --- a/src/Profile/Shopware/Converter/CrossSellingConverter.php +++ b/src/Profile/Shopware/Converter/CrossSellingConverter.php @@ -7,13 +7,10 @@ namespace SwagMigrationAssistant\Profile\Shopware\Converter; -use Shopware\Core\Content\Product\Aggregate\ProductCrossSelling\ProductCrossSellingDefinition; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\MigrationContextInterface; #[Package('fundamentals@after-sales')] @@ -59,36 +56,14 @@ public function convert(array $data, Context $context, MigrationContextInterface $converted['id'] = $crossSellingMapping['entityId']; $sourceProductMapping = $this->getProductMapping($data['articleID']); - if ($sourceProductMapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductCrossSellingDefinition::ENTITY_NAME) - ->withFieldName('id') - ->withFieldSourcePath('articleID') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $data); + if ($sourceProductMapping !== null) { + $this->mappingIds[] = $sourceProductMapping['id']; } - $this->mappingIds[] = $sourceProductMapping['id']; $relatedProductMapping = $this->getProductMapping($data['relatedarticle']); - if ($relatedProductMapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductCrossSellingDefinition::ENTITY_NAME) - ->withFieldName('id') - ->withFieldSourcePath('relatedarticle') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $data); + if ($relatedProductMapping !== null) { + $this->mappingIds[] = $relatedProductMapping['id']; } - $this->mappingIds[] = $relatedProductMapping['id']; if ($data['type'] === DefaultEntities::CROSS_SELLING_SIMILAR) { $converted['name'] = 'Similar Items'; @@ -105,15 +80,17 @@ public function convert(array $data, Context $context, MigrationContextInterface $converted['type'] = 'productList'; $converted['active'] = true; - $converted['productId'] = $sourceProductMapping['entityId']; $converted['assignedProducts'] = [ [ - 'id' => $relationMapping['entityId'], - 'position' => $data['position'], - 'productId' => $relatedProductMapping['entityId'], + 'id' => $relationMapping['entityId'] ?? null, + 'position' => $data['position'] ?? null, + 'productId' => $relatedProductMapping['entityId'] ?? null, ], ]; + if (isset($sourceProductMapping['entityId'])) { + $converted['productId'] = $sourceProductMapping['entityId']; + } unset( $data['type'], $data['id'], diff --git a/src/Profile/Shopware/Converter/CurrencyConverter.php b/src/Profile/Shopware/Converter/CurrencyConverter.php index fd2475a09..5ec5d92f6 100644 --- a/src/Profile/Shopware/Converter/CurrencyConverter.php +++ b/src/Profile/Shopware/Converter/CurrencyConverter.php @@ -40,7 +40,7 @@ public function getSourceIdentifier(array $data): string return $data['currency']; } - public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct + public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ?ConvertStruct { $this->generateChecksum($data); $this->context = $context; @@ -63,7 +63,7 @@ public function convert(array $data, Context $context, MigrationContextInterface ); } - return new ConvertStruct(null, $data); + return null; } $converted = []; diff --git a/src/Profile/Shopware/Converter/CustomerConverter.php b/src/Profile/Shopware/Converter/CustomerConverter.php index ce0cb9fcc..6964e59d8 100644 --- a/src/Profile/Shopware/Converter/CustomerConverter.php +++ b/src/Profile/Shopware/Converter/CustomerConverter.php @@ -31,7 +31,6 @@ use SwagMigrationAssistant\Migration\MigrationContextInterface; use SwagMigrationAssistant\Profile\Shopware\Premapping\PaymentMethodReader; use SwagMigrationAssistant\Profile\Shopware\Premapping\SalutationReader; -use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Validator\ValidatorInterface; #[Package('fundamentals@after-sales')] @@ -165,19 +164,18 @@ public function convert( $converted['customerNumber'] = 'number-' . $this->oldCustomerId; } - $mapping = $this->mappingService->getMapping( - $this->connectionId, - DefaultEntities::CUSTOMER_GROUP, - $data['customerGroupId'] ?? '', - $context - ); - - if (\is_array($mapping) && \array_key_exists('entityId', $mapping)) { - $converted['groupId'] = $mapping['entityId']; - $this->mappingIds[] = $mapping['id']; + if (isset($data['customerGroupId'])) { + $mapping = $this->mappingService->getMapping( + $this->connectionId, + DefaultEntities::CUSTOMER_GROUP, + $data['customerGroupId'], + $context + ); + if ($mapping !== null) { + $converted['groupId'] = $mapping['entityId']; + $this->mappingIds[] = $mapping['id']; + } unset($data['customerGroupId'], $data['customergroup']); - } else { - $converted['groupId'] = null; } if (isset($data['defaultpayment']['id'])) { @@ -198,19 +196,15 @@ public function convert( $this->context ); - if (\is_array($mapping) && \array_key_exists('entityId', $mapping)) { + if ($mapping !== null) { $converted['defaultPaymentMethodId'] = $mapping['entityId']; $this->mappingIds[] = $mapping['id']; - } else { - $converted['defaultPaymentMethodId'] = null; } } $salutationUuid = $this->getSalutation($data['salutation']); if ($salutationUuid !== null) { $converted['salutationId'] = $salutationUuid; - } else { - $converted['salutationId'] = null; } if (isset($data['addresses']) && isset($this->mainMapping['entityId'])) { @@ -404,13 +398,13 @@ protected function applyAddresses(array &$originalData, array &$converted, strin $converted['addresses'] = $addresses; // No valid default billing and shipping address was converted, so use the first valid one as default - $this->checkUnsetDefaultShippingAndDefaultBillingAddress($originalData, $converted, $customerUuid, $addresses); + $this->checkUnsetDefaultShippingAndDefaultBillingAddress($originalData, $converted, $addresses); // No valid default shipping address was converted, but the default billing address is valid - $this->checkUnsetDefaultShippingAddress($originalData, $converted, $customerUuid); + $this->checkUnsetDefaultShippingAddress($originalData, $converted); // No valid default billing address was converted, but the default shipping address is valid - $this->checkUnsetDefaultBillingAddress($originalData, $converted, $customerUuid); + $this->checkUnsetDefaultBillingAddress($originalData, $converted); } /** @@ -610,7 +604,7 @@ protected function applyCountryStateTranslation(array &$state, array $data): voi * @param array $converted * @param array> $addresses */ - protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$originalData, array &$converted, string $customerUuid, array $addresses): void + protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$originalData, array &$converted, array $addresses): void { if (!isset($converted['defaultBillingAddressId']) && !isset($converted['defaultShippingAddressId'])) { $converted['defaultBillingAddressId'] = $addresses[0]['id']; @@ -636,7 +630,7 @@ protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$ori * @param array $originalData * @param array $converted */ - protected function checkUnsetDefaultShippingAddress(array &$originalData, array &$converted, string $customerUuid): void + protected function checkUnsetDefaultShippingAddress(array &$originalData, array &$converted): void { if (!isset($converted['defaultShippingAddressId']) && isset($converted['defaultBillingAddressId'])) { $converted['defaultShippingAddressId'] = $converted['defaultBillingAddressId']; @@ -657,7 +651,7 @@ protected function checkUnsetDefaultShippingAddress(array &$originalData, array * @param array $originalData * @param array $converted */ - protected function checkUnsetDefaultBillingAddress(array &$originalData, array &$converted, string $customerUuid): void + protected function checkUnsetDefaultBillingAddress(array &$originalData, array &$converted): void { if (!isset($converted['defaultBillingAddressId']) && isset($converted['defaultShippingAddressId'])) { $converted['defaultBillingAddressId'] = $converted['defaultShippingAddressId']; @@ -700,17 +694,6 @@ protected function getSalutation(string $salutation): ?string return $mapping['entityId']; } - protected function checkEmailValidity(string $email): bool - { - $constraint = new Email(); - $errors = $this->validator->validate( - $email, - $constraint - ); - - return \count($errors) === 0; - } - /** * If the customer's default billing address or default shipping address contains a company, * the account type is business, else private. diff --git a/src/Profile/Shopware/Converter/CustomerWishlistConverter.php b/src/Profile/Shopware/Converter/CustomerWishlistConverter.php index 1a3667d68..7bcbe3261 100644 --- a/src/Profile/Shopware/Converter/CustomerWishlistConverter.php +++ b/src/Profile/Shopware/Converter/CustomerWishlistConverter.php @@ -37,31 +37,31 @@ public function convert(array $data, Context $context, MigrationContextInterface $this->checksum ); + $converted = []; + $customerMapping = $this->mappingService->getMapping($this->connectionId, DefaultEntities::CUSTOMER, $data['userID'], $context); - if ($customerMapping === null) { - return new ConvertStruct(null, $data); + if ($customerMapping !== null) { + $this->mappingIds[] = $customerMapping['id']; + $converted['customerId'] = $customerMapping['entityId']; } + $productId = null; $productMapping = $this->mappingService->getMapping($this->connectionId, DefaultEntities::PRODUCT, $data['ordernumber'], $context); - if ($productMapping === null) { - return new ConvertStruct(null, $data); + if ($productMapping !== null) { + $this->mappingIds[] = $productMapping['id']; + $productId = $productMapping['entityId']; } $shopMapping = $this->mappingService->getMapping($this->connectionId, DefaultEntities::SALES_CHANNEL, $data['subshopID'], $context); - if ($shopMapping === null) { - return new ConvertStruct(null, $data); + if ($shopMapping !== null) { + $converted['salesChannelId'] = $shopMapping['entityId']; } - $this->mappingIds[] = $customerMapping['id']; - $this->mappingIds[] = $productMapping['id']; - - $converted = []; $converted['id'] = $this->mainMapping['entityId']; - $converted['customerId'] = $customerMapping['entityId']; - $converted['salesChannelId'] = $shopMapping['entityId']; + $converted['products'][] = [ 'id' => $this->mappingService->getOrCreateMapping($this->connectionId, DefaultEntities::CUSTOMER_WISHLIST_PRODUCT, $data['userID'] . '_' . $data['ordernumber'], $context)['entityId'], - 'productId' => $productMapping['entityId'], + 'productId' => $productId, ]; $this->updateMainMapping($migrationContext, $context); diff --git a/src/Profile/Shopware/Converter/LanguageConverter.php b/src/Profile/Shopware/Converter/LanguageConverter.php index fc4362fb8..d0732d893 100644 --- a/src/Profile/Shopware/Converter/LanguageConverter.php +++ b/src/Profile/Shopware/Converter/LanguageConverter.php @@ -9,11 +9,8 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\Log\Package; -use Shopware\Core\System\Language\LanguageDefinition; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; -use SwagMigrationAssistant\Migration\Logging\Log\EntityAlreadyExistsRunLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\LocaleLookup; @@ -30,8 +27,8 @@ abstract class LanguageConverter extends ShopwareConverter public function __construct( MappingServiceInterface $mappingService, LoggingServiceInterface $loggingService, - protected readonly LanguageLookup $languageLookup, protected readonly LocaleLookup $localeLookup, + protected readonly LanguageLookup $languageLookup, ) { parent::__construct($mappingService, $loggingService); } @@ -41,7 +38,7 @@ public function getSourceIdentifier(array $data): string return $data['locale']; } - public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct + public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ?ConvertStruct { $this->generateChecksum($data); $this->context = $context; @@ -51,15 +48,7 @@ public function convert(array $data, Context $context, MigrationContextInterface $languageUuid = $this->languageLookup->get($data['locale'], $context); if ($languageUuid !== null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(LanguageDefinition::ENTITY_NAME) - ->withFieldSourcePath('locale') - ->withSourceData($data) - ->build(EntityAlreadyExistsRunLog::class) - ); - - return new ConvertStruct(null, $data); + return null; } $converted = []; diff --git a/src/Profile/Shopware/Converter/MainVariantRelationConverter.php b/src/Profile/Shopware/Converter/MainVariantRelationConverter.php index bf6d2bb8b..17748310b 100644 --- a/src/Profile/Shopware/Converter/MainVariantRelationConverter.php +++ b/src/Profile/Shopware/Converter/MainVariantRelationConverter.php @@ -11,8 +11,8 @@ use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; +use SwagMigrationAssistant\Migration\Logging\Log\MainVariantRelationNotConverted; use SwagMigrationAssistant\Migration\MigrationContextInterface; #[Package('fundamentals@after-sales')] @@ -27,7 +27,7 @@ public function getSourceIdentifier(array $data): string return $data['id']; } - public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct + public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ?ConvertStruct { $this->generateChecksum($data); $this->context = $context; @@ -35,7 +35,15 @@ public function convert(array $data, Context $context, MigrationContextInterface $this->connectionId = $connection->getId(); if (!isset($data['id'], $data['ordernumber'])) { - return new ConvertStruct(null, $data); + $this->loggingService->addLogEntry( + MigrationLogBuilder::fromMigrationContext($migrationContext) + ->withSourceData($data) + ->withExceptionMessage('MainVariantRelation requires ID and order number, to be converted successful') + ->withExceptionTrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 2)) + ->build(MainVariantRelationNotConverted::class) + ); + + return null; } $this->mainMapping = $this->mappingService->getOrCreateMapping( @@ -60,38 +68,21 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($mainProductMapping === null) { - $this->addAssociationRequiredLog( - $migrationContext, - 'id', - DefaultEntities::PRODUCT_CONTAINER, - $data - ); + $converted = []; - return new ConvertStruct(null, $data); + if ($mainProductMapping !== null) { + $this->mappingIds[] = $mainProductMapping['id']; + $converted['id'] = $mainProductMapping['entityId']; } - if ($variantProductMapping === null) { - $this->addAssociationRequiredLog( - $migrationContext, - 'ordernumber', - DefaultEntities::PRODUCT, - $data - ); - - return new ConvertStruct(null, $data); + if ($variantProductMapping !== null) { + $this->mappingIds[] = $variantProductMapping['id']; + $converted['variantListingConfig'] = [ + 'displayParent' => true, + 'mainVariantId' => $variantProductMapping['entityId'], + ]; } - $this->mappingIds[] = $mainProductMapping['id']; - $this->mappingIds[] = $variantProductMapping['id']; - - $converted = []; - $converted['id'] = $mainProductMapping['entityId']; - - $converted['variantListingConfig'] = [ - 'displayParent' => true, - 'mainVariantId' => $variantProductMapping['entityId'], - ]; unset($data['id'], $data['ordernumber']); $returnData = $data; @@ -103,18 +94,4 @@ public function convert(array $data, Context $context, MigrationContextInterface return new ConvertStruct($converted, $returnData, $this->mainMapping['id'] ?? null); } - - /** - * @param array $data - */ - private function addAssociationRequiredLog(MigrationContextInterface $migrationContext, string $field, string $entity, array $data): void - { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName($entity) - ->withFieldSourcePath($field) - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - } } diff --git a/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php b/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php index 6e23b12ff..6b97460bb 100644 --- a/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php +++ b/src/Profile/Shopware/Converter/NewsletterRecipientConverter.php @@ -36,14 +36,6 @@ abstract class NewsletterRecipientConverter extends ShopwareConverter protected string $runId; - /** - * @var list - */ - protected array $requiredDataFieldKeys = [ - '_locale', - 'shopId', - ]; - public function __construct( MappingServiceInterface $mappingService, LoggingServiceInterface $loggingService, @@ -61,21 +53,7 @@ public function convert( $this->connectionId = $connection->getId(); $this->runId = $migrationContext->getRunUuid(); - $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); - - if (!empty($fields)) { - $this->loggingService->addLogForEach( - $fields, - fn (string $key) => MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(NewsletterRecipientDefinition::ENTITY_NAME) - ->withFieldName($key) - ->build(EmptyNecessaryFieldRunLog::class) - ); - return new ConvertStruct(null, $data); - } - - $oldData = $data; $this->generateChecksum($data); $this->context = $context; $this->locale = $data['_locale']; @@ -120,21 +98,19 @@ public function convert( $status = $this->getStatus($migrationContext); } - if ($status === null) { - return new ConvertStruct(null, $oldData); + if ($status !== null) { + $converted['status'] = $status; } - $converted['status'] = $status; $converted['languageId'] = $this->languageLookup->get($this->locale, $context); $salesChannelUuid = $this->getSalesChannel($data); - if ($salesChannelUuid === null) { - return new ConvertStruct(null, $oldData); + if ($salesChannelUuid !== null) { + $converted['salesChannelId'] = $salesChannelUuid; } - unset($data['shopId']); - $converted['salesChannelId'] = $salesChannelUuid; unset( + $data['shopId'], $data['id'], $data['groupID'], $data['lastmailing'], diff --git a/src/Profile/Shopware/Converter/NumberRangeConverter.php b/src/Profile/Shopware/Converter/NumberRangeConverter.php index f4b7e22e5..8ca84d57b 100644 --- a/src/Profile/Shopware/Converter/NumberRangeConverter.php +++ b/src/Profile/Shopware/Converter/NumberRangeConverter.php @@ -14,18 +14,14 @@ use Shopware\Core\Framework\Log\Package; use Shopware\Core\Framework\Uuid\Uuid; use Shopware\Core\System\NumberRange\NumberRangeCollection; -use Shopware\Core\System\NumberRange\NumberRangeDefinition; use Shopware\Core\System\NumberRange\NumberRangeEntity; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\NumberRangeLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; -use SwagMigrationAssistant\Profile\Shopware\Logging\Log\UnsupportedNumberRangeTypeLog; #[Package('fundamentals@after-sales')] abstract class NumberRangeConverter extends ShopwareConverter @@ -71,35 +67,10 @@ public function convert(array $data, Context $context, MigrationContextInterface $connection = $migrationContext->getConnection(); $this->connectionId = $connection->getId(); - - if (!\array_key_exists($data['name'], self::TYPE_MAPPING)) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(NumberRangeDefinition::ENTITY_NAME) - ->withFieldName('typeId') - ->withFieldSourcePath('name') - ->withSourceData($data) - ->build(UnsupportedNumberRangeTypeLog::class) - ); - - return new ConvertStruct(null, $data); - } - $converted = []; $converted['id'] = $this->getUuid($data, $migrationContext, $context); - $converted['typeId'] = $this->getProductNumberRangeTypeUuid($data['name']); - - if (empty($converted['typeId'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(NumberRangeDefinition::ENTITY_NAME) - ->withFieldName('typeId') - ->withFieldSourcePath('name') - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); + if (\array_key_exists($data['name'], self::TYPE_MAPPING)) { + $converted['typeId'] = $this->getProductNumberRangeTypeUuid($data['name']); } $converted['global'] = $this->getGlobal($data['name']); @@ -268,7 +239,7 @@ protected function setNumberRangeSalesChannels(array &$converted, Context $conte $numberRangeSalesChannel['id'] = $mapping['entityId']; $numberRangeSalesChannel['numberRangeId'] = $converted['id']; $numberRangeSalesChannel['salesChannelId'] = $saleChannelId; - $numberRangeSalesChannel['numberRangeTypeId'] = $converted['typeId']; + $numberRangeSalesChannel['numberRangeTypeId'] = $converted['typeId'] ?? null; $numberRangeSalesChannels[] = $numberRangeSalesChannel; $this->mappingIds[] = $mapping['id']; } diff --git a/src/Profile/Shopware/Converter/OrderConverter.php b/src/Profile/Shopware/Converter/OrderConverter.php index ec08e13e9..759752370 100644 --- a/src/Profile/Shopware/Converter/OrderConverter.php +++ b/src/Profile/Shopware/Converter/OrderConverter.php @@ -21,7 +21,6 @@ use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryDefinition; use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemDefinition; use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionDefinition; -use Shopware\Core\Checkout\Order\OrderDefinition; use Shopware\Core\Defaults; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -35,7 +34,6 @@ use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\Log\UnknownEntityLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\CountryLookup; @@ -71,29 +69,6 @@ abstract class OrderConverter extends ShopwareConverter protected string $runId; - /** - * @var list - */ - protected array $requiredDataFieldKeys = [ - 'customer', - 'currency', - 'currencyFactor', - 'payment', - 'status', - ]; - - /** - * @var list - */ - protected array $requiredAddressDataFieldKeys = [ - 'firstname', - 'lastname', - 'zipcode', - 'city', - 'street', - 'salutation', - ]; - protected int $paymentStatusId; /** @@ -129,27 +104,6 @@ public function convert( $this->connectionId = $connection->getId(); $this->connectionName = $connection->getName(); - $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); - if (empty($data['billingaddress']['id'])) { - $fields[] = 'billingaddress'; - } - if (isset($data['payment']) && empty($data['payment']['name'])) { - $fields[] = 'paymentMethod'; - } - - if (!empty($fields)) { - $this->loggingService->addLogForEach( - $fields, - fn (string $key) => MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(OrderDefinition::ENTITY_NAME) - ->withFieldSourcePath($key) - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); - } - $this->mainLocale = $data['_locale']; unset($data['_locale']); $this->context = $context; @@ -202,17 +156,21 @@ public function convert( $this->mappingIds[] = $orderCustomerMapping['id']; unset($customerMapping); - $salutationUuid = $this->getSalutation($data['customer']['salutation']); - if ($salutationUuid === null) { - return new ConvertStruct(null, $data); + $salutationUuid = null; + if (isset($data['customer']['salutation'])) { + $salutationUuid = $this->getSalutation($data['customer']['salutation']); + } + if ($salutationUuid !== null) { + $converted['orderCustomer']['salutationId'] = $salutationUuid; } - $converted['orderCustomer']['salutationId'] = $salutationUuid; - $this->convertValue($converted['orderCustomer'], 'email', $data['customer'], 'email'); - $this->convertValue($converted['orderCustomer'], 'firstName', $data['customer'], 'firstname'); - $this->convertValue($converted['orderCustomer'], 'lastName', $data['customer'], 'lastname'); - $this->convertValue($converted['orderCustomer'], 'customerNumber', $data['customer'], 'customernumber'); - unset($data['userID'], $data['customer']); + if (isset($data['customer'])) { + $this->convertValue($converted['orderCustomer'], 'email', $data['customer'], 'email'); + $this->convertValue($converted['orderCustomer'], 'firstName', $data['customer'], 'firstname'); + $this->convertValue($converted['orderCustomer'], 'lastName', $data['customer'], 'lastname'); + $this->convertValue($converted['orderCustomer'], 'customerNumber', $data['customer'], 'customernumber'); + unset($data['userID'], $data['customer']); + } $this->convertValue($converted, 'currencyFactor', $data, 'currencyFactor', self::TYPE_FLOAT); @@ -220,22 +178,10 @@ public function convert( if (isset($data['currency'])) { $currencyUuid = $this->currencyLookup->get($data['currency'], $context); } - if ($currencyUuid === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(OrderDefinition::ENTITY_NAME) - ->withFieldName('currencyId') - ->withFieldSourcePath('currency') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); + if ($currencyUuid !== null) { + $converted['currencyId'] = $currencyUuid; } - $converted['currencyId'] = $currencyUuid; - $converted['itemRounding'] = [ 'decimals' => $context->getRounding()->getDecimals(), 'interval' => 0.01, @@ -245,28 +191,20 @@ public function convert( $this->convertValue($converted, 'orderDateTime', $data, 'ordertime', self::TYPE_DATETIME); - $stateMapping = $this->mappingService->getMapping( - $this->connectionId, - OrderStateReader::getMappingName(), - (string) $data['status'], - $this->context - ); - - if ($stateMapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(OrderDefinition::ENTITY_NAME) - ->withFieldName('stateId') - ->withFieldSourcePath('status') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(UnknownEntityLog::class) + $stateMapping = null; + if (isset($data['status'])) { + $stateMapping = $this->mappingService->getMapping( + $this->connectionId, + OrderStateReader::getMappingName(), + (string) $data['status'], + $this->context ); + } - return new ConvertStruct(null, $data); + if ($stateMapping !== null) { + $converted['stateId'] = $stateMapping['entityId']; + $this->mappingIds[] = $stateMapping['id']; } - $converted['stateId'] = $stateMapping['entityId']; - $this->mappingIds[] = $stateMapping['id']; $shippingGross = (float) $data['invoice_shipping']; $shippingNet = (float) $data['invoice_shipping_net']; @@ -331,25 +269,18 @@ public function convert( $this->applyTransactions($data, $converted); unset($data['cleared'], $data['paymentstatus']); - $billingAddress = $this->getAddress($data['billingaddress']); - if (empty($billingAddress)) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(OrderDefinition::ENTITY_NAME) - ->withFieldName('billingAddressId') - ->withFieldSourcePath('billingaddress') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(EmptyNecessaryFieldRunLog::class) - ); + $billingAddress = null; + if (isset($data['billingaddress']) && \is_array($data['billingaddress'])) { + $billingAddress = $this->getAddress($data['billingaddress']); + } - return new ConvertStruct(null, $data); + if (!empty($billingAddress)) { + $converted['billingAddressId'] = $billingAddress['id']; + $converted['addresses'][] = $billingAddress; } if (isset($data['billingaddress']['ustid']) && $data['billingaddress']['ustid'] !== '') { $converted['orderCustomer']['vatIds'][] = $data['billingaddress']['ustid']; } - $converted['billingAddressId'] = $billingAddress['id']; - $converted['addresses'][] = $billingAddress; unset($data['billingaddress']); if (isset($data['subshopID'])) { @@ -494,12 +425,15 @@ protected function applyTransactions(array $data, array &$converted): void */ protected function getPaymentMethod(array $originalData): ?string { - $paymentMethodMapping = $this->mappingService->getMapping( - $this->connectionId, - PaymentMethodReader::getMappingName(), - $originalData['payment']['id'], - $this->context - ); + $paymentMethodMapping = null; + if (isset($originalData['payment']['id'])) { + $paymentMethodMapping = $this->mappingService->getMapping( + $this->connectionId, + PaymentMethodReader::getMappingName(), + $originalData['payment']['id'], + $this->context + ); + } if ($paymentMethodMapping === null) { $this->loggingService->addLogEntry( @@ -526,21 +460,6 @@ protected function getPaymentMethod(array $originalData): ?string */ protected function getAddress(array $originalData, string $type = self::BILLING_ADDRESS): array { - $fields = $this->checkForEmptyRequiredDataFields($originalData, $this->requiredAddressDataFieldKeys); - - if (!empty($fields)) { - $this->loggingService->addLogForEach( - $fields, - fn (string $key) => MigrationLogBuilder::fromMigrationContext($this->migrationContext) - ->withEntityName(OrderDefinition::ENTITY_NAME) - ->withFieldSourcePath($key) - ->withSourceData($originalData) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return []; - } - $entityName = DefaultEntities::ORDER_ADDRESS; if ($type !== self::BILLING_ADDRESS) { $entityName = DefaultEntities::ORDER_ADDRESS . '_' . $type; @@ -785,12 +704,15 @@ protected function applyCountryStateTranslation(array &$state, array $data): voi protected function getDeliveries(array $data, array $converted, CalculatedPrice $shippingCosts): array { $deliveries = []; - $deliveryStateMapping = $this->mappingService->getMapping( - $this->connectionId, - OrderDeliveryStateReader::getMappingName(), - (string) $data['status'], - $this->context - ); + $deliveryStateMapping = null; + if (isset($data['status'])) { + $deliveryStateMapping = $this->mappingService->getMapping( + $this->connectionId, + OrderDeliveryStateReader::getMappingName(), + (string) $data['status'], + $this->context + ); + } if ($deliveryStateMapping === null) { $this->loggingService->addLogEntry( diff --git a/src/Profile/Shopware/Converter/OrderDocumentConverter.php b/src/Profile/Shopware/Converter/OrderDocumentConverter.php index 3ca78bd64..f3590b14f 100644 --- a/src/Profile/Shopware/Converter/OrderDocumentConverter.php +++ b/src/Profile/Shopware/Converter/OrderDocumentConverter.php @@ -15,10 +15,8 @@ use Shopware\Core\Framework\Util\Random; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\Log\DocumentTypeNotSupportedLog; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\DocumentTypeLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\MediaDefaultFolderLookup; @@ -76,36 +74,8 @@ public function convert(array $data, Context $context, MigrationContextInterface $this->connectionId = $connection->getId(); $this->connectionName = $connection->getName(); - $oldData = $data; $converted = []; - if (empty($data['hash'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($this->migrationContext) - ->withEntityName(DocumentDefinition::ENTITY_NAME) - ->withFieldSourcePath('hash') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $oldData); - } - - if (!isset($data['documenttype'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(DocumentDefinition::ENTITY_NAME) - ->withFieldName('documentType') - ->withFieldSourcePath('documenttype') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $oldData); - } - $orderMapping = $this->mappingService->getMapping( $this->connectionId, DefaultEntities::ORDER, @@ -113,22 +83,11 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($orderMapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(DocumentDefinition::ENTITY_NAME) - ->withFieldName('orderId') - ->withFieldSourcePath('orderID') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $oldData); + if ($orderMapping !== null) { + $this->mappingIds[] = $orderMapping['id']; + $converted['orderId'] = $orderMapping['entityId']; } unset($data['orderID']); - $orderUuid = $orderMapping['entityId']; - $this->mappingIds[] = $orderMapping['id']; $this->mainMapping = $this->mappingService->getOrCreateMapping( $this->connectionId, @@ -137,27 +96,27 @@ public function convert(array $data, Context $context, MigrationContextInterface $context, $this->checksum ); + $converted['id'] = $this->mainMapping['entityId']; - $converted['orderId'] = $orderUuid; $converted['fileType'] = FileTypes::PDF; $converted['static'] = true; $converted['deepLinkCode'] = Random::getAlphanumericString(32); $converted['config'] = []; + if (isset($data['docID'])) { $converted['config']['documentNumber'] = $data['docID']; + if (isset($data['documenttype'])) { + $converted['documentType'] = $this->getDocumentType($data['documenttype']); + } + if (isset($data['documenttype']['key']) && $data['documenttype']['key'] === 'invoice') { $converted['config']['custom']['invoiceNumber'] = $data['docID']; } - unset($data['docID']); + unset($data['docID'], $data['documenttype']); } - $documentType = $this->getDocumentType($data['documenttype']); - - $converted['documentType'] = $documentType; - unset($data['documenttype']); - if (isset($data['attributes'])) { $converted['customFields'] = $this->getAttributes($data['attributes'], DefaultEntities::ORDER_DOCUMENT, $this->connectionName, ['id', 'documentID'], $this->context); } @@ -244,16 +203,18 @@ protected function getMediaFile(array $data): array $newMedia['id'] = $mapping['entityId']; $this->mappingIds[] = $mapping['id']; - $this->mediaFileService->saveMediaFile( - [ - 'runId' => $this->runId, - 'entity' => OrderDocumentDataSet::getEntity(), - 'uri' => $data['hash'], - 'fileName' => $data['hash'], - 'fileSize' => 0, - 'mediaId' => $newMedia['id'], - ] - ); + if (!empty($data['hash'])) { + $this->mediaFileService->saveMediaFile( + [ + 'runId' => $this->runId, + 'entity' => OrderDocumentDataSet::getEntity(), + 'uri' => $data['hash'], + 'fileName' => $data['hash'], + 'fileSize' => 0, + 'mediaId' => $newMedia['id'], + ] + ); + } $newMedia['private'] = true; $this->convertValue($newMedia, 'title', $data, 'hash'); diff --git a/src/Profile/Shopware/Converter/ProductConverter.php b/src/Profile/Shopware/Converter/ProductConverter.php index 63e844fcf..9499ec730 100644 --- a/src/Profile/Shopware/Converter/ProductConverter.php +++ b/src/Profile/Shopware/Converter/ProductConverter.php @@ -51,14 +51,6 @@ abstract class ProductConverter extends ShopwareConverter protected string $runId; - /** - * @var list - */ - protected array $requiredDataFieldKeys = [ - 'tax', - 'prices', - ]; - /** * @var array{minPurchase: int, purchaseSteps: int, shippingFree: bool, restockTime: int} */ @@ -146,20 +138,6 @@ public function convert( $this->connectionId = $connection->getId(); $this->connectionName = $connection->getName(); - $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); - if (!empty($fields)) { - $this->loggingService->addLogForEach( - $fields, - fn (string $key) => MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductDefinition::ENTITY_NAME) - ->withFieldSourcePath($key) - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); - } - $this->productType = (int) $data['detail']['kind']; unset($data['detail']['kind']); $isProductWithVariant = $data['configurator_set_id'] !== null; diff --git a/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php b/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php index 4298f2d2e..2da20c296 100644 --- a/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php +++ b/src/Profile/Shopware/Converter/ProductOptionRelationConverter.php @@ -44,29 +44,16 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($productContainerMapping === null) { - return new ConvertStruct(null, $this->originalData); - } - $this->mappingIds[] = $productContainerMapping['id']; - - $optionMapping = $this->mappingService->getMapping( - $this->connectionId, - DefaultEntities::PROPERTY_GROUP_OPTION, - Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'), - $context - ); - - if ($optionMapping === null) { - return new ConvertStruct(null, $this->originalData); + $relationMapping = null; + if ($productContainerMapping !== null) { + $this->mappingIds[] = $productContainerMapping['id']; + $relationMapping = $this->mappingService->getMapping( + $this->connectionId, + DefaultEntities::PRODUCT_PROPERTY, + $data['id'] . '_' . $productContainerMapping['entityId'], + $context + ); } - $this->mappingIds[] = $optionMapping['id']; - - $relationMapping = $this->mappingService->getMapping( - $this->connectionId, - DefaultEntities::PRODUCT_PROPERTY, - $data['id'] . '_' . $productContainerMapping['entityId'], - $context - ); // use "old" relation mapping if exists < v.1.3 if ($relationMapping !== null) { @@ -88,12 +75,27 @@ public function convert(array $data, Context $context, MigrationContextInterface ); } + $optionMapping = $this->mappingService->getMapping( + $this->connectionId, + DefaultEntities::PROPERTY_GROUP_OPTION, + Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'), + $context + ); + $converted = []; - $converted['id'] = $productContainerMapping['entityId']; - $converted['configuratorSettings'][] = [ - 'id' => $this->mainMapping['entityId'], - 'optionId' => $optionMapping['entityId'], - ]; + + if ($optionMapping !== null) { + $this->mappingIds[] = $optionMapping['id']; + $converted['configuratorSettings'][] = [ + 'id' => $this->mainMapping['entityId'], + 'optionId' => $optionMapping['entityId'], + ]; + } + + if (isset($productContainerMapping['entityId'])) { + $converted['id'] = $productContainerMapping['entityId']; + } + $this->updateMainMapping($migrationContext, $context); return new ConvertStruct($converted, null, $this->mainMapping['id'] ?? null); diff --git a/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php b/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php index 2ef841a17..75d6c9289 100644 --- a/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php +++ b/src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php @@ -40,6 +40,7 @@ public function convert(array $data, Context $context, MigrationContextInterface $connection = $migrationContext->getConnection(); $this->connectionId = $connection->getId(); + $converted = []; $productMapping = $this->mappingService->getMapping( $this->connectionId, DefaultEntities::PRODUCT_CONTAINER, @@ -54,12 +55,13 @@ public function convert(array $data, Context $context, MigrationContextInterface $data['productId'], $context ); + } - if ($productMapping === null) { - return new ConvertStruct(null, $this->originalData); - } + if ($productMapping !== null) { + $this->mappingIds[] = $productMapping['id']; + $converted['id'] = $productMapping['entityId']; } - $this->mappingIds[] = $productMapping['id']; + $optionMapping = $this->mappingService->getMapping( $this->connectionId, DefaultEntities::PROPERTY_GROUP_OPTION, @@ -67,10 +69,14 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($optionMapping === null) { - return new ConvertStruct(null, $this->originalData); + if ($optionMapping !== null) { + $this->mappingIds[] = $optionMapping['id']; + + $converted['properties'][] = [ + 'id' => $optionMapping['entityId'], + ]; } - $this->mappingIds[] = $optionMapping['id']; + $this->mainMapping = $this->mappingService->getOrCreateMapping( $this->connectionId, DefaultEntities::PRODUCT_PROPERTY_RELATION, @@ -78,12 +84,6 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - $converted = []; - $converted['id'] = $productMapping['entityId']; - $converted['properties'][] = [ - 'id' => $optionMapping['entityId'], - ]; - $this->updateMainMapping($migrationContext, $context); return new ConvertStruct($converted, null, $this->mainMapping['id'] ?? null); diff --git a/src/Profile/Shopware/Converter/ProductReviewConverter.php b/src/Profile/Shopware/Converter/ProductReviewConverter.php index 23fd1da6d..c0efbc6bd 100644 --- a/src/Profile/Shopware/Converter/ProductReviewConverter.php +++ b/src/Profile/Shopware/Converter/ProductReviewConverter.php @@ -7,14 +7,10 @@ namespace SwagMigrationAssistant\Profile\Shopware\Converter; -use Shopware\Core\Content\Product\Aggregate\ProductReview\ProductReviewDefinition; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; @@ -23,14 +19,6 @@ #[Package('fundamentals@after-sales')] abstract class ProductReviewConverter extends ShopwareConverter { - /** - * @var list - */ - protected array $requiredDataFieldKeys = [ - '_locale', - 'articleID', - ]; - public function __construct( MappingServiceInterface $mappingService, LoggingServiceInterface $loggingService, @@ -41,27 +29,16 @@ public function __construct( public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct { - $fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys); - $connection = $migrationContext->getConnection(); $connectionId = $connection->getId(); - if (!empty($fields)) { - $this->loggingService->addLogForEach( - $fields, - fn (string $key) => MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductReviewDefinition::ENTITY_NAME) - ->withFieldSourcePath($key) - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); + $this->generateChecksum($data); - return new ConvertStruct(null, $data); + $mainLocale = null; + if (isset($data['_locale'])) { + $mainLocale = $data['_locale']; + unset($data['_locale']); } - $this->generateChecksum($data); - $originalData = $data; - $mainLocale = $data['_locale']; - unset($data['_locale']); $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( @@ -71,13 +48,14 @@ public function convert(array $data, Context $context, MigrationContextInterface $context, $this->checksum ); + $converted['id'] = $this->mainMapping['entityId']; unset($data['id']); $mapping = $this->mappingService->getMapping( $connectionId, DefaultEntities::PRODUCT_MAIN, - $data['articleID'], + $data['articleID'] ?? '', $context ); @@ -85,27 +63,16 @@ public function convert(array $data, Context $context, MigrationContextInterface $mapping = $this->mappingService->getMapping( $connectionId, DefaultEntities::PRODUCT_CONTAINER, - $data['articleID'], + $data['articleID'] ?? '', $context ); + } - if ($mapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductReviewDefinition::ENTITY_NAME) - ->withFieldName('productId') - ->withFieldSourcePath('articleID') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); - } + if ($mapping !== null) { + $converted['productId'] = $mapping['entityId']; + $this->mappingIds[] = $mapping['id']; + unset($data['articleID']); } - $converted['productId'] = $mapping['entityId']; - $this->mappingIds[] = $mapping['id']; - unset($data['articleID']); if (isset($data['email'])) { $mapping = $this->mappingService->getMapping( @@ -120,6 +87,7 @@ public function convert(array $data, Context $context, MigrationContextInterface $this->mappingIds[] = $mapping['id']; } } + $this->convertValue($converted, 'externalEmail', $data, 'email'); $this->convertValue($converted, 'externalUser', $data, 'name'); @@ -131,37 +99,13 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($mapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductReviewDefinition::ENTITY_NAME) - ->withFieldName('salesChannelId') - ->withFieldSourcePath('shop_id') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); + if ($mapping !== null) { + $converted['salesChannelId'] = $mapping['entityId']; + $this->mappingIds[] = $mapping['id']; + unset($data['shop_id'], $data['mainShopId']); } - $converted['salesChannelId'] = $mapping['entityId']; - $this->mappingIds[] = $mapping['id']; - unset($data['shop_id'], $data['mainShopId']); $converted['languageId'] = $this->languageLookup->get($mainLocale, $context); - if ($converted['languageId'] === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ProductReviewDefinition::ENTITY_NAME) - ->withFieldName('languageId') - ->withFieldSourcePath('_locale') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); - } $this->convertValue($converted, 'title', $data, 'headline'); if (empty($converted['title'])) { diff --git a/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php b/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php index bbf4b87e0..9dd355a16 100644 --- a/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php +++ b/src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php @@ -15,7 +15,6 @@ use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\Log\CannotConvertChildEntityLog; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; @@ -76,42 +75,29 @@ public function convert(array $data, Context $context, MigrationContextInterface $connection = $migrationContext->getConnection(); $this->connectionId = $connection->getId(); - - if (!isset($data['group']['name'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(PropertyGroupDefinition::ENTITY_NAME) - ->withFieldName('id') - ->withFieldSourcePath('group.name') - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) + $converted = []; + if (isset($data['group']['name'])) { + $mapping = $this->mappingService->getOrCreateMapping( + $this->connectionId, + DefaultEntities::PROPERTY_GROUP_OPTION, + Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'), + $context ); + $this->mappingIds[] = $mapping['id']; - return new ConvertStruct(null, $data); - } - - $mapping = $this->mappingService->getOrCreateMapping( - $this->connectionId, - DefaultEntities::PROPERTY_GROUP_OPTION, - Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'), - $context - ); - $this->mappingIds[] = $mapping['id']; - - $propertyGroupMapping = $this->mappingService->getOrCreateMapping( - $this->connectionId, - DefaultEntities::PROPERTY_GROUP, - Hasher::hash(\mb_strtolower($data['group']['name']), 'md5'), - $context - ); - $this->mappingIds[] = $propertyGroupMapping['id']; + $propertyGroupMapping = $this->mappingService->getOrCreateMapping( + $this->connectionId, + DefaultEntities::PROPERTY_GROUP, + Hasher::hash(\mb_strtolower($data['group']['name']), 'md5'), + $context + ); + $this->mappingIds[] = $propertyGroupMapping['id']; - $converted = [ - 'id' => $mapping['entityId'], - 'group' => [ + $converted['id'] = $mapping['entityId']; + $converted['group'] = [ 'id' => $propertyGroupMapping['entityId'], - ], - ]; + ]; + } $this->createAndDeleteNecessaryMappings($data, $converted); diff --git a/src/Profile/Shopware/Converter/SalesChannelConverter.php b/src/Profile/Shopware/Converter/SalesChannelConverter.php index 88e88e727..037c89f3e 100644 --- a/src/Profile/Shopware/Converter/SalesChannelConverter.php +++ b/src/Profile/Shopware/Converter/SalesChannelConverter.php @@ -23,7 +23,6 @@ use Shopware\Core\System\SalesChannel\SalesChannelDefinition; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\CurrencyLookup; @@ -96,40 +95,21 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($customerGroupMapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SalesChannelDefinition::ENTITY_NAME) - ->withFieldName('customerGroupId') - ->withFieldSourcePath('customer_group_id') - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $data); + if ($customerGroupMapping !== null) { + $this->mappingIds[] = $customerGroupMapping['id']; + $converted['customerGroupId'] = $customerGroupMapping['entityId']; } - $customerGroupUuid = $customerGroupMapping['entityId']; - $this->mappingIds[] = $customerGroupMapping['id']; - $converted['customerGroupId'] = $customerGroupUuid; $languageUuid = $this->languageLookup->get($data['locale'], $context); - if ($languageUuid === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SalesChannelDefinition::ENTITY_NAME) - ->withFieldName('languageId') - ->withFieldSourcePath('locale') - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $data); + if ($languageUuid !== null) { + $converted['languageId'] = $languageUuid; + $converted['languages'] = $this->getSalesChannelLanguages($languageUuid, $data, $context); } - $converted['languageId'] = $languageUuid; - $converted['languages'] = $this->getSalesChannelLanguages($languageUuid, $data, $context); + if (isset($converted['languages'])) { + $this->filterExistingLanguageSalesChannelRelation($converted['id'], $converted['languages']); + } - $this->filterExistingLanguageSalesChannelRelation($converted['id'], $converted['languages']); $this->filterDisabledPackLanguages($converted); if (empty($converted['languages'])) { @@ -137,26 +117,15 @@ public function convert(array $data, Context $context, MigrationContextInterface } $currencyUuid = $this->currencyLookup->get($data['currency'], $context); - if ($currencyUuid === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SalesChannelDefinition::ENTITY_NAME) - ->withFieldName('currencyId') - ->withFieldSourcePath('currency') - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $data); + if ($currencyUuid !== null) { + $converted['currencyId'] = $currencyUuid; + $converted['currencies'] = [ + [ + 'id' => $currencyUuid, + ], + ]; } - $converted['currencyId'] = $currencyUuid; - $converted['currencies'] = [ - [ - 'id' => $currencyUuid, - ], - ]; - $categoryMapping = $this->mappingService->getMapping( $this->connectionId, DefaultEntities::CATEGORY, @@ -164,21 +133,10 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($categoryMapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SalesChannelDefinition::ENTITY_NAME) - ->withFieldName('navigationCategoryId') - ->withFieldSourcePath('category_id') - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $data); + if ($categoryMapping !== null) { + $this->mappingIds[] = $categoryMapping['id']; + $converted['navigationCategoryId'] = $categoryMapping['entityId']; } - $categoryUuid = $categoryMapping['entityId']; - $this->mappingIds[] = $categoryMapping['id']; - $converted['navigationCategoryId'] = $categoryUuid; $countryUuid = $this->getFirstActiveCountryId(); $converted['countryId'] = $countryUuid; diff --git a/src/Profile/Shopware/Converter/SeoUrlConverter.php b/src/Profile/Shopware/Converter/SeoUrlConverter.php index e1ead8955..3c3ffde91 100644 --- a/src/Profile/Shopware/Converter/SeoUrlConverter.php +++ b/src/Profile/Shopware/Converter/SeoUrlConverter.php @@ -7,18 +7,14 @@ namespace SwagMigrationAssistant\Profile\Shopware\Converter; -use Shopware\Core\Content\Seo\SeoUrl\SeoUrlDefinition; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; -use SwagMigrationAssistant\Profile\Shopware\Logging\Log\UnsupportedSeoUrlTypeLog; #[Package('fundamentals@after-sales')] abstract class SeoUrlConverter extends ShopwareConverter @@ -42,7 +38,6 @@ public function __construct( public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct { $this->generateChecksum($data); - $originalData = $data; $connection = $migrationContext->getConnection(); $this->connectionId = $connection->getId(); @@ -65,39 +60,17 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($mapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SeoUrlDefinition::ENTITY_NAME) - ->withFieldName('salesChannelId') - ->withFieldSourcePath('subshopID') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); + if ($mapping !== null) { + $converted['salesChannelId'] = $mapping['entityId']; + $this->mappingIds[] = $mapping['id']; + unset($data['subshopID']); } - $converted['salesChannelId'] = $mapping['entityId']; - $this->mappingIds[] = $mapping['id']; - unset($data['subshopID']); $converted['languageId'] = $this->languageLookup->get($data['_locale'], $context); - if ($converted['languageId'] === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SeoUrlDefinition::ENTITY_NAME) - ->withFieldName('languageId') - ->withFieldSourcePath('_locale') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); + if ($converted['languageId'] !== null) { + $this->mappingIds[] = $converted['languageId']; + unset($data['_locale']); } - $this->mappingIds[] = $converted['languageId']; - unset($data['_locale']); if ($data['type'] === self::TYPE_PRODUCT && isset($data['typeId'])) { $mapping = $this->mappingService->getMapping( @@ -114,25 +87,14 @@ public function convert(array $data, Context $context, MigrationContextInterface $data['typeId'], $context ); - - if ($mapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SeoUrlDefinition::ENTITY_NAME) - ->withFieldName('foreignKey') - ->withFieldSourcePath('type') - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); - } } - $converted['foreignKey'] = $mapping['entityId']; - $converted['routeName'] = self::ROUTE_NAME_PRODUCT; - $converted['pathInfo'] = '/detail/' . $mapping['entityId']; - $this->mappingIds[] = $mapping['id']; + if ($mapping !== null) { + $converted['foreignKey'] = $mapping['entityId']; + $converted['routeName'] = self::ROUTE_NAME_PRODUCT; + $converted['pathInfo'] = '/detail/' . $mapping['entityId']; + $this->mappingIds[] = $mapping['id']; + } } elseif ($data['type'] === self::TYPE_CATEGORY && isset($data['typeId'])) { $mapping = $this->mappingService->getMapping( $this->connectionId, @@ -141,33 +103,12 @@ public function convert(array $data, Context $context, MigrationContextInterface $context ); - if ($mapping === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SeoUrlDefinition::ENTITY_NAME) - ->withFieldName('foreignKey') - ->withFieldSourcePath('type') - ->withSourceData($data) - ->build(AssociationRequiredMissingLog::class) - ); - - return new ConvertStruct(null, $originalData); + if ($mapping !== null) { + $converted['foreignKey'] = $mapping['entityId']; + $converted['routeName'] = self::ROUTE_NAME_NAVIGATION; + $converted['pathInfo'] = '/navigation/' . $mapping['entityId']; + $this->mappingIds[] = $mapping['id']; } - $converted['foreignKey'] = $mapping['entityId']; - $converted['routeName'] = self::ROUTE_NAME_NAVIGATION; - $converted['pathInfo'] = '/navigation/' . $mapping['entityId']; - $this->mappingIds[] = $mapping['id']; - } else { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(SeoUrlDefinition::ENTITY_NAME) - ->withFieldName('foreignKey') - ->withFieldSourcePath('type') - ->withSourceData($data) - ->build(UnsupportedSeoUrlTypeLog::class) - ); - - return new ConvertStruct(null, $originalData); } unset($data['type'], $data['typeId']); diff --git a/src/Profile/Shopware/Converter/ShippingMethodConverter.php b/src/Profile/Shopware/Converter/ShippingMethodConverter.php index 5917e4e95..1c9c69d7e 100644 --- a/src/Profile/Shopware/Converter/ShippingMethodConverter.php +++ b/src/Profile/Shopware/Converter/ShippingMethodConverter.php @@ -74,13 +74,6 @@ abstract class ShippingMethodConverter extends ShopwareConverter protected string $mainLocale; - /** - * @var array - */ - protected array $requiredDataFields = [ - 'deliveryTimeId' => 'delivery_time', - ]; - public function __construct( MappingServiceInterface $mappingService, LoggingServiceInterface $loggingService, @@ -95,26 +88,17 @@ public function convert(array $data, Context $context, MigrationContextInterface $connection = $migrationContext->getConnection(); $this->connectionId = $connection->getId(); - if (empty($data['id'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ShippingMethodDefinition::ENTITY_NAME) - ->withFieldName('id') - ->withFieldSourcePath('id') - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); - } - $this->generateChecksum($data); $this->context = $context; $this->runId = $migrationContext->getRunUuid(); - $this->oldShippingMethod = $data['id']; + $converted = []; + + if (!empty($data['id'])) { + $this->oldShippingMethod = $data['id']; + } + $this->mainLocale = $data['_locale']; - $converted = []; $this->mainMapping = $this->mappingService->getOrCreateMapping( $this->connectionId, DefaultEntities::SHIPPING_METHOD, @@ -148,20 +132,6 @@ public function convert(array $data, Context $context, MigrationContextInterface $this->mappingIds[] = $defaultAvailabilityRuleUuid['id']; } - $fields = $this->checkForEmptyRequiredConvertedFields($converted, $this->requiredDataFields); - if (!empty($fields)) { - $this->loggingService->addLogForEach( - $fields, - fn (string $key) => MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withFieldName(ShippingMethodDefinition::ENTITY_NAME) - ->withFieldSourcePath($key) - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); - } - $converted['technicalName'] = 'migrated_' . $data['id']; $this->addShippingMethodTranslation($converted, $data); @@ -246,19 +216,6 @@ public function convert(array $data, Context $context, MigrationContextInterface } $this->updateMainMapping($migrationContext, $context); - if (!\is_array($this->mainMapping) || !\array_key_exists('id', $this->mainMapping)) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName(ShippingMethodDefinition::ENTITY_NAME) - ->withFieldName('id') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); - } - return new ConvertStruct($converted, $returnData, $this->mainMapping['id'] ?? null); } diff --git a/src/Profile/Shopware/Converter/ShopwareConverter.php b/src/Profile/Shopware/Converter/ShopwareConverter.php index b4766d28d..e0549101f 100644 --- a/src/Profile/Shopware/Converter/ShopwareConverter.php +++ b/src/Profile/Shopware/Converter/ShopwareConverter.php @@ -92,24 +92,6 @@ protected function checkForEmptyRequiredDataFields(array $rawData, array $requir return $emptyFields; } - /** - * @param array $converted - * @param array $requiredDataFields - * - * @return list - */ - protected function checkForEmptyRequiredConvertedFields(array $converted, array $requiredDataFields): array - { - $emptyFields = []; - foreach ($requiredDataFields as $requiredDataFieldKey => $requiredDataFieldValue) { - if (!isset($converted[$requiredDataFieldKey]) || $converted[$requiredDataFieldKey] === '') { - $emptyFields[] = $requiredDataFieldValue; - } - } - - return $emptyFields; - } - protected function validDate(string $value): bool { try { diff --git a/src/Profile/Shopware/Converter/TranslationConverter.php b/src/Profile/Shopware/Converter/TranslationConverter.php index 5754a2eb7..9a0ee0ab5 100644 --- a/src/Profile/Shopware/Converter/TranslationConverter.php +++ b/src/Profile/Shopware/Converter/TranslationConverter.php @@ -28,7 +28,6 @@ use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog; use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; -use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog; use SwagMigrationAssistant\Migration\Logging\Log\InvalidUnserializedDataLog; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup; @@ -66,19 +65,6 @@ public function convert( $connection = $migrationContext->getConnection(); $this->connectionId = $connection->getId(); - if (!isset($data['locale'])) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($migrationContext) - ->withEntityName('unknown_translation') - ->withFieldName('languageId') - ->withFieldSourcePath('locale') - ->withSourceData($data) - ->build(EmptyNecessaryFieldRunLog::class) - ); - - return new ConvertStruct(null, $data); - } - switch ($data['objecttype']) { case 'article': return $this->createProductTranslation($data); @@ -213,10 +199,12 @@ protected function createProductTranslation(array &$data): ConvertStruct $productTranslation['id'] = $this->mainMapping['entityId']; unset($data['id']); - $languageUuid = $this->languageLookup->get($data['locale'], $this->context); - if ($languageUuid !== null) { - $productTranslation['languageId'] = $languageUuid; - $product['translations'][$languageUuid] = $productTranslation; + if (isset($data['locale'])) { + $languageUuid = $this->languageLookup->get($data['locale'], $this->context); + if ($languageUuid !== null) { + $productTranslation['languageId'] = $languageUuid; + $product['translations'][$languageUuid] = $productTranslation; + } } unset($data['name'], $data['locale']); diff --git a/src/Profile/Shopware6/Converter/CategoryCmsPageAssociationConverter.php b/src/Profile/Shopware6/Converter/CategoryCmsPageAssociationConverter.php index 4ace86477..c0af9a249 100644 --- a/src/Profile/Shopware6/Converter/CategoryCmsPageAssociationConverter.php +++ b/src/Profile/Shopware6/Converter/CategoryCmsPageAssociationConverter.php @@ -40,10 +40,9 @@ protected function convertData(array $data): ConvertStruct $this->context ); - if ($mapping === null) { - return new ConvertStruct(null, $converted); + if ($mapping !== null) { + $converted['cmsPageId'] = $mapping['entityId']; } - $converted['cmsPageId'] = $mapping['entityId']; } return new ConvertStruct($converted, null, $this->mainMapping['id']); diff --git a/src/Profile/Shopware6/Converter/CmsPageConverter.php b/src/Profile/Shopware6/Converter/CmsPageConverter.php index d9dceea0f..fc63452bd 100644 --- a/src/Profile/Shopware6/Converter/CmsPageConverter.php +++ b/src/Profile/Shopware6/Converter/CmsPageConverter.php @@ -34,20 +34,18 @@ public function supports(MigrationContextInterface $migrationContext): bool && $this->getDataSetEntity($migrationContext) === CmsPageDataSet::getEntity(); } - protected function convertData(array $data): ConvertStruct + protected function convertData(array $data): ?ConvertStruct { - $converted = $data; - // handle locked default layouts - if (isset($converted['locked']) && $converted['locked'] === true) { + if (isset($data['locked']) && $data['locked'] === true) { $cmsPageMapping = $this->mappingService->getMapping($this->connectionId, DefaultEntities::CMS_PAGE, $data['id'], $this->context); if ($cmsPageMapping !== null) { - return new ConvertStruct(null, $data, $cmsPageMapping['id']); + return null; } $cmpPageUuid = $this->cmsPageLookup->getLockedByNamesAndType( - \array_column($converted['translations'], 'name'), - $converted['type'], + \array_column($data['translations'], 'name'), + $data['type'], $this->context ); @@ -60,9 +58,11 @@ protected function convertData(array $data): ConvertStruct $cmpPageUuid, ); - return new ConvertStruct(null, $data); + return null; } + $converted = $data; + $this->updateTranslations($converted); $this->mainMapping = $this->getOrCreateMappingMainCompleteFacade( DefaultEntities::CMS_PAGE, diff --git a/src/Profile/Shopware6/Converter/CustomerWishlistConverter.php b/src/Profile/Shopware6/Converter/CustomerWishlistConverter.php index 38df224eb..9a65a772d 100644 --- a/src/Profile/Shopware6/Converter/CustomerWishlistConverter.php +++ b/src/Profile/Shopware6/Converter/CustomerWishlistConverter.php @@ -35,12 +35,12 @@ protected function convertData(array $data): ConvertStruct $customerMapping = $this->getMappingIdFacade(DefaultEntities::CUSTOMER, $converted['customerId']); if ($customerMapping === null) { - return new ConvertStruct(null, $data); + $converted['customerId'] = null; } $salesChannelMapping = $this->getMappingIdFacade(DefaultEntities::SALES_CHANNEL, $converted['salesChannelId']); if ($salesChannelMapping === null) { - return new ConvertStruct(null, $data); + $converted['salesChannelId'] = null; } // products association could be empty and thus this array key might not be set diff --git a/src/Profile/Shopware6/Converter/DocumentBaseConfigConverter.php b/src/Profile/Shopware6/Converter/DocumentBaseConfigConverter.php index c7855cafc..9ce720233 100644 --- a/src/Profile/Shopware6/Converter/DocumentBaseConfigConverter.php +++ b/src/Profile/Shopware6/Converter/DocumentBaseConfigConverter.php @@ -7,11 +7,9 @@ namespace SwagMigrationAssistant\Profile\Shopware6\Converter; -use Shopware\Core\Checkout\Document\Aggregate\DocumentBaseConfig\DocumentBaseConfigDefinition; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\DocumentTypeLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\GlobalDocumentBaseConfigLookup; @@ -19,7 +17,6 @@ use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\DocumentBaseConfigDataSet; -use SwagMigrationAssistant\Profile\Shopware6\Logging\Log\UnsupportedDocumentTypeLog; use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; #[Package('fundamentals@after-sales')] @@ -58,26 +55,15 @@ protected function convertData(array $data): ConvertStruct $converted = $data; $converted['documentTypeId'] = $this->documentTypeLookup->get($converted['documentType']['technicalName'], $this->context); - if ($converted['documentTypeId'] === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($this->migrationContext) - ->withEntityName(DocumentBaseConfigDefinition::ENTITY_NAME) - ->withFieldName('documentTypeId') - ->withFieldSourcePath('id') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(UnsupportedDocumentTypeLog::class) - ); - - return new ConvertStruct(null, $data, $converted['id'] ?? null); - } - unset($converted['documentType']); - - if ($data['global']) { - $converted['id'] = $this->globalDocumentBaseConfigLookup->get($converted['documentTypeId'], $this->context); - if ($converted['id'] === null) { - $converted['id'] = $data['id']; + if ($converted['documentTypeId'] !== null) { + if ($data['global']) { + $converted['id'] = $this->globalDocumentBaseConfigLookup->get($converted['documentTypeId'], $this->context); + if ($converted['id'] === null) { + $converted['id'] = $data['id']; + } } + + unset($converted['documentType']); } $this->mainMapping = $this->getOrCreateMappingMainCompleteFacade( diff --git a/src/Profile/Shopware6/Converter/DocumentConverter.php b/src/Profile/Shopware6/Converter/DocumentConverter.php index b39403992..9885b3bc4 100644 --- a/src/Profile/Shopware6/Converter/DocumentConverter.php +++ b/src/Profile/Shopware6/Converter/DocumentConverter.php @@ -7,18 +7,15 @@ namespace SwagMigrationAssistant\Profile\Shopware6\Converter; -use Shopware\Core\Checkout\Document\DocumentDefinition; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\DocumentTypeLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\DocumentDataSet; -use SwagMigrationAssistant\Profile\Shopware6\Logging\Log\UnsupportedDocumentTypeLog; use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; #[Package('fundamentals@after-sales')] @@ -64,23 +61,12 @@ protected function convertData(array $data): ConvertStruct ); $converted['documentTypeId'] = $this->documentTypeLookup->get($converted['documentType']['technicalName'], $this->context); - if ($converted['documentTypeId'] === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($this->migrationContext) - ->withEntityName(DocumentDefinition::ENTITY_NAME) - ->withFieldName('documentTypeId') - ->withFieldSourcePath('id') - ->withSourceData($data) - ->withConvertedData($converted) - ->build(UnsupportedDocumentTypeLog::class) - ); - - return new ConvertStruct(null, $data, $this->mainMapping['id'] ?? null); - } - unset($converted['documentType']); + if ($converted['documentTypeId'] !== null) { + if (isset($converted['config']['documentTypeId'])) { + $converted['config']['documentTypeId'] = $converted['documentTypeId']; + } - if (isset($converted['config']['documentTypeId'])) { - $converted['config']['documentTypeId'] = $converted['documentTypeId']; + unset($converted['documentType']); } if (isset($converted['documentMediaFile'])) { diff --git a/src/Profile/Shopware6/Converter/MailTemplateConverter.php b/src/Profile/Shopware6/Converter/MailTemplateConverter.php index b82613b9b..4aaa75c19 100644 --- a/src/Profile/Shopware6/Converter/MailTemplateConverter.php +++ b/src/Profile/Shopware6/Converter/MailTemplateConverter.php @@ -7,18 +7,15 @@ namespace SwagMigrationAssistant\Profile\Shopware6\Converter; -use Shopware\Core\Content\MailTemplate\MailTemplateDefinition; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\MailTemplateTypeLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\SystemDefaultMailTemplateLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; -use SwagMigrationAssistant\Profile\Shopware\Logging\Log\UnsupportedMailTemplateTypeLog; use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\MailTemplateDataSet; use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; @@ -65,33 +62,23 @@ protected function convertData(array $data): ConvertStruct $typeUuid = $mailTemplateTypeMapping['entityId']; } else { $typeUuid = $this->mailTemplateTypeLookup->get($converted['mailTemplateType']['technicalName'], $this->context); - if ($typeUuid === null) { - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($this->migrationContext) - ->withEntityName(MailTemplateDefinition::ENTITY_NAME) - ->withFieldName('mailTemplateTypeId') - ->withFieldSourcePath('mailTemplateType.technicalName') - ->build(UnsupportedMailTemplateTypeLog::class) + if ($typeUuid !== null) { + $this->mappingService->createMapping( + $this->connectionId, + DefaultEntities::MAIL_TEMPLATE_TYPE, + $data['mailTemplateTypeId'], + $this->checksum, + null, + $typeUuid, ); - - return new ConvertStruct(null, $data, $converted['id'] ?? null); } - - $this->mappingService->createMapping( - $this->connectionId, - DefaultEntities::MAIL_TEMPLATE_TYPE, - $data['mailTemplateTypeId'], - $this->checksum, - null, - $typeUuid, - ); } - unset($converted['mailTemplateType']); $converted['mailTemplateTypeId'] = $typeUuid; + unset($converted['mailTemplateType']); } - if ($data['systemDefault']) { + if ($data['systemDefault'] && isset($converted['mailTemplateTypeId'])) { $defaultMailTemplateMapping = $this->mappingService->getMapping($this->connectionId, DefaultEntities::MAIL_TEMPLATE, $data['id'], $this->context); if ($defaultMailTemplateMapping !== null) { $defaultMailTemplateUuid = $defaultMailTemplateMapping['entityId']; diff --git a/src/Profile/Shopware6/Converter/MediaFolderConverter.php b/src/Profile/Shopware6/Converter/MediaFolderConverter.php index 4187fbd9d..3bd90dc13 100644 --- a/src/Profile/Shopware6/Converter/MediaFolderConverter.php +++ b/src/Profile/Shopware6/Converter/MediaFolderConverter.php @@ -39,7 +39,7 @@ public function supports(MigrationContextInterface $migrationContext): bool && $this->getDataSetEntity($migrationContext) === MediaFolderDataSet::getEntity(); } - protected function convertData(array $data): ConvertStruct + protected function convertData(array $data): ?ConvertStruct { $converted = $data; @@ -53,7 +53,7 @@ protected function convertData(array $data): ConvertStruct // edge case for hidden download products media folder // this doesn't need to be migrated, just map the files into it // otherwise the code below would lead to a self-referential parentId - return new ConvertStruct(null, $data, $this->mainMapping['id'] ?? null); + return null; } if (isset($converted['defaultFolder'])) { diff --git a/src/Profile/Shopware6/Converter/NumberRangeConverter.php b/src/Profile/Shopware6/Converter/NumberRangeConverter.php index da7a38f0d..1eecdb219 100644 --- a/src/Profile/Shopware6/Converter/NumberRangeConverter.php +++ b/src/Profile/Shopware6/Converter/NumberRangeConverter.php @@ -12,16 +12,13 @@ use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; use Shopware\Core\Framework\Log\Package; use Shopware\Core\System\NumberRange\Aggregate\NumberRangeState\NumberRangeStateCollection; -use Shopware\Core\System\NumberRange\NumberRangeDefinition; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\NumberRangeLookup; use SwagMigrationAssistant\Migration\Mapping\Lookup\NumberRangeTypeLookup; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; -use SwagMigrationAssistant\Profile\Shopware\Logging\Log\UnsupportedNumberRangeTypeLog; use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\NumberRangeDataSet; use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; @@ -57,31 +54,13 @@ protected function convertData(array $data): ConvertStruct $typeUuid = $numberRangeTypeMapping['entityId']; } else { $typeUuid = $this->numberRangeTypeLookup->get($converted['type']['technicalName'], $this->context); - if ($typeUuid === null) { - $this->mainMapping = $this->getOrCreateMappingMainCompleteFacade( - DefaultEntities::NUMBER_RANGE, - $data['id'], - $data['id'] - ); - - $this->loggingService->addLogEntry( - MigrationLogBuilder::fromMigrationContext($this->migrationContext) - ->withEntityName(NumberRangeDefinition::ENTITY_NAME) - ->withFieldName('typeId') - ->withFieldSourcePath('id') - ->withSourceData($data) - ->build(UnsupportedNumberRangeTypeLog::class) - ); - - return new ConvertStruct(null, $data, $this->mainMapping['id'] ?? null); - } } if ($converted['global']) { $this->checkForExistingNumberRange($converted); } - if (isset($converted['numberRangeSalesChannels'])) { + if (isset($converted['numberRangeSalesChannels']) && $typeUuid !== null) { foreach ($converted['numberRangeSalesChannels'] as &$numberRangeSalesChannel) { $numberRangeSalesChannel['numberRangeTypeId'] = $typeUuid; } diff --git a/src/Profile/Shopware6/Converter/ProductSortingConverter.php b/src/Profile/Shopware6/Converter/ProductSortingConverter.php index 459b285f4..024b3a607 100644 --- a/src/Profile/Shopware6/Converter/ProductSortingConverter.php +++ b/src/Profile/Shopware6/Converter/ProductSortingConverter.php @@ -34,7 +34,7 @@ public function supports(MigrationContextInterface $migrationContext): bool && $this->getDataSetEntity($migrationContext) === ProductSortingDataSet::getEntity(); } - protected function convertData(array $data): ConvertStruct + protected function convertData(array $data): ?ConvertStruct { $converted = $data; $productSortingUuid = $this->productSortingLookup->get($data['key'], $this->context); @@ -50,7 +50,7 @@ protected function convertData(array $data): ConvertStruct ); if ($this->productSortingLookup->getIsLocked($data['key'], $this->context)) { - return new ConvertStruct(null, $data, $this->mainMapping['id'] ?? null); + return null; } $this->updateAssociationIds( diff --git a/src/Profile/Shopware6/Converter/SeoUrlConverter.php b/src/Profile/Shopware6/Converter/SeoUrlConverter.php index 06c2224a0..c35c6c246 100644 --- a/src/Profile/Shopware6/Converter/SeoUrlConverter.php +++ b/src/Profile/Shopware6/Converter/SeoUrlConverter.php @@ -33,34 +33,37 @@ public function supports(MigrationContextInterface $migrationContext): bool && $this->getDataSetEntity($migrationContext) === SeoUrlDataSet::getEntity(); } - protected function convertData(array $data): ConvertStruct + protected function convertData(array $data): ?ConvertStruct { if (isset($data['isModified']) && $data['isModified'] === false) { - return new ConvertStruct(null, $data); + return null; } $converted = $data; if (isset($converted['foreignKey'])) { + $relatedEntity = null; if ($converted['routeName'] === self::CATEGORY_ROUTE_NAME) { $relatedEntity = DefaultEntities::CATEGORY; } elseif ($converted['routeName'] === self::PRODUCT_ROUTE_NAME) { $relatedEntity = DefaultEntities::PRODUCT; - } else { - return new ConvertStruct(null, $converted); } - $converted['foreignKey'] = $this->getMappingIdFacade( - $relatedEntity, - $converted['foreignKey'] - ); + if ($relatedEntity !== null) { + $converted['foreignKey'] = $this->getMappingIdFacade( + $relatedEntity, + $converted['foreignKey'] + ); + } } - $this->mainMapping = $this->getOrCreateMappingMainCompleteFacade( - DefaultEntities::SEO_URL, - $data['id'], - $converted['id'] - ); + if (isset($data['id']) && isset($converted['id'])) { + $this->mainMapping = $this->getOrCreateMappingMainCompleteFacade( + DefaultEntities::SEO_URL, + $data['id'], + $converted['id'] + ); + } if (isset($converted['salesChannelId'])) { $converted['salesChannelId'] = $this->getMappingIdFacade( diff --git a/src/Profile/Shopware6/Converter/ShopwareConverter.php b/src/Profile/Shopware6/Converter/ShopwareConverter.php index 7427f3c06..c9614992a 100644 --- a/src/Profile/Shopware6/Converter/ShopwareConverter.php +++ b/src/Profile/Shopware6/Converter/ShopwareConverter.php @@ -42,7 +42,7 @@ public function getSourceIdentifier(array $data): string return $data['id']; } - public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ConvertStruct + public function convert(array $data, Context $context, MigrationContextInterface $migrationContext): ?ConvertStruct { $this->context = $context; $this->migrationContext = $migrationContext; @@ -65,7 +65,7 @@ public function convert(array $data, Context $context, MigrationContextInterface /** * @param array $data */ - abstract protected function convertData(array $data): ConvertStruct; + abstract protected function convertData(array $data): ?ConvertStruct; protected function getMappingIdFacade(string $entityName, string $oldIdentifier): ?string { diff --git a/src/Profile/Shopware6/Converter/TaxRuleConverter.php b/src/Profile/Shopware6/Converter/TaxRuleConverter.php index e078f9134..e63df5d88 100644 --- a/src/Profile/Shopware6/Converter/TaxRuleConverter.php +++ b/src/Profile/Shopware6/Converter/TaxRuleConverter.php @@ -44,19 +44,17 @@ protected function convertData(array $data): ConvertStruct DefaultEntities::TAX, $converted['taxId'] ); - if ($taxId === null) { - return new ConvertStruct(null, $converted); + if ($taxId !== null) { + $converted['taxId'] = $taxId; } - $converted['taxId'] = $taxId; $countryId = $this->getMappingIdFacade( DefaultEntities::COUNTRY, $converted['countryId'] ); - if ($countryId === null) { - return new ConvertStruct(null, $converted); + if ($countryId !== null) { + $converted['countryId'] = $countryId; } - $converted['countryId'] = $countryId; $taxRuleTypeMapping = $this->mappingService->getMapping( $this->connectionId, @@ -84,11 +82,10 @@ protected function convertData(array $data): ConvertStruct } // new types can not be created due to write protection on technical name - if ($taxRuleTypeUuid === null) { - return new ConvertStruct(null, $converted); + if ($taxRuleTypeUuid !== null) { + $converted['taxRuleTypeId'] = $taxRuleTypeUuid; + unset($converted['type']); } - unset($converted['type']); - $converted['taxRuleTypeId'] = $taxRuleTypeUuid; $taxRuleId = $this->taxRuleLookup->get( $converted['taxId'], diff --git a/tests/Migration/Controller/HistoryControllerTest.php b/tests/Migration/Controller/HistoryControllerTest.php index 0a91f73f4..8a61a2597 100644 --- a/tests/Migration/Controller/HistoryControllerTest.php +++ b/tests/Migration/Controller/HistoryControllerTest.php @@ -54,13 +54,13 @@ protected function setUp(): void { $this->context = Context::createDefaultContext(); $this->runUuid = Uuid::randomHex(); - $this->historyService = $this->getContainer()->get(HistoryService::class); - $this->controller = $this->getContainer()->get(HistoryController::class); - $this->controller->setContainer($this->getContainer()); - $this->loggingRepo = $this->getContainer()->get('swag_migration_logging.repository'); + $this->historyService = static::getContainer()->get(HistoryService::class); + $this->controller = static::getContainer()->get(HistoryController::class); + $this->controller->setContainer(static::getContainer()); + $this->loggingRepo = static::getContainer()->get('swag_migration_logging.repository'); $connectionId = Uuid::randomHex(); - $connectionRepo = $this->getContainer()->get('swag_migration_connection.repository'); + $connectionRepo = static::getContainer()->get('swag_migration_connection.repository'); $credentialFields = [ 'apiUser' => 'testUser', 'apiKey' => 'testKey', @@ -83,7 +83,7 @@ protected function setUp(): void $this->context ); }); - $this->runRepo = $this->getContainer()->get('swag_migration_run.repository'); + $this->runRepo = static::getContainer()->get('swag_migration_run.repository'); $this->runRepo->create( [ [ diff --git a/tests/Migration/Controller/PremappingControllerTest.php b/tests/Migration/Controller/PremappingControllerTest.php index b884075f1..eb962522c 100644 --- a/tests/Migration/Controller/PremappingControllerTest.php +++ b/tests/Migration/Controller/PremappingControllerTest.php @@ -75,14 +75,14 @@ class PremappingControllerTest extends TestCase protected function setUp(): void { $this->context = Context::createDefaultContext(); - $connectionRepo = $this->getContainer()->get('swag_migration_connection.repository'); - $this->runRepo = $this->getContainer()->get('swag_migration_run.repository'); - $stateMachineRepo = $this->getContainer()->get('state_machine.repository'); - $stateMachineStateRepo = $this->getContainer()->get('state_machine_state.repository'); - $this->mappingRepo = $this->getContainer()->get('swag_migration_mapping.repository'); - $migrationContextFactory = $this->getContainer()->get(MigrationContextFactory::class); - - $gatewayRegistry = $this->getContainer()->get(GatewayRegistry::class); + $connectionRepo = static::getContainer()->get('swag_migration_connection.repository'); + $this->runRepo = static::getContainer()->get('swag_migration_run.repository'); + $stateMachineRepo = static::getContainer()->get('state_machine.repository'); + $stateMachineStateRepo = static::getContainer()->get('state_machine_state.repository'); + $this->mappingRepo = static::getContainer()->get('swag_migration_mapping.repository'); + $migrationContextFactory = static::getContainer()->get(MigrationContextFactory::class); + + $gatewayRegistry = static::getContainer()->get(GatewayRegistry::class); $this->createMappingService(); $this->controller = new PremappingController( @@ -120,7 +120,7 @@ protected function setUp(): void ); }); - $generalSettingRepo = $this->getContainer()->get('swag_migration_general_setting.repository'); + $generalSettingRepo = static::getContainer()->get('swag_migration_general_setting.repository'); $setting = $generalSettingRepo->searchIds(new Criteria(), $this->context)->firstId(); $generalSettingRepo->update([ @@ -283,9 +283,9 @@ private function createMappingService(): void { $this->mappingService = new MappingService( $this->mappingRepo, - $this->getContainer()->get(EntityWriter::class), - $this->getContainer()->get(SwagMigrationMappingDefinition::class), - $this->getContainer()->get(Connection::class), + static::getContainer()->get(EntityWriter::class), + static::getContainer()->get(SwagMigrationMappingDefinition::class), + static::getContainer()->get(Connection::class), new NullLogger() ); } diff --git a/tests/Migration/Converter/ConverterRegistryTest.php b/tests/Migration/Converter/ConverterRegistryTest.php index 5516056c8..9b438e432 100644 --- a/tests/Migration/Converter/ConverterRegistryTest.php +++ b/tests/Migration/Converter/ConverterRegistryTest.php @@ -140,7 +140,7 @@ class ConverterRegistryTest extends TestCase protected function setUp(): void { - $this->converterRegistry = $this->getContainer()->get(ConverterRegistry::class); + $this->converterRegistry = static::getContainer()->get(ConverterRegistry::class); } /** diff --git a/tests/Migration/DataSelection/DataSetRegistryTest.php b/tests/Migration/DataSelection/DataSetRegistryTest.php index 2e2cd1a46..a033fff80 100644 --- a/tests/Migration/DataSelection/DataSetRegistryTest.php +++ b/tests/Migration/DataSelection/DataSetRegistryTest.php @@ -41,7 +41,7 @@ protected function setUp(): void $this->connection->setProfileName(Shopware55Profile::PROFILE_NAME); $this->connection->setGatewayName(ShopwareLocalGateway::GATEWAY_NAME); $this->connection->setCredentialFields([]); - $this->dataSetRegistry = $this->getContainer()->get(DataSetRegistry::class); + $this->dataSetRegistry = static::getContainer()->get(DataSetRegistry::class); } public function testSupports(): void diff --git a/tests/Migration/Logging/LoggingServiceTest.php b/tests/Migration/Logging/LoggingServiceTest.php index 31a0d6f06..37992103a 100644 --- a/tests/Migration/Logging/LoggingServiceTest.php +++ b/tests/Migration/Logging/LoggingServiceTest.php @@ -42,10 +42,10 @@ class LoggingServiceTest extends TestCase protected function setUp(): void { $this->context = Context::createDefaultContext(); - $this->loggingRepo = $this->getContainer()->get('swag_migration_logging.repository'); + $this->loggingRepo = static::getContainer()->get('swag_migration_logging.repository'); $this->loggingService = new LoggingService($this->loggingRepo, new NullLogger()); - $runRepo = $this->getContainer()->get('swag_migration_run.repository'); + $runRepo = static::getContainer()->get('swag_migration_run.repository'); $this->runUuid = Uuid::randomHex(); $runRepo->create( [ diff --git a/tests/Migration/Mapping/Lookup/CmsPageLookupTest.php b/tests/Migration/Mapping/Lookup/CmsPageLookupTest.php index 4a2ce2209..0b59634cd 100644 --- a/tests/Migration/Mapping/Lookup/CmsPageLookupTest.php +++ b/tests/Migration/Mapping/Lookup/CmsPageLookupTest.php @@ -160,7 +160,7 @@ public static function getGetByNamesDatabaseData(): array private function getCmsPageLookup(): CmsPageLookup { - return $this->getContainer()->get(CmsPageLookup::class); + return static::getContainer()->get(CmsPageLookup::class); } private function getMockedCmsPageLookup(): CmsPageLookup diff --git a/tests/Migration/Mapping/Lookup/CountryLookupTest.php b/tests/Migration/Mapping/Lookup/CountryLookupTest.php index 143ec5bb7..944ec9b8d 100644 --- a/tests/Migration/Mapping/Lookup/CountryLookupTest.php +++ b/tests/Migration/Mapping/Lookup/CountryLookupTest.php @@ -147,7 +147,7 @@ private static function getDatabaseData(): array private function getCountryLookup(): CountryLookup { - $countryLookup = $this->getContainer()->get(CountryLookup::class); + $countryLookup = static::getContainer()->get(CountryLookup::class); static::assertInstanceOf(CountryLookup::class, $countryLookup); return $countryLookup; diff --git a/tests/Migration/Mapping/Lookup/CountryStateLookupTest.php b/tests/Migration/Mapping/Lookup/CountryStateLookupTest.php index 2c904c97e..c2f3c91bd 100644 --- a/tests/Migration/Mapping/Lookup/CountryStateLookupTest.php +++ b/tests/Migration/Mapping/Lookup/CountryStateLookupTest.php @@ -96,7 +96,7 @@ public static function getDatabaseData(): array private function getCountryStateLookup(): CountryStateLookup { - $countryStateLookup = $this->getContainer()->get(CountryStateLookup::class); + $countryStateLookup = static::getContainer()->get(CountryStateLookup::class); static::assertInstanceOf(CountryStateLookup::class, $countryStateLookup); return $countryStateLookup; diff --git a/tests/Migration/Mapping/Lookup/CurrencyLookupTest.php b/tests/Migration/Mapping/Lookup/CurrencyLookupTest.php index 6d85182a6..87569488d 100644 --- a/tests/Migration/Mapping/Lookup/CurrencyLookupTest.php +++ b/tests/Migration/Mapping/Lookup/CurrencyLookupTest.php @@ -85,7 +85,7 @@ public static function getDatabaseData(): array private function getCurrencyLookup(): CurrencyLookup { - $currencyLookup = $this->getContainer()->get(CurrencyLookup::class); + $currencyLookup = static::getContainer()->get(CurrencyLookup::class); static::assertInstanceOf(CurrencyLookup::class, $currencyLookup); return $currencyLookup; diff --git a/tests/Migration/Mapping/Lookup/DefaultCmsPageLookupTest.php b/tests/Migration/Mapping/Lookup/DefaultCmsPageLookupTest.php index d15ecd96c..a30474132 100644 --- a/tests/Migration/Mapping/Lookup/DefaultCmsPageLookupTest.php +++ b/tests/Migration/Mapping/Lookup/DefaultCmsPageLookupTest.php @@ -26,7 +26,7 @@ class DefaultCmsPageLookupTest extends TestCase public function testGet(): void { $defaultCmsPageLookup = new DefaultCmsPageLookup( - $this->getContainer()->get('cms_page.repository') + static::getContainer()->get('cms_page.repository') ); $result = $defaultCmsPageLookup->get(Context::createDefaultContext()); @@ -77,7 +77,7 @@ public function testGetShouldGetDataFromCache(): void public function testReset(): void { $defaultCmsPageLookup = new DefaultCmsPageLookup( - $this->getContainer()->get('cms_page.repository') + static::getContainer()->get('cms_page.repository') ); $reflectionProperty = new \ReflectionProperty(DefaultCmsPageLookup::class, 'cache'); @@ -98,7 +98,7 @@ private function getDefaultCmsPageId(): string $criteria->addFilter(new EqualsFilter('type', 'product_list')); $criteria->addFilter(new EqualsFilter('locked', true)); - $result = $this->getContainer()->get('cms_page.repository')->search($criteria, Context::createDefaultContext())->getEntities()->first(); + $result = static::getContainer()->get('cms_page.repository')->search($criteria, Context::createDefaultContext())->getEntities()->first(); static::assertInstanceOf(CmsPageEntity::class, $result); static::assertTrue(Uuid::isValid($result->getId())); diff --git a/tests/Migration/Mapping/Lookup/DeliveryTimeLookupTest.php b/tests/Migration/Mapping/Lookup/DeliveryTimeLookupTest.php index 1c1c86b8d..52056f5ad 100644 --- a/tests/Migration/Mapping/Lookup/DeliveryTimeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/DeliveryTimeLookupTest.php @@ -111,7 +111,7 @@ public static function getDatabaseData(): array private function getDeliveryTimeLookup(): DeliveryTimeLookup { return new DeliveryTimeLookup( - $this->getContainer()->get('delivery_time.repository') + static::getContainer()->get('delivery_time.repository') ); } diff --git a/tests/Migration/Mapping/Lookup/DocumentTypeLookupTest.php b/tests/Migration/Mapping/Lookup/DocumentTypeLookupTest.php index 61f9cad33..f812ed402 100644 --- a/tests/Migration/Mapping/Lookup/DocumentTypeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/DocumentTypeLookupTest.php @@ -86,7 +86,7 @@ public static function getDatabaseData(): array private function getDocumentTypeLookup(): DocumentTypeLookup { return new DocumentTypeLookup( - $this->getContainer()->get('document_type.repository') + static::getContainer()->get('document_type.repository') ); } diff --git a/tests/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookupTest.php b/tests/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookupTest.php index 917b1a6bf..543fd82eb 100644 --- a/tests/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookupTest.php +++ b/tests/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookupTest.php @@ -85,7 +85,7 @@ public static function getDatabaseData(): array private function getGlobalDocumentBaseConfigLookup(): GlobalDocumentBaseConfigLookup { - return $this->getContainer()->get(GlobalDocumentBaseConfigLookup::class); + return static::getContainer()->get(GlobalDocumentBaseConfigLookup::class); } private function getMockedGlobalDocumentBaseConfigLookup(): GlobalDocumentBaseConfigLookup diff --git a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php index d05ddbb50..1a936140e 100644 --- a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php +++ b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php @@ -199,9 +199,9 @@ public static function getLanguageIdDatabaseData(): array private function getLanguageLookup(): LanguageLookup { return new LanguageLookup( - $this->getContainer()->get('language.repository'), + static::getContainer()->get('language.repository'), new LocaleLookup( - $this->getContainer()->get('locale.repository') + static::getContainer()->get('locale.repository') ) ); } diff --git a/tests/Migration/Mapping/Lookup/LocaleLookupTest.php b/tests/Migration/Mapping/Lookup/LocaleLookupTest.php index 5d7ba4e60..32b9850fc 100644 --- a/tests/Migration/Mapping/Lookup/LocaleLookupTest.php +++ b/tests/Migration/Mapping/Lookup/LocaleLookupTest.php @@ -87,7 +87,7 @@ public static function getDatabaseData(): array private function getLocaleLookup(): LocaleLookup { return new LocaleLookup( - $this->getContainer()->get('locale.repository') + static::getContainer()->get('locale.repository') ); } diff --git a/tests/Migration/Mapping/Lookup/LowestRootCategoryLookupTest.php b/tests/Migration/Mapping/Lookup/LowestRootCategoryLookupTest.php index 933df2b24..7c0a452fc 100644 --- a/tests/Migration/Mapping/Lookup/LowestRootCategoryLookupTest.php +++ b/tests/Migration/Mapping/Lookup/LowestRootCategoryLookupTest.php @@ -78,7 +78,7 @@ public function testReset(): void private function getGetTestExpectedResult(): string { - $categoryRepository = $this->getContainer()->get('category.repository'); + $categoryRepository = static::getContainer()->get('category.repository'); $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('parentId', null)); @@ -95,7 +95,7 @@ private function getGetTestExpectedResult(): string private function getLowestRootCategoryLookup(): LowestRootCategoryLookup { return new LowestRootCategoryLookup( - $this->getContainer()->get('category.repository') + static::getContainer()->get('category.repository') ); } diff --git a/tests/Migration/Mapping/Lookup/MailTemplateTypeLookupTest.php b/tests/Migration/Mapping/Lookup/MailTemplateTypeLookupTest.php index d5eaf6fa4..faa3b7134 100644 --- a/tests/Migration/Mapping/Lookup/MailTemplateTypeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/MailTemplateTypeLookupTest.php @@ -81,7 +81,7 @@ public static function getDatabaseData(): array private function getMailTemplateTypeLookup(): MailTemplateTypeLookup { - return $this->getContainer()->get(MailTemplateTypeLookup::class); + return static::getContainer()->get(MailTemplateTypeLookup::class); } private function getMockedMailTemplateTypeLookup(): MailTemplateTypeLookup diff --git a/tests/Migration/Mapping/Lookup/MediaDefaultFolderLookupTest.php b/tests/Migration/Mapping/Lookup/MediaDefaultFolderLookupTest.php index 86d059272..215f57f8c 100644 --- a/tests/Migration/Mapping/Lookup/MediaDefaultFolderLookupTest.php +++ b/tests/Migration/Mapping/Lookup/MediaDefaultFolderLookupTest.php @@ -85,7 +85,7 @@ public static function getDatabaseData(): array private function getMediaDefaultFolderLookup(): MediaDefaultFolderLookup { return new MediaDefaultFolderLookup( - $this->getContainer()->get('media_default_folder.repository') + static::getContainer()->get('media_default_folder.repository') ); } diff --git a/tests/Migration/Mapping/Lookup/MediaThumbnailSizeLookupTest.php b/tests/Migration/Mapping/Lookup/MediaThumbnailSizeLookupTest.php index ee1fdf24c..c07012b28 100644 --- a/tests/Migration/Mapping/Lookup/MediaThumbnailSizeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/MediaThumbnailSizeLookupTest.php @@ -87,7 +87,7 @@ public static function getDatabaseData(): array private function getMediaThumbnailSizeLookup(): MediaThumbnailSizeLookup { return new MediaThumbnailSizeLookup( - $this->getContainer()->get('media_thumbnail_size.repository') + static::getContainer()->get('media_thumbnail_size.repository') ); } diff --git a/tests/Migration/Mapping/Lookup/NumberRangeLookupTest.php b/tests/Migration/Mapping/Lookup/NumberRangeLookupTest.php index fbbd97af3..6c68a2c6b 100644 --- a/tests/Migration/Mapping/Lookup/NumberRangeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/NumberRangeLookupTest.php @@ -88,7 +88,7 @@ public static function getDatabaseData(): array private function getNumberRangeLookup(): NumberRangeLookup { - $numberRangeLookup = $this->getContainer()->get(NumberRangeLookup::class); + $numberRangeLookup = static::getContainer()->get(NumberRangeLookup::class); static::assertInstanceOf(NumberRangeLookup::class, $numberRangeLookup); return $numberRangeLookup; diff --git a/tests/Migration/Mapping/Lookup/NumberRangeTypeLookupTest.php b/tests/Migration/Mapping/Lookup/NumberRangeTypeLookupTest.php index 95df32894..576ddd74e 100644 --- a/tests/Migration/Mapping/Lookup/NumberRangeTypeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/NumberRangeTypeLookupTest.php @@ -81,7 +81,7 @@ public static function getDatabaseData(): array private function getNumberRangeTypeLookup(): NumberRangeTypeLookup { - return $this->getContainer()->get(NumberRangeTypeLookup::class); + return static::getContainer()->get(NumberRangeTypeLookup::class); } private function getMockedNumberRangeTypeLookup(): NumberRangeTypeLookup diff --git a/tests/Migration/Mapping/Lookup/ProductSortingLookupTest.php b/tests/Migration/Mapping/Lookup/ProductSortingLookupTest.php index 8115b1abf..5d0ad2460 100644 --- a/tests/Migration/Mapping/Lookup/ProductSortingLookupTest.php +++ b/tests/Migration/Mapping/Lookup/ProductSortingLookupTest.php @@ -81,7 +81,7 @@ public static function getDatabaseData(): array private function getProductSortingLookup(): ProductSortingLookup { - return $this->getContainer()->get(ProductSortingLookup::class); + return static::getContainer()->get(ProductSortingLookup::class); } private function getMockedProductSortingLookup(): ProductSortingLookup diff --git a/tests/Migration/Mapping/Lookup/SalutationLookupTest.php b/tests/Migration/Mapping/Lookup/SalutationLookupTest.php index 3079eff4b..2d49a296e 100644 --- a/tests/Migration/Mapping/Lookup/SalutationLookupTest.php +++ b/tests/Migration/Mapping/Lookup/SalutationLookupTest.php @@ -81,7 +81,7 @@ public static function getDatabaseData(): array private function getSalutationLookup(): SalutationLookup { - return $this->getContainer()->get(SalutationLookup::class); + return static::getContainer()->get(SalutationLookup::class); } private function getMockedSalutationLookup(): SalutationLookup diff --git a/tests/Migration/Mapping/Lookup/SeoUrlTemplateLookupTest.php b/tests/Migration/Mapping/Lookup/SeoUrlTemplateLookupTest.php index 4bdac2bdc..d662f4eed 100644 --- a/tests/Migration/Mapping/Lookup/SeoUrlTemplateLookupTest.php +++ b/tests/Migration/Mapping/Lookup/SeoUrlTemplateLookupTest.php @@ -82,7 +82,7 @@ public static function getDatabaseData(): array private function getSeoUrlTemplateLookup(): SeoUrlTemplateLookup { - $seoUrlTemplateLookup = $this->getContainer()->get(SeoUrlTemplateLookup::class); + $seoUrlTemplateLookup = static::getContainer()->get(SeoUrlTemplateLookup::class); static::assertInstanceOf(SeoUrlTemplateLookup::class, $seoUrlTemplateLookup); return $seoUrlTemplateLookup; diff --git a/tests/Migration/Mapping/Lookup/StateMachineStateLookupTest.php b/tests/Migration/Mapping/Lookup/StateMachineStateLookupTest.php index e441e3ab8..ab9a11013 100644 --- a/tests/Migration/Mapping/Lookup/StateMachineStateLookupTest.php +++ b/tests/Migration/Mapping/Lookup/StateMachineStateLookupTest.php @@ -86,7 +86,7 @@ public static function getDatabaseData(): array private function getStateMachineStateLookup(): StateMachineStateLookup { - return $this->getContainer()->get(StateMachineStateLookup::class); + return static::getContainer()->get(StateMachineStateLookup::class); } private function getMockedStateMachineStateLookup(): StateMachineStateLookup diff --git a/tests/Migration/Mapping/Lookup/SystemConfigLookupTest.php b/tests/Migration/Mapping/Lookup/SystemConfigLookupTest.php index 96ef29e0b..1d3619aed 100644 --- a/tests/Migration/Mapping/Lookup/SystemConfigLookupTest.php +++ b/tests/Migration/Mapping/Lookup/SystemConfigLookupTest.php @@ -85,7 +85,7 @@ public static function getDatabaseData(): array private function getSystemConfigLookup(): SystemConfigLookup { - return $this->getContainer()->get(SystemConfigLookup::class); + return static::getContainer()->get(SystemConfigLookup::class); } private function getMockedSystemConfigLookup(): SystemConfigLookup diff --git a/tests/Migration/Mapping/Lookup/SystemDefaultMailTemplateLookupTest.php b/tests/Migration/Mapping/Lookup/SystemDefaultMailTemplateLookupTest.php index 7ffd919cb..d2036cfba 100644 --- a/tests/Migration/Mapping/Lookup/SystemDefaultMailTemplateLookupTest.php +++ b/tests/Migration/Mapping/Lookup/SystemDefaultMailTemplateLookupTest.php @@ -85,7 +85,7 @@ public static function getDatabaseData(): array private function getSystemDefaultMailTemplateLookup(): SystemDefaultMailTemplateLookup { - return $this->getContainer()->get(SystemDefaultMailTemplateLookup::class); + return static::getContainer()->get(SystemDefaultMailTemplateLookup::class); } private function getMockedSystemDefaultMailTemplateLookup(): SystemDefaultMailTemplateLookup diff --git a/tests/Migration/Mapping/Lookup/TaxLookupTest.php b/tests/Migration/Mapping/Lookup/TaxLookupTest.php index b5554fe4a..223e8c4cd 100644 --- a/tests/Migration/Mapping/Lookup/TaxLookupTest.php +++ b/tests/Migration/Mapping/Lookup/TaxLookupTest.php @@ -193,7 +193,7 @@ private static function getTaxRateList(): EntityCollection private function getTaxLookup(): TaxLookup { - $taxLookup = $this->getContainer()->get(TaxLookup::class); + $taxLookup = static::getContainer()->get(TaxLookup::class); static::assertInstanceOf(TaxLookup::class, $taxLookup); return $taxLookup; diff --git a/tests/Migration/Mapping/Lookup/TaxRuleLookupTest.php b/tests/Migration/Mapping/Lookup/TaxRuleLookupTest.php index 62b5d9790..b76c39bb4 100644 --- a/tests/Migration/Mapping/Lookup/TaxRuleLookupTest.php +++ b/tests/Migration/Mapping/Lookup/TaxRuleLookupTest.php @@ -97,7 +97,7 @@ public static function getDatabaseData(): array private function getTaxRuleLookup(): TaxRuleLookup { - return $this->getContainer()->get(TaxRuleLookup::class); + return static::getContainer()->get(TaxRuleLookup::class); } private function getMockedTaxRuleLookup(): TaxRuleLookup diff --git a/tests/Migration/Mapping/Lookup/TaxRuleTypeLookupTest.php b/tests/Migration/Mapping/Lookup/TaxRuleTypeLookupTest.php index 431cc168e..f1771e0d4 100644 --- a/tests/Migration/Mapping/Lookup/TaxRuleTypeLookupTest.php +++ b/tests/Migration/Mapping/Lookup/TaxRuleTypeLookupTest.php @@ -81,7 +81,7 @@ public static function getDatabaseData(): array private function getTaxRuleTypeLookup(): TaxRuleTypeLookup { - return $this->getContainer()->get(TaxRuleTypeLookup::class); + return static::getContainer()->get(TaxRuleTypeLookup::class); } private function getMockedTaxRuleTypeLookup(): TaxRuleTypeLookup diff --git a/tests/Migration/Mapping/MappingServiceTest.php b/tests/Migration/Mapping/MappingServiceTest.php index 09c01eaa5..50dab0d76 100644 --- a/tests/Migration/Mapping/MappingServiceTest.php +++ b/tests/Migration/Mapping/MappingServiceTest.php @@ -48,8 +48,8 @@ class MappingServiceTest extends TestCase protected function setUp(): void { $context = Context::createDefaultContext(); - $connectionRepo = $this->getContainer()->get('swag_migration_connection.repository'); - $this->mappingRepo = $this->getContainer()->get('swag_migration_mapping.repository'); + $connectionRepo = static::getContainer()->get('swag_migration_connection.repository'); + $this->mappingRepo = static::getContainer()->get('swag_migration_mapping.repository'); $context->scope(MigrationContext::SOURCE_CONTEXT, function (Context $context) use ($connectionRepo): void { $this->connectionId = Uuid::randomHex(); @@ -258,7 +258,7 @@ public function testWriteMapping(array $dataset): void $this->mappingService->writeMapping(); $sql = 'SELECT * FROM swag_migration_mapping'; - $result = $this->getContainer()->get(Connection::class)->fetchAllAssociative($sql); + $result = static::getContainer()->get(Connection::class)->fetchAllAssociative($sql); static::assertCount(\count($dataset), $result); foreach ($dataset as $set) { @@ -282,7 +282,7 @@ public function testWriteMapping(array $dataset): void $this->setMappingAndWriteArray($mapping); $this->mappingService->writeMapping(); - $result = $this->getContainer()->get(Connection::class)->fetchAllAssociative($sql); + $result = static::getContainer()->get(Connection::class)->fetchAllAssociative($sql); static::assertCount(\count($dataset), $result); foreach ($dataset as $set) { @@ -302,7 +302,7 @@ public function testGetMappingWithNullAdditionalData(): void $oldIdentifier = '42'; $entityId = Uuid::randomHex(); - $conn = $this->getContainer()->get(Connection::class); + $conn = static::getContainer()->get(Connection::class); $qb = $conn->createQueryBuilder(); $rowsAffected = $qb->insert('swag_migration_mapping') ->values([ @@ -361,7 +361,7 @@ public function testWritePerEntry(array $dataset): void $reflectionMethod->invoke($this->mappingService); $sql = 'SELECT * FROM swag_migration_mapping'; - $result = $this->getContainer()->get(Connection::class)->fetchAllAssociative($sql); + $result = static::getContainer()->get(Connection::class)->fetchAllAssociative($sql); static::assertCount(\count($dataset), $result); foreach ($dataset as $set) { @@ -381,7 +381,7 @@ public function testWritePerEntry(array $dataset): void $this->setMappingAndWriteArray($mapping); $reflectionMethod->invoke($this->mappingService); - $result = $this->getContainer()->get(Connection::class)->fetchAllAssociative($sql); + $result = static::getContainer()->get(Connection::class)->fetchAllAssociative($sql); static::assertCount(\count($dataset), $result); foreach ($dataset as $set) { @@ -480,9 +480,9 @@ private function createMappingService(): void { $this->mappingService = new MappingService( $this->mappingRepo, - $this->getContainer()->get(EntityWriter::class), - $this->getContainer()->get(SwagMigrationMappingDefinition::class), - $this->getContainer()->get(Connection::class), + static::getContainer()->get(EntityWriter::class), + static::getContainer()->get(SwagMigrationMappingDefinition::class), + static::getContainer()->get(Connection::class), new NullLogger() ); } diff --git a/tests/Migration/Run/MigrationProgressFieldSerializerTest.php b/tests/Migration/Run/MigrationProgressFieldSerializerTest.php index aa6073331..55224f359 100644 --- a/tests/Migration/Run/MigrationProgressFieldSerializerTest.php +++ b/tests/Migration/Run/MigrationProgressFieldSerializerTest.php @@ -33,7 +33,7 @@ class MigrationProgressFieldSerializerTest extends TestCase protected function setUp(): void { - $this->serializer = $this->getContainer()->get(MigrationProgressFieldSerializer::class); + $this->serializer = static::getContainer()->get(MigrationProgressFieldSerializer::class); } public function testEncodeWithArrayInput(): void diff --git a/tests/Migration/Run/PremappingFieldSerializerIntegrationTest.php b/tests/Migration/Run/PremappingFieldSerializerIntegrationTest.php index a9bdcd391..ab98f8c37 100644 --- a/tests/Migration/Run/PremappingFieldSerializerIntegrationTest.php +++ b/tests/Migration/Run/PremappingFieldSerializerIntegrationTest.php @@ -29,7 +29,7 @@ class PremappingFieldSerializerIntegrationTest extends TestCase protected function setUp(): void { - $this->serializer = $this->getContainer()->get(PremappingFieldSerializer::class); + $this->serializer = static::getContainer()->get(PremappingFieldSerializer::class); } public static function invalidInputProvider(): \Generator diff --git a/tests/Migration/Services/MigrationDataConverterTest.php b/tests/Migration/Services/MigrationDataConverterTest.php new file mode 100644 index 000000000..a5632703a --- /dev/null +++ b/tests/Migration/Services/MigrationDataConverterTest.php @@ -0,0 +1,103 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationAssistant\Test\Migration\Services; + +use PHPUnit\Framework\TestCase; +use Shopware\Core\Framework\Context; +use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; +use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriter; +use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriterInterface; +use SwagMigrationAssistant\Migration\Converter\ConverterInterface; +use SwagMigrationAssistant\Migration\Converter\ConverterRegistryInterface; +use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; +use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; +use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface; +use SwagMigrationAssistant\Migration\MigrationContextInterface; +use SwagMigrationAssistant\Migration\Service\MigrationDataConverter; +use SwagMigrationAssistant\Migration\Validation\MigrationValidationService; +use SwagMigrationAssistant\Test\Mock\DataSet\DataSetMock; +use SwagMigrationAssistant\Test\Mock\Migration\Logging\DummyLoggingService; + +class MigrationDataConverterTest extends TestCase +{ + public function testConvertLogsNullConverted(): void + { + $context = Context::createDefaultContext(); + + $dataSet = new DataSetMock(); + + $migrationContext = $this->createMock(MigrationContextInterface::class); + $migrationContext->method('getDataSet')->willReturn($dataSet); + + $converter = $this->createMock(ConverterInterface::class); + // // To pass the test case, return null + $converter->expects(static::once())->method('convert')->willReturn(null); + + $converterRegistry = $this->createMock(ConverterRegistryInterface::class); + $converterRegistry->expects(static::once())->method('getConverter')->willReturn($converter); + + $dummyLogger = new DummyLoggingService(); + + $migrationDataConverter = $this->createMigrationDataConverter(converterRegistry: $converterRegistry, loggingService: $dummyLogger); + + $migrationDataConverter->convert([['id' => '1']], $migrationContext, $context); + + $result = $dummyLogger->getLoggingArray(); + + static::assertCount(1, $result); + static::assertSame('SWAG_MIGRATION__ENTITY_NOT_CONVERTED', $result[0]['code']); + } + + private function createMigrationDataConverter( + ?EntityWriterInterface $entityWriter = null, + ?ConverterRegistryInterface $converterRegistry = null, + ?MediaFileServiceInterface $mediaFileService = null, + ?LoggingServiceInterface $loggingService = null, + ?EntityDefinition $dataDefinition = null, + ?MappingServiceInterface $mappingService = null, + ?MigrationValidationService $validationService = null, + ): MigrationDataConverter { + if ($entityWriter === null) { + $entityWriter = $this->createMock(EntityWriter::class); + } + + if ($converterRegistry === null) { + $converterRegistry = $this->createMock(ConverterRegistryInterface::class); + } + + if ($mediaFileService === null) { + $mediaFileService = $this->createMock(MediaFileServiceInterface::class); + } + + if ($loggingService === null) { + $loggingService = $this->createMock(LoggingServiceInterface::class); + } + + if ($dataDefinition === null) { + $dataDefinition = $this->createMock(EntityDefinition::class); + } + + if ($mappingService === null) { + $mappingService = $this->createMock(MappingServiceInterface::class); + } + + if ($validationService === null) { + $validationService = $this->createMock(MigrationValidationService::class); + } + + return new MigrationDataConverter( + $entityWriter, + $converterRegistry, + $mediaFileService, + $loggingService, + $dataDefinition, + $mappingService, + $validationService + ); + } +} diff --git a/tests/Migration/Services/MigrationDataProcessingTest.php b/tests/Migration/Services/MigrationDataProcessingTest.php index cda83833a..2a0f95570 100644 --- a/tests/Migration/Services/MigrationDataProcessingTest.php +++ b/tests/Migration/Services/MigrationDataProcessingTest.php @@ -29,7 +29,6 @@ use SwagMigrationAssistant\Migration\Data\SwagMigrationDataDefinition; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; use SwagMigrationAssistant\Migration\Gateway\Reader\ReaderRegistry; -use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry; use SwagMigrationAssistant\Migration\Logging\SwagMigrationLoggingCollection; use SwagMigrationAssistant\Migration\Mapping\MappingService; use SwagMigrationAssistant\Migration\Mapping\SwagMigrationMappingDefinition; @@ -49,7 +48,6 @@ use SwagMigrationAssistant\Profile\Shopware\Premapping\SalutationReader; use SwagMigrationAssistant\Profile\Shopware55\Shopware55Profile; use SwagMigrationAssistant\Test\MigrationServicesTrait; -use SwagMigrationAssistant\Test\Mock\DataSet\InvalidCustomerDataSet; /** * Combines tests for data fetching and converting @@ -329,61 +327,13 @@ public function testFetchProductDataLocalGateway(): void static::assertSame(37, $result->getTotal()); } - public function testFetchInvalidCustomerData(): void - { - $context = Context::createDefaultContext(); - $migrationContext = new MigrationContext( - $this->connection, - new Shopware55Profile(), - null, - new InvalidCustomerDataSet(), - $this->runUuid, - 0, - 250 - ); - - $this->clearCacheData(); - $data = $this->migrationDataFetcher->fetchData($migrationContext, $context); - static::assertCount(4, $data); - - $this->migrationDataConverter->convert($data, $migrationContext, $context); - $logs = $this->loggingRepo->search(new Criteria(), $context)->getEntities(); - - $countValidLogging = 0; - $countInvalidLogging = 0; - - foreach ($logs as $log) { - $type = $log->getLevel(); - - if ( - ($type === AbstractMigrationLogEntry::LOG_LEVEL_INFO && $log->getCode() === 'SWAG_MIGRATION_ENTITY_FIELD_REASSIGNED') - || ($type === AbstractMigrationLogEntry::LOG_LEVEL_WARNING && $log->getCode() === 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD') - ) { - ++$countValidLogging; - - continue; - } - - ++$countInvalidLogging; - } - - static::assertSame(5, $countValidLogging); - static::assertSame(4, $countInvalidLogging); - - $failureConvertCriteria = new Criteria(); - $failureConvertCriteria->addFilter(new EqualsFilter('convertFailure', true)); - $logs = $this->migrationDataRepo->search($failureConvertCriteria, $context); - - static::assertSame(4, $logs->getTotal()); - } - private function createMappingService(): MappingService { return new MappingService( - $this->getContainer()->get('swag_migration_mapping.repository'), - $this->getContainer()->get(EntityWriter::class), - $this->getContainer()->get(SwagMigrationMappingDefinition::class), - $this->getContainer()->get(Connection::class), + static::getContainer()->get('swag_migration_mapping.repository'), + static::getContainer()->get(EntityWriter::class), + static::getContainer()->get(SwagMigrationMappingDefinition::class), + static::getContainer()->get(Connection::class), new NullLogger() ); } diff --git a/tests/Migration/Services/MigrationDataWriterTest.php b/tests/Migration/Services/MigrationDataWriterTest.php index 7d237ed21..d7f1bd3be 100644 --- a/tests/Migration/Services/MigrationDataWriterTest.php +++ b/tests/Migration/Services/MigrationDataWriterTest.php @@ -13,7 +13,6 @@ use Psr\Log\NullLogger; use Shopware\Core\Checkout\Customer\CustomerCollection; use Shopware\Core\Checkout\Customer\CustomerDefinition; -use Shopware\Core\Checkout\Order\OrderCollection; use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\InvoicePayment; use Shopware\Core\Checkout\Payment\PaymentMethodCollection; use Shopware\Core\Checkout\Shipping\ShippingMethodCollection; @@ -122,11 +121,6 @@ class MigrationDataWriterTest extends TestCase */ private EntityRepository $customerRepo; - /** - * @var EntityRepository - */ - private EntityRepository $orderRepo; - /** * @var EntityRepository */ @@ -515,15 +509,12 @@ public function testWriteCustomerData(): void $data = $this->migrationDataFetcher->fetchData($migrationContext, $context); $this->migrationDataConverter->convert($data, $migrationContext, $context); - $criteria = new Criteria(); - $customerTotalBefore = $this->customerRepo->search($criteria, $context)->getTotal(); - - $context->scope(Context::USER_SCOPE, function (Context $context) use ($migrationContext): void { - $this->migrationDataWriter->writeData($migrationContext, $context); + $total = 0; + $context->scope(Context::USER_SCOPE, function (Context $context) use ($migrationContext, &$total): void { + $total = $this->migrationDataWriter->writeData($migrationContext, $context); }); - $customerTotalAfter = $this->dbConnection->executeQuery('select count(*) from customer')->fetchOne(); - static::assertSame(3, $customerTotalAfter - $customerTotalBefore); + static::assertSame(3, $total); } public function testWriteOrderData(): void @@ -543,11 +534,12 @@ public function testWriteOrderData(): void $this->migrationDataConverter->convert($data, $userMigrationContext, $context); $this->clearCacheData(); - $context->scope(Context::USER_SCOPE, function (Context $context) use ($userMigrationContext): void { - $this->migrationDataWriter->writeData($userMigrationContext, $context); + $total = 0; + $context->scope(Context::USER_SCOPE, function (Context $context) use ($userMigrationContext, &$total): void { + $total = $this->migrationDataWriter->writeData($userMigrationContext, $context); $this->clearCacheData(); }); - + static::assertSame(3, $total); // Add orders $migrationContext = new MigrationContext( $this->connection, @@ -559,22 +551,16 @@ public function testWriteOrderData(): void 250 ); - $criteria = new Criteria(); - - // Get data before writing $data = $this->migrationDataFetcher->fetchData($migrationContext, $context); $this->migrationDataConverter->convert($data, $migrationContext, $context); $this->clearCacheData(); - $orderTotalBefore = $this->orderRepo->search($criteria, $context)->getTotal(); - // Get data after writing - $context->scope(Context::USER_SCOPE, function (Context $context) use ($migrationContext): void { - $this->migrationDataWriter->writeData($migrationContext, $context); + $context->scope(Context::USER_SCOPE, function (Context $context) use ($migrationContext, &$total): void { + $total = $this->migrationDataWriter->writeData($migrationContext, $context); $this->clearCacheData(); }); - $orderTotalAfter = $this->orderRepo->search($criteria, $context)->getTotal(); - static::assertSame(2, $orderTotalAfter - $orderTotalBefore); + static::assertSame(2, $total); } public function testWriteMediaData(): void @@ -684,8 +670,8 @@ private function createMappingService(): MappingService return new MappingService( $this->migrationMappingRepo, $this->entityWriter, - $this->getContainer()->get(SwagMigrationMappingDefinition::class), - $this->getContainer()->get(Connection::class), + static::getContainer()->get(SwagMigrationMappingDefinition::class), + static::getContainer()->get(Connection::class), new NullLogger() ); } @@ -710,7 +696,6 @@ private function initRepos(): void $this->mediaRepo = static::getContainer()->get('media.repository'); $this->productRepo = static::getContainer()->get('product.repository'); $this->categoryRepo = static::getContainer()->get('category.repository'); - $this->orderRepo = static::getContainer()->get('order.repository'); $this->customerRepo = static::getContainer()->get('customer.repository'); $this->connectionRepo = static::getContainer()->get('swag_migration_connection.repository'); $this->migrationDataRepo = static::getContainer()->get('swag_migration_data.repository'); diff --git a/tests/Migration/Services/RunTransitionServiceTest.php b/tests/Migration/Services/RunTransitionServiceTest.php index 7f948610d..a1ff8e856 100644 --- a/tests/Migration/Services/RunTransitionServiceTest.php +++ b/tests/Migration/Services/RunTransitionServiceTest.php @@ -35,10 +35,10 @@ class RunTransitionServiceTest extends TestCase protected function setUp(): void { - $this->runRepository = $this->getContainer()->get('swag_migration_run.repository'); + $this->runRepository = static::getContainer()->get('swag_migration_run.repository'); $this->context = Context::createDefaultContext(); - $this->runTransitionService = new RunTransitionService($this->getContainer()->get(Connection::class)); + $this->runTransitionService = new RunTransitionService(static::getContainer()->get(Connection::class)); } #[DataProvider('transitionToRunStepProvider')] diff --git a/tests/Migration/Writer/SeoUrlWriterTest.php b/tests/Migration/Writer/SeoUrlWriterTest.php index 6ab430a35..e806f1846 100644 --- a/tests/Migration/Writer/SeoUrlWriterTest.php +++ b/tests/Migration/Writer/SeoUrlWriterTest.php @@ -28,6 +28,8 @@ #[Package('fundamentals@after-sales')] class SeoUrlWriterTest extends TestCase { + private const SALES_CHANNEL_ID = 'sales-channel-uuid'; + private EntityWriterInterface $entityWriter; private EntityDefinition $entityDefinition; @@ -40,7 +42,6 @@ class SeoUrlWriterTest extends TestCase private SeoUrlPersister&MockObject $seoUrlPersister; private SeoUrlWriter $seoUrlWriter; - private const SALES_CHANNEL_ID = 'sales-channel-uuid'; protected function setUp(): void { @@ -87,7 +88,7 @@ public function testWriteData(): void static::assertInstanceOf(EntityWriteResult::class, $result[SeoUrlDefinition::ENTITY_NAME][0]); } - public function testWriteDataSkipIfSalesChannelIsInvalid(): void + public function testWriteDataShouldIgnoreIfIsModified(): void { $context = Context::createDefaultContext(); $seoUrlData = [ diff --git a/tests/MigrationServicesTrait.php b/tests/MigrationServicesTrait.php index e030a5b15..9135d0557 100644 --- a/tests/MigrationServicesTrait.php +++ b/tests/MigrationServicesTrait.php @@ -140,48 +140,48 @@ protected function getMigrationDataConverter( $mappingService, $loggingService, $mediaFileService, - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class), + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class), ), new Shopware55TranslationConverter( $mappingService, $loggingService, - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LanguageLookup::class) ), new Shopware55CategoryConverter( $mappingService, $loggingService, $mediaFileService, - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LanguageLookup::class) ), new Shopware55MediaConverter( $mappingService, $loggingService, $mediaFileService, - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LanguageLookup::class) ), new Shopware55CustomerConverter( $mappingService, $loggingService, $validator, $salesChannelRepo, - $this->getContainer()->get(CountryLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(CountryStateLookup::class), + static::getContainer()->get(CountryLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(CountryStateLookup::class), ), new Shopware55OrderConverter( $mappingService, $loggingService, new TaxCalculator(), $salesChannelRepo, - $this->getContainer()->get(CountryLookup::class), - $this->getContainer()->get(CurrencyLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(CountryStateLookup::class), + static::getContainer()->get(CountryLookup::class), + static::getContainer()->get(CurrencyLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(CountryStateLookup::class), ), new Shopware55SalesChannelConverter( $mappingService, @@ -191,17 +191,17 @@ protected function getMigrationDataConverter( $countryRepo, $salesChannelRepo, null, - $this->getContainer()->get(CurrencyLookup::class), - $this->getContainer()->get(LanguageLookup::class), + static::getContainer()->get(CurrencyLookup::class), + static::getContainer()->get(LanguageLookup::class), ), new DummyInvalidCustomerConverter( $mappingService, $loggingService, $validator, $salesChannelRepo, - $this->getContainer()->get(CountryLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(CountryStateLookup::class), + static::getContainer()->get(CountryLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(CountryStateLookup::class), ), ] ) @@ -221,7 +221,7 @@ protected function getMigrationDataConverter( $loggingService, $dataDefinition, new DummyMappingService(), - $validationService, + $validationService ); } diff --git a/tests/Mock/DataSet/DataSetMock.php b/tests/Mock/DataSet/DataSetMock.php new file mode 100644 index 000000000..9d73bbfcf --- /dev/null +++ b/tests/Mock/DataSet/DataSetMock.php @@ -0,0 +1,35 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationAssistant\Test\Mock\DataSet; + +use Shopware\Core\Framework\Log\Package; +use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet; +use SwagMigrationAssistant\Migration\MigrationContextInterface; + +#[Package('after-sales')] +class DataSetMock extends DataSet +{ + private static string $entityName = 'defaultDatasetEntityName'; + + private bool $supports; + + public function __construct(bool $supports = true) + { + $this->supports = $supports; + } + + public static function getEntity(): string + { + return self::$entityName; + } + + public function supports(MigrationContextInterface $migrationContext): bool + { + return $this->supports; + } +} diff --git a/tests/Profile/Shopware/Gateway/LocalGatewayTest.php b/tests/Profile/Shopware/Gateway/LocalGatewayTest.php index 4e6e2d253..1f6891d75 100644 --- a/tests/Profile/Shopware/Gateway/LocalGatewayTest.php +++ b/tests/Profile/Shopware/Gateway/LocalGatewayTest.php @@ -61,14 +61,14 @@ public function testReadFailedNoCredentials(string $profileName, ProfileInterfac ); $connectionFactory = new ConnectionFactory(); - $readerRegistry = $this->getContainer()->get(ReaderRegistry::class); + $readerRegistry = static::getContainer()->get(ReaderRegistry::class); $localEnvironmentReader = new EnvironmentReader($connectionFactory); $localTableReader = new TableReader($connectionFactory); /** @var EntityRepository $currencyRepository */ - $currencyRepository = $this->getContainer()->get('currency.repository'); + $currencyRepository = static::getContainer()->get('currency.repository'); /** @var EntityRepository $languageRepository */ - $languageRepository = $this->getContainer()->get('language.repository'); + $languageRepository = static::getContainer()->get('language.repository'); $gatewaySource = new ShopwareLocalGateway( $readerRegistry, @@ -112,14 +112,14 @@ public function testReadWithUnknownEntityThrowsException(string $profileName, Pr ); $connectionFactory = new ConnectionFactory(); - $readerRegistry = $this->getContainer()->get(ReaderRegistry::class); + $readerRegistry = static::getContainer()->get(ReaderRegistry::class); $localEnvironmentReader = new EnvironmentReader($connectionFactory); $localTableReader = new TableReader($connectionFactory); /** @var EntityRepository $currencyRepository */ - $currencyRepository = $this->getContainer()->get('currency.repository'); + $currencyRepository = static::getContainer()->get('currency.repository'); /** @var EntityRepository $languageRepository */ - $languageRepository = $this->getContainer()->get('language.repository'); + $languageRepository = static::getContainer()->get('language.repository'); $gatewaySource = new ShopwareLocalGateway( $readerRegistry, @@ -160,15 +160,15 @@ public function testReadEnvironmentInformationHasEmptyResult(string $profileName $profile, ); - $readerRegistry = $this->getContainer()->get(ReaderRegistry::class); + $readerRegistry = static::getContainer()->get(ReaderRegistry::class); $connectionFactory = new ConnectionFactory(); $localEnvironmentReader = new EnvironmentReader($connectionFactory); $localTableReader = new TableReader($connectionFactory); /** @var EntityRepository $currencyRepository */ - $currencyRepository = $this->getContainer()->get('currency.repository'); + $currencyRepository = static::getContainer()->get('currency.repository'); /** @var EntityRepository $languageRepository */ - $languageRepository = $this->getContainer()->get('language.repository'); + $languageRepository = static::getContainer()->get('language.repository'); $gateway = new ShopwareLocalGateway( $readerRegistry, diff --git a/tests/Profile/Shopware/Gateway/ShopwareApiGatewayTest.php b/tests/Profile/Shopware/Gateway/ShopwareApiGatewayTest.php index c4da62be4..49bc0cdb3 100644 --- a/tests/Profile/Shopware/Gateway/ShopwareApiGatewayTest.php +++ b/tests/Profile/Shopware/Gateway/ShopwareApiGatewayTest.php @@ -54,8 +54,8 @@ public function testReadFailed(): void $environmentReader, $tableReader, $tableCountReader, - $this->getContainer()->get('currency.repository'), - $this->getContainer()->get('language.repository') + static::getContainer()->get('currency.repository'), + static::getContainer()->get('language.repository') ); $migrationContext->setGateway($gateway); @@ -94,8 +94,8 @@ public function testReadEnvironmentInformationFailed(): void $environmentReader, $tableReader, $tableCountReader, - $this->getContainer()->get('currency.repository'), - $this->getContainer()->get('language.repository') + static::getContainer()->get('currency.repository'), + static::getContainer()->get('language.repository') ); $response = $gateway->readEnvironmentInformation($migrationContext, Context::createDefaultContext()); @@ -126,8 +126,8 @@ public function testReadEnvironmentInformation(): void $environmentReader, $tableReader, $tableCountReader, - $this->getContainer()->get('currency.repository'), - $this->getContainer()->get('language.repository') + static::getContainer()->get('currency.repository'), + static::getContainer()->get('language.repository') ); $response = $gateway->readEnvironmentInformation($migrationContext, Context::createDefaultContext()); @@ -158,8 +158,8 @@ public function testReadEnvironmentInformationWithoutSourceDefaultLanguage(): vo $environmentReader, $tableReader, $tableCountReader, - $this->getContainer()->get('currency.repository'), - $this->getContainer()->get('language.repository') + static::getContainer()->get('currency.repository'), + static::getContainer()->get('language.repository') ); /** @var EnvironmentInformation $response */ $response = $gateway->readEnvironmentInformation($migrationContext, Context::createDefaultContext()); diff --git a/tests/Profile/Shopware54/Converter/OrderDocumentConverterTest.php b/tests/Profile/Shopware54/Converter/OrderDocumentConverterTest.php index 3bf9bdd14..c790ac098 100644 --- a/tests/Profile/Shopware54/Converter/OrderDocumentConverterTest.php +++ b/tests/Profile/Shopware54/Converter/OrderDocumentConverterTest.php @@ -14,6 +14,7 @@ use Shopware\Core\Framework\Test\TestCaseBase\KernelTestBehaviour; use Shopware\Core\Framework\Uuid\Uuid; use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity; +use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\Lookup\DocumentTypeLookup; @@ -91,37 +92,6 @@ public function testSupports(): void static::assertTrue($supportsDefinition); } - public function testConvertWithUnknownOrderId(): void - { - $orderDocumentData = require __DIR__ . '/../../../_fixtures/order_document_data.php'; - $context = Context::createDefaultContext(); - - $convertResult = $this->orderDocumentConverter->convert( - $orderDocumentData[1], - $context, - $this->migrationContext - ); - static::assertEmpty($convertResult->getConverted()); - $logs = $this->loggingService->getLoggingArray(); - static::assertSame('SWAG_MIGRATION__SHOPWARE_ASSOCIATION_REQUIRED_MISSING', $logs[0]['code']); - } - - public function testConvertWithoutDocumentType(): void - { - $orderDocumentData = require __DIR__ . '/../../../_fixtures/order_document_data.php'; - $context = Context::createDefaultContext(); - unset($orderDocumentData[0]['documenttype']); - - $convertResult = $this->orderDocumentConverter->convert( - $orderDocumentData[0], - $context, - $this->migrationContext - ); - static::assertEmpty($convertResult->getConverted()); - $logs = $this->loggingService->getLoggingArray(); - static::assertSame('SWAG_MIGRATION_EMPTY_NECESSARY_FIELD', $logs[0]['code']); - } - public function testConvert(): void { $orderDocumentData = require __DIR__ . '/../../../_fixtures/order_document_data.php'; @@ -182,6 +152,7 @@ public function testConvertShouldLogUnknownType(): void $this->migrationContext ); + static::assertInstanceOf(ConvertStruct::class, $convertResult); $converted = $convertResult->getConverted(); static::assertIsArray($converted); @@ -218,6 +189,7 @@ public function testConvertShouldMapDocumentTypes(array $document, string $expec $this->migrationContext ); + static::assertInstanceOf(ConvertStruct::class, $convertResult); $converted = $convertResult->getConverted(); static::assertIsArray($converted); diff --git a/tests/Profile/Shopware54/Converter/ProductConverterTest.php b/tests/Profile/Shopware54/Converter/ProductConverterTest.php index c35586835..e93400732 100644 --- a/tests/Profile/Shopware54/Converter/ProductConverterTest.php +++ b/tests/Profile/Shopware54/Converter/ProductConverterTest.php @@ -54,10 +54,10 @@ public function testConvertShouldConvertSeoMainCategories(): void $mappingServiceMock, $loggerMock, $mediaFileServiceMock, - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class), + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class), ); $data = require __DIR__ . '/_fixtures/product_with_seo_main_category.php'; diff --git a/tests/Profile/Shopware55/Converter/CategoryConverterTest.php b/tests/Profile/Shopware55/Converter/CategoryConverterTest.php index abdc073d2..2cf8560f4 100644 --- a/tests/Profile/Shopware55/Converter/CategoryConverterTest.php +++ b/tests/Profile/Shopware55/Converter/CategoryConverterTest.php @@ -50,9 +50,9 @@ protected function setUp(): void $mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - $this->getContainer()->get(LanguageLookup::class), + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LanguageLookup::class), ); $runId = Uuid::randomHex(); @@ -99,8 +99,8 @@ public function testConvert(): void new DummyMappingService(), $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), $languageLookup ); @@ -132,9 +132,8 @@ public function testConvertWithParent(): void new DummyMappingService(), $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - // $this->getContainer()->get(LanguageLookup::class), + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), $languageLookup ); @@ -175,10 +174,39 @@ public function testConvertWithoutLocale(): void $context = Context::createDefaultContext(); $convertResult = $this->categoryConverter->convert($categoryData, $context, $this->migrationContext); - static::assertNull($convertResult->getConverted()); - $logs = $this->loggingService->getLoggingArray(); - static::assertCount(1, $logs); + $converted = $convertResult->getConverted(); + static::assertNotNull($converted); + + $expected = [ + 'description' => '

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

', + 'level' => 0, + 'active' => true, + 'visible' => true, + 'name' => 'Lebensmittel', + ]; + + static::assertArrayHasKey('id', $converted); + static::assertTrue(Uuid::isValid($converted['id'])); + + static::assertArrayHasKey('afterCategoryId', $converted); + static::assertTrue(Uuid::isValid($converted['afterCategoryId'])); + + static::assertArrayHasKey('cmsPageId', $converted); + static::assertTrue(Uuid::isValid($converted['cmsPageId'])); + + foreach ($expected as $key => $value) { + static::assertSame($value, $converted[$key]); + } + + static::assertArrayHasKey('media', $converted); + $media = $converted['media']; + static::assertArrayHasKey('id', $media); + static::assertArrayHasKey('title', $media); + static::assertArrayHasKey('alt', $media); + static::assertTrue(Uuid::isValid($media['id'])); + static::assertSame('brot', $media['title']); + static::assertSame('Nices Brot', $media['alt']); } public function testConvertWithExternalLink(): void diff --git a/tests/Profile/Shopware55/Converter/CrossSellingConverterTest.php b/tests/Profile/Shopware55/Converter/CrossSellingConverterTest.php index 1fe87ba8a..3cd3541d8 100644 --- a/tests/Profile/Shopware55/Converter/CrossSellingConverterTest.php +++ b/tests/Profile/Shopware55/Converter/CrossSellingConverterTest.php @@ -144,34 +144,6 @@ public function testConvertMultipleTime(): void static::assertSame($converted1['assignedProducts'][0]['productId'], $converted2['assignedProducts']['0']['productId']); } - public function testConvertWithoutMapping(): void - { - $data = require __DIR__ . '/../../../_fixtures/cross_selling_data.php'; - $product = $data[0]; - $product['articleID'] = '99'; - - $context = Context::createDefaultContext(); - $convertResult = $this->crossSellingConverter->convert($product, $context, $this->migrationContext); - - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($convertResult->getConverted()); - - $logs = $this->loggingService->getLoggingArray(); - static::assertCount(1, $logs); - static::assertSame('SWAG_MIGRATION__SHOPWARE_ASSOCIATION_REQUIRED_MISSING', $logs[0]['code']); - - $this->loggingService->resetLogging(); - $data[0]['relatedarticle'] = '80'; - $convertResult = $this->crossSellingConverter->convert($data[0], $context, $this->migrationContext); - - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($convertResult->getConverted()); - - $logs = $this->loggingService->getLoggingArray(); - static::assertCount(1, $logs); - static::assertSame('SWAG_MIGRATION__SHOPWARE_ASSOCIATION_REQUIRED_MISSING', $logs[0]['code']); - } - public function testConvertCreatesAdditionalMappingForTypeAndArticleId(): void { $crossSellingData = require __DIR__ . '/../../../_fixtures/cross_selling_data.php'; @@ -256,6 +228,8 @@ private function checkProduct(int $fromIndex, int $toIndex, ConvertStruct $conve static::assertNull($convertStruct->getUnmapped()); static::assertNotNull($convertStruct->getMappingUuid()); - static::assertSame($this->compareProduct, $converted); + foreach ($this->compareProduct as $key => $value) { + static::assertSame($value, $converted[$key]); + } } } diff --git a/tests/Profile/Shopware55/Converter/CurrencyConverterTest.php b/tests/Profile/Shopware55/Converter/CurrencyConverterTest.php index 66e4dc60f..56e76185b 100644 --- a/tests/Profile/Shopware55/Converter/CurrencyConverterTest.php +++ b/tests/Profile/Shopware55/Converter/CurrencyConverterTest.php @@ -98,10 +98,10 @@ public function testConvert(): void $currencyData = require __DIR__ . '/../../../_fixtures/currency_data.php'; $convertResult = $this->converter->convert($currencyData[0], $this->context, $this->migrationContext); $this->converter->writeMapping($this->context); - $converted = $convertResult->getConverted(); + $converted = $convertResult?->getConverted(); - static::assertNull($convertResult->getUnmapped()); - static::assertNotNull($convertResult->getMappingUuid()); + static::assertNull($convertResult?->getUnmapped()); + static::assertNotNull($convertResult?->getMappingUuid()); static::assertNotNull($converted); static::assertArrayHasKey('id', $converted); static::assertArrayHasKey('translations', $converted); @@ -141,10 +141,27 @@ public function testConvertWhichExists(): void $convertResult = $this->converter->convert($currencyData[0], $this->context, $this->migrationContext); - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - - $logs = $this->loggingService->getLoggingArray(); - static::assertEmpty($logs); + $expected = [ + 'isDefault' => false, + 'shortName' => 'COC', + 'isoCode' => 'COC', + 'name' => 'Kekse', + 'factor' => 100.0, + 'position' => 0, + 'symbol' => 'COOKIES', + 'placedInFront' => false, + 'itemRounding' => [ + 'decimals' => 2, + 'interval' => 0.01, + 'roundForNet' => true, + ], + 'totalRounding' => [ + 'decimals' => 2, + 'interval' => 0.01, + 'roundForNet' => true, + ], + ]; + + static::assertNull($convertResult); } } diff --git a/tests/Profile/Shopware55/Converter/CustomerConverterTest.php b/tests/Profile/Shopware55/Converter/CustomerConverterTest.php index 76105f918..3ccabe247 100644 --- a/tests/Profile/Shopware55/Converter/CustomerConverterTest.php +++ b/tests/Profile/Shopware55/Converter/CustomerConverterTest.php @@ -7,6 +7,7 @@ namespace SwagMigrationAssistant\Test\Profile\Shopware55\Converter; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Shopware\Core\Checkout\Customer\CustomerEntity; use Shopware\Core\Framework\Context; @@ -138,6 +139,40 @@ public function testConvert(): void static::assertCount(0, $this->loggingService->getLoggingArray()); } + #[DataProvider('requiredProperties')] + public function testConvertWithoutRequiredProperties(string $property, ?string $value): void + { + $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; + $customerData = $customerData[0]; + $customerData[$property] = $value; + + $context = Context::createDefaultContext(); + $convertResult = $this->customerConverter->convert( + $customerData, + $context, + $this->migrationContext + ); + static::assertNotNull($convertResult->getConverted()); + } + + /** + * @return array> + */ + public static function requiredProperties(): array + { + return [ + 'email is null' => ['email', null], + 'email is empty' => ['email', ''], + 'firstname is null' => ['firstname', null], + 'firstname is empty' => ['firstname', ''], + 'lastname is null' => ['lastname', null], + 'lastname is empty' => ['lastname', ''], + 'defaultpayment is null' => ['defaultpayment', null], + 'customerGroupId is empty' => ['customerGroupId', ''], + 'customerGroupId is null' => ['customerGroupId', null], + ]; + } + public function testConvertGuestAccount(): void { $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; @@ -161,6 +196,177 @@ public function testConvertGuestAccount(): void static::assertCount(0, $this->loggingService->getLoggingArray()); } + public function testConvertCustomerWithoutNumber(): void + { + $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; + $customerData = $customerData[0]; + $customerData['customernumber'] = null; + + $context = Context::createDefaultContext(); + $convertResult = $this->customerConverter->convert( + $customerData, + $context, + $this->migrationContext + ); + + $converted = $convertResult->getConverted(); + static::assertNotNull($converted); + + static::assertNull($convertResult->getUnmapped()); + static::assertArrayHasKey('id', $converted); + static::assertArrayHasKey('addresses', $converted); + static::assertSame(TestDefaults::SALES_CHANNEL, $converted['salesChannelId']); + static::assertSame('Mustermann', $converted['lastName']); + static::assertSame('number-1', $converted['customerNumber']); + static::assertCount(0, $this->loggingService->getLoggingArray()); + } + + public function testConvertCustomerWithoutPaymentAndWithDefaultPayment(): void + { + $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; + $customerData = $customerData[0]; + unset($customerData['defaultpayment']); + + $context = Context::createDefaultContext(); + $mapping = $this->mappingService->getOrCreateMapping($this->connectionId, PaymentMethodReader::getMappingName(), PaymentMethodReader::SOURCE_ID, $context, null, [], Uuid::randomHex()); + $convertResult = $this->customerConverter->convert( + $customerData, + $context, + $this->migrationContext + ); + + $converted = $convertResult->getConverted(); + $logs = $this->loggingService->getLoggingArray(); + + static::assertNull($convertResult->getUnmapped()); + static::assertNotNull($converted); + static::assertCount(0, $logs); + static::assertArrayHasKey('id', $converted); + static::assertArrayHasKey('addresses', $converted); + static::assertSame(TestDefaults::SALES_CHANNEL, $converted['salesChannelId']); + static::assertSame('Mustermann', $converted['lastName']); + static::assertSame($mapping['entityId'], $converted['defaultPaymentMethodId']); + static::assertCount(0, $this->loggingService->getLoggingArray()); + } + + /** + * @return array> + */ + public static function requiredAddressProperties(): array + { + return [ + 'firstname is null' => ['firstname', null], + 'firstname is empty' => ['firstname', ''], + 'lastname is null' => ['lastname', null], + 'lastname is empty' => ['lastname', ''], + 'zipcode is null' => ['zipcode', null], + 'zipcode is empty' => ['zipcode', ''], + 'city is null' => ['city', null], + 'city is empty' => ['city', ''], + 'street is null' => ['street', null], + 'street is empty' => ['street', ''], + ]; + } + + #[DataProvider('requiredAddressProperties')] + public function testConvertWithoutRequiredAddressPropertiesForBillingDefault(string $property, ?string $value): void + { + $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; + $customerData = $customerData[0]; + $customerData['addresses'][0][$property] = $value; + + $context = Context::createDefaultContext(); + $convertResult = $this->customerConverter->convert( + $customerData, + $context, + $this->migrationContext + ); + + $converted = $convertResult->getConverted(); + static::assertNotNull($converted); + + static::assertNull($convertResult->getUnmapped()); + static::assertArrayHasKey('id', $converted); + static::assertArrayHasKey('addresses', $converted); + + static::assertSame('Mustermannstraße 92', $converted['addresses'][0]['street']); + static::assertSame($converted['addresses'][0]['id'], $converted['defaultBillingAddressId']); + static::assertSame($converted['addresses'][0]['id'], $converted['defaultShippingAddressId']); + + $logs = $this->loggingService->getLoggingArray(); + static::assertCount(2, $logs); + + static::assertSame($logs[0]['code'], 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD'); + static::assertSame($logs[1]['code'], 'SWAG_MIGRATION_ENTITY_FIELD_REASSIGNED'); + } + + #[DataProvider('requiredAddressProperties')] + public function testConvertWithoutRequiredAddressPropertiesForShippingDefault(string $property, ?string $value): void + { + $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; + $customerData = $customerData[0]; + $customerData['addresses'][1][$property] = $value; + + $context = Context::createDefaultContext(); + $convertResult = $this->customerConverter->convert( + $customerData, + $context, + $this->migrationContext + ); + + $converted = $convertResult->getConverted(); + static::assertNotNull($converted); + + static::assertNull($convertResult->getUnmapped()); + static::assertArrayHasKey('id', $converted); + static::assertArrayHasKey('addresses', $converted); + + static::assertSame('Musterstr. 55', $converted['addresses'][0]['street']); + static::assertSame($converted['addresses'][0]['id'], $converted['defaultBillingAddressId']); + static::assertSame($converted['addresses'][0]['id'], $converted['defaultShippingAddressId']); + + $logs = $this->loggingService->getLoggingArray(); + static::assertCount(2, $logs); + + static::assertSame($logs[0]['code'], 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD'); + static::assertSame($logs[1]['code'], 'SWAG_MIGRATION_ENTITY_FIELD_REASSIGNED'); + } + + #[DataProvider('requiredAddressProperties')] + public function testConvertWithoutRequiredAddressPropertiesForDefaultBillingAndShipping(string $property, ?string $value): void + { + $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; + $customerData = $customerData[0]; + $customerData['addresses'][0][$property] = $value; + $customerData['addresses'][1][$property] = $value; + + $context = Context::createDefaultContext(); + $convertResult = $this->customerConverter->convert( + $customerData, + $context, + $this->migrationContext + ); + + $converted = $convertResult->getConverted(); + static::assertNotNull($converted); + + static::assertNull($convertResult->getUnmapped()); + static::assertArrayHasKey('id', $converted); + static::assertArrayHasKey('addresses', $converted); + + static::assertSame('Musterstraße 3', $converted['addresses'][0]['street']); + static::assertSame($converted['addresses'][0]['id'], $converted['defaultBillingAddressId']); + static::assertSame($converted['addresses'][0]['id'], $converted['defaultShippingAddressId']); + + $logs = $this->loggingService->getLoggingArray(); + static::assertCount(4, $logs); + + static::assertSame($logs[0]['code'], 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD'); + static::assertSame($logs[1]['code'], 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD'); + static::assertSame($logs[2]['code'], 'SWAG_MIGRATION_ENTITY_FIELD_REASSIGNED'); + static::assertSame($logs[2]['code'], 'SWAG_MIGRATION_ENTITY_FIELD_REASSIGNED'); + } + public function testGetCustomerWithShopScope(): void { $customerData = require __DIR__ . '/../../../_fixtures/customer_data.php'; @@ -199,7 +405,7 @@ public function testConvertCountryStateWithMapping(): void $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('shortCode', 'DE-NW')); - $expectedStateId = $this->getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); + $expectedStateId = static::getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); static::assertNotNull($converted); static::assertArrayHasKey('id', $converted); @@ -226,7 +432,7 @@ public function testConvertExistingCountryStateWithoutMapping(): void $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('shortCode', 'DE-NW')); - $expectedStateId = $this->getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); + $expectedStateId = static::getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); static::assertNotNull($converted); static::assertArrayHasKey('id', $converted); diff --git a/tests/Profile/Shopware55/Converter/CustomerWishlistConverterTest.php b/tests/Profile/Shopware55/Converter/CustomerWishlistConverterTest.php index a8b080157..a566e6a38 100644 --- a/tests/Profile/Shopware55/Converter/CustomerWishlistConverterTest.php +++ b/tests/Profile/Shopware55/Converter/CustomerWishlistConverterTest.php @@ -112,43 +112,4 @@ public function testConvert(): void $wishlistProduct = $wishlistProducts[0]; static::assertArrayHasKey('id', $wishlistProduct); } - - public function testConvertWithoutCustomer(): void - { - $data = require __DIR__ . '/../../../_fixtures/customer_wishlist.php'; - $data[0]['userID'] = '99'; - - $convertResult = $this->converter->convert($data[0], $this->context, $this->migrationContext); - $this->converter->writeMapping($this->context); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($convertResult->getMappingUuid()); - } - - public function testConvertWithoutProduct(): void - { - $data = require __DIR__ . '/../../../_fixtures/customer_wishlist.php'; - $data[0]['ordernumber'] = '99'; - - $convertResult = $this->converter->convert($data[0], $this->context, $this->migrationContext); - $this->converter->writeMapping($this->context); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($convertResult->getMappingUuid()); - } - - public function testConvertWithoutSalesChannel(): void - { - $data = require __DIR__ . '/../../../_fixtures/customer_wishlist.php'; - $data[0]['subshopID'] = '99'; - - $convertResult = $this->converter->convert($data[0], $this->context, $this->migrationContext); - $this->converter->writeMapping($this->context); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($convertResult->getMappingUuid()); - } } diff --git a/tests/Profile/Shopware55/Converter/LanguageConverterTest.php b/tests/Profile/Shopware55/Converter/LanguageConverterTest.php index bee77f357..b00d606b3 100644 --- a/tests/Profile/Shopware55/Converter/LanguageConverterTest.php +++ b/tests/Profile/Shopware55/Converter/LanguageConverterTest.php @@ -21,7 +21,6 @@ use SwagMigrationAssistant\Profile\Shopware55\Shopware55Profile; use SwagMigrationAssistant\Test\Mock\Migration\Logging\DummyLoggingService; use SwagMigrationAssistant\Test\Mock\Migration\Mapping\BasicSettingsMappingService; -use SwagMigrationAssistant\Test\Mock\Migration\Mapping\DummyMappingService; #[Package('fundamentals@after-sales')] class LanguageConverterTest extends TestCase @@ -40,8 +39,8 @@ protected function setUp(): void $this->converter = new Shopware55LanguageConverter( new BasicSettingsMappingService(), $this->loggingService, - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(LocaleLookup::class), + static::getContainer()->get(LocaleLookup::class), + static::getContainer()->get(LanguageLookup::class), ); $runId = Uuid::randomHex(); @@ -73,6 +72,7 @@ public function testConvert(): void $context = Context::createDefaultContext(); $convertResult = $this->converter->convert($languageData[0], $context, $this->migrationContext); + static::assertNotNull($convertResult); $this->converter->writeMapping($context); $converted = $convertResult->getConverted(); static::assertNotNull($converted); @@ -83,28 +83,4 @@ public function testConvert(): void static::assertSame('Niederländisch', $converted['name']); static::assertSame($converted['translationCodeId'], $converted['localeId']); } - - public function testConvertWhichExists(): void - { - $languageData = require __DIR__ . '/../../../_fixtures/language_data.php'; - - $languageLookupMock = $this->createMock(LanguageLookup::class); - $languageLookupMock->method('get')->willReturn('test-uuid'); - - $context = Context::createDefaultContext(); - $this->converter = new Shopware55LanguageConverter( - new DummyMappingService(), - $this->loggingService, - $languageLookupMock, - $this->createMock(LocaleLookup::class) - ); - $convertResult = $this->converter->convert($languageData[0], $context, $this->migrationContext); - $this->converter->writeMapping($context); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - - $logs = $this->loggingService->getLoggingArray(); - static::assertSame('SWAG_MIGRATION_ENTITY_ALREADY_EXISTS', $logs[0]['code']); - } } diff --git a/tests/Profile/Shopware55/Converter/MainVariantRelationConverterTest.php b/tests/Profile/Shopware55/Converter/MainVariantRelationConverterTest.php index 0fafcd270..572080f71 100644 --- a/tests/Profile/Shopware55/Converter/MainVariantRelationConverterTest.php +++ b/tests/Profile/Shopware55/Converter/MainVariantRelationConverterTest.php @@ -114,51 +114,20 @@ public function testConvert(): void $context = Context::createDefaultContext(); $convertResult = $this->converter->convert($data[0], $context, $this->migrationContext); $this->converter->writeMapping($context); - $converted = $convertResult->getConverted(); + $converted = $convertResult?->getConverted(); - static::assertNull($convertResult->getUnmapped()); + static::assertNull($convertResult?->getUnmapped()); static::assertNotNull($converted); static::assertSame($this->productContainer1['entityId'], $converted['id']); static::assertSame($this->productVariant1['entityId'], $converted['variantListingConfig']['mainVariantId']); $convertResult = $this->converter->convert($data[1], $context, $this->migrationContext); $this->converter->writeMapping($context); - $converted = $convertResult->getConverted(); + $converted = $convertResult?->getConverted(); - static::assertNull($convertResult->getUnmapped()); + static::assertNull($convertResult?->getUnmapped()); static::assertNotNull($converted); static::assertSame($this->productContainer2['entityId'], $converted['id']); static::assertSame($this->productVariant2['entityId'], $converted['variantListingConfig']['mainVariantId']); } - - public function testConvertWithoutMapping(): void - { - $data = require __DIR__ . '/../../../_fixtures/main_variant_relation.php'; - $context = Context::createDefaultContext(); - $raw1 = $data[0]; - $raw2 = $data[0]; - - $raw1['id'] = 'invalid-id'; - $convertResult = $this->converter->convert($raw1, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $converted = $convertResult->getConverted(); - - $logs = $this->loggingService->getLoggingArray(); - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($converted); - static::assertCount(1, $logs); - static::assertSame('SWAG_MIGRATION__SHOPWARE_ASSOCIATION_REQUIRED_MISSING', $logs[0]['code']); - - $this->loggingService->resetLogging(); - $raw2['ordernumber'] = 'invalid-ordernumber'; - $convertResult = $this->converter->convert($raw2, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $converted = $convertResult->getConverted(); - - $logs = $this->loggingService->getLoggingArray(); - static::assertNotNull($convertResult->getUnmapped()); - static::assertNull($converted); - static::assertCount(1, $logs); - static::assertSame('SWAG_MIGRATION__SHOPWARE_ASSOCIATION_REQUIRED_MISSING', $logs[0]['code']); - } } diff --git a/tests/Profile/Shopware55/Converter/MediaConverterTest.php b/tests/Profile/Shopware55/Converter/MediaConverterTest.php index c756735da..2c73c93cc 100644 --- a/tests/Profile/Shopware55/Converter/MediaConverterTest.php +++ b/tests/Profile/Shopware55/Converter/MediaConverterTest.php @@ -39,7 +39,7 @@ protected function setUp(): void $mappingService, new DummyLoggingService(), $mediaFileService, - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LanguageLookup::class) ); $runId = Uuid::randomHex(); diff --git a/tests/Profile/Shopware55/Converter/MediaFolderConverterTest.php b/tests/Profile/Shopware55/Converter/MediaFolderConverterTest.php index 2c8c294e4..d5cb99198 100644 --- a/tests/Profile/Shopware55/Converter/MediaFolderConverterTest.php +++ b/tests/Profile/Shopware55/Converter/MediaFolderConverterTest.php @@ -37,8 +37,8 @@ protected function setUp(): void $this->converter = new Shopware55MediaFolderConverter( new DummyMappingService(), $loggingService, - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(MediaThumbnailSizeLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(MediaThumbnailSizeLookup::class), ); $runId = Uuid::randomHex(); diff --git a/tests/Profile/Shopware55/Converter/NewsletterRecipientConverterTest.php b/tests/Profile/Shopware55/Converter/NewsletterRecipientConverterTest.php index f45d56585..ca8705a71 100644 --- a/tests/Profile/Shopware55/Converter/NewsletterRecipientConverterTest.php +++ b/tests/Profile/Shopware55/Converter/NewsletterRecipientConverterTest.php @@ -42,7 +42,7 @@ protected function setUp(): void $this->newsletterReceiverConverter = new Shopware55NewsletterRecipientConverter( $mappingService, $this->loggingService, - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LanguageLookup::class) ); $runId = Uuid::randomHex(); @@ -92,30 +92,6 @@ protected function setUp(): void ); } - public function testConvertWithoutDoubleOptinConfirmed(): void - { - $customerData = require __DIR__ . '/../../../_fixtures/invalid/newsletter_recipient_data.php'; - - $context = Context::createDefaultContext(); - $customerData = $customerData[1]; - $customerData['address']['double_optin_confirmed'] = null; - $customerData['address']['salutation'] = 'mr'; - $customerData['double_optin_confirmed'] = null; - - $convertResult = $this->newsletterReceiverConverter->convert( - $customerData, - $context, - $this->context - ); - - static::assertNull($convertResult->getConverted()); - - $logs = $this->loggingService->getLoggingArray(); - static::assertCount(1, $logs); - - static::assertSame($logs[0]['code'], 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD'); - } - public function testConvertWithNotExistingSalutation(): void { $data = require __DIR__ . '/../../../_fixtures/invalid/newsletter_recipient_data.php'; diff --git a/tests/Profile/Shopware55/Converter/NumberRangeConverterTest.php b/tests/Profile/Shopware55/Converter/NumberRangeConverterTest.php index 1747507da..2243a01ae 100644 --- a/tests/Profile/Shopware55/Converter/NumberRangeConverterTest.php +++ b/tests/Profile/Shopware55/Converter/NumberRangeConverterTest.php @@ -40,8 +40,8 @@ protected function setUp(): void $mappingService, $loggingService, $numberRangeRepo, - $this->getContainer()->get(NumberRangeLookup::class), - $this->getContainer()->get(LanguageLookup::class), + static::getContainer()->get(NumberRangeLookup::class), + static::getContainer()->get(LanguageLookup::class), ); $runId = Uuid::randomHex(); @@ -138,16 +138,4 @@ public function testConvert(): void static::assertSame('SW{n}', $converted['pattern']); static::assertSame(50006, $converted['start']); } - - public function testConvertWithUnknownType(): void - { - $numberRangeData = require __DIR__ . '/../../../_fixtures/number_range_data.php'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($numberRangeData[2], $context, $this->migrationContext); - $this->converter->writeMapping($context); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - } } diff --git a/tests/Profile/Shopware55/Converter/OrderConverterTest.php b/tests/Profile/Shopware55/Converter/OrderConverterTest.php index c5eb150d9..ce4ff69be 100644 --- a/tests/Profile/Shopware55/Converter/OrderConverterTest.php +++ b/tests/Profile/Shopware55/Converter/OrderConverterTest.php @@ -85,10 +85,10 @@ protected function setUp(): void $this->loggingService, $taxCalculator, $salesChannelRepo, - $this->getContainer()->get(CountryLookup::class), + static::getContainer()->get(CountryLookup::class), $currencyLookup, - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(CountryStateLookup::class) + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(CountryStateLookup::class) ); $this->customerConverter = new Shopware55CustomerConverter( @@ -393,26 +393,21 @@ public function testConvertWithoutRequiredProperties(string $missingProperty): v $this->migrationContext ); - static::assertNull($convertResult->getConverted()); - - $logs = $this->loggingService->getLoggingArray(); - static::assertCount(1, $logs); - - static::assertSame($logs[0]['code'], 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD'); + static::assertNotNull($convertResult->getConverted()); } /** - * @return list> + * @return array */ public static function requiredProperties(): array { return [ - ['billingaddress'], - ['payment'], - ['customer'], - ['currencyFactor'], - ['currency'], - ['status'], + 'billingaddress' => ['billingaddress'], + 'payment' => ['payment'], + 'customer' => ['customer'], + 'currencyFactor' => ['currencyFactor'], + 'currency' => ['currency'], + 'status' => ['status'], ]; } @@ -577,17 +572,7 @@ public function testConvertWithoutValidBillingAddress(string $missingAddressProp $converted = $convertResult->getConverted(); - static::assertNull($converted); - static::assertCount(2, $this->loggingService->getLoggingArray()); - - $validLog = 0; - foreach ($this->loggingService->getLoggingArray() as $log) { - if ($log['code'] === 'SWAG_MIGRATION_EMPTY_NECESSARY_FIELD') { - ++$validLog; - } - } - - static::assertSame(2, $validLog); + static::assertNotNull($converted); } #[DataProvider('requiredAddressProperties')] @@ -617,71 +602,12 @@ public function testConvertWithoutValidShippingAddress(string $missingProperty): static::assertArrayHasKey('id', $converted); static::assertSame(TestDefaults::SALES_CHANNEL, $converted['salesChannelId']); static::assertSame('test@example.com', $converted['orderCustomer']['email']); - static::assertCount(1, $this->loggingService->getLoggingArray()); foreach ($this->loggingService->getLoggingArray() as $log) { static::assertSame('SWAG_MIGRATION_EMPTY_NECESSARY_FIELD', $log['code']); } } - public function testConvertWithoutPaymentName(): void - { - [$customerData, $orderData] = $this->getFixtureData(); - $orderData = $orderData[0]; - unset($orderData['payment']['name']); - $context = Context::createDefaultContext(); - - $this->customerConverter->convert( - $customerData[0], - $context, - $this->customerMigrationContext - ); - - $convertResult = $this->orderConverter->convert( - $orderData, - $context, - $this->migrationContext - ); - - $converted = $convertResult->getConverted(); - - static::assertNull($converted); - static::assertCount(1, $this->loggingService->getLoggingArray()); - - foreach ($this->loggingService->getLoggingArray() as $log) { - static::assertSame('SWAG_MIGRATION_EMPTY_NECESSARY_FIELD', $log['code']); - } - } - - public function testConvertWithoutKnownOrderState(): void - { - [$customerData, $orderData] = $this->getFixtureData(); - $orderData = $orderData[0]; - $orderData['status'] = 100; - $context = Context::createDefaultContext(); - - $this->customerConverter->convert( - $customerData[0], - $context, - $this->customerMigrationContext - ); - - $convertResult = $this->orderConverter->convert( - $orderData, - $context, - $this->migrationContext - ); - - $converted = $convertResult->getConverted(); - - static::assertNull($converted); - static::assertCount(1, $this->loggingService->getLoggingArray()); - - foreach ($this->loggingService->getLoggingArray() as $log) { - static::assertSame('SWAG_MIGRATION_ENTITY_UNKNOWN', $log['code']); - } - } - public function testConvertWithOrderLanguage(): void { [$customerData, $orderData] = $this->getFixtureData(); @@ -707,7 +633,7 @@ public function testConvertWithOrderLanguage(): void $this->loggingService, new TaxCalculator(), static::getContainer()->get('sales_channel.repository'), - $this->getContainer()->get(CountryLookup::class), + static::getContainer()->get(CountryLookup::class), $currencyLookup, $languageLookup, $this->createMock(CountryStateLookup::class) @@ -809,7 +735,7 @@ public function testConvertCountryStateWithMapping(): void $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('shortCode', 'DE-NW')); - $expectedStateId = $this->getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); + $expectedStateId = static::getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); static::assertNotNull($converted); static::assertArrayHasKey('id', $converted); @@ -850,7 +776,7 @@ public function testConvertExistingCountryStateWithoutMapping(): void $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('shortCode', 'DE-NW')); - $expectedStateId = $this->getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); + $expectedStateId = static::getContainer()->get('country_state.repository')->searchIds($criteria, $context)->firstId(); static::assertNotNull($converted); static::assertArrayHasKey('id', $converted); diff --git a/tests/Profile/Shopware55/Converter/ProductConverterTest.php b/tests/Profile/Shopware55/Converter/ProductConverterTest.php index dc489f352..6c4c1873d 100644 --- a/tests/Profile/Shopware55/Converter/ProductConverterTest.php +++ b/tests/Profile/Shopware55/Converter/ProductConverterTest.php @@ -55,10 +55,10 @@ protected function setUp(): void $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class), + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class), ); $runId = Uuid::randomHex(); @@ -199,9 +199,9 @@ public function testConvertWithCategory(): void $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - $this->getContainer()->get(LanguageLookup::class), + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LanguageLookup::class), ); $categoryData = require __DIR__ . '/../../../_fixtures/category_data.php'; $productData = require __DIR__ . '/../../../_fixtures/product_data.php'; diff --git a/tests/Profile/Shopware55/Converter/ProductOptionRelationConverterTest.php b/tests/Profile/Shopware55/Converter/ProductOptionRelationConverterTest.php index c24068380..6d3134912 100644 --- a/tests/Profile/Shopware55/Converter/ProductOptionRelationConverterTest.php +++ b/tests/Profile/Shopware55/Converter/ProductOptionRelationConverterTest.php @@ -155,48 +155,4 @@ public function testConvertWithOldRelationMapping(): void static::assertSame($this->propertyUuids[0], $converted['configuratorSettings'][0]['optionId']); static::assertSame($this->oldMappingId, $converted['configuratorSettings'][0]['id']); } - - public function testConvertWithoutProductMapping(): void - { - $data = require __DIR__ . '/../../../_fixtures/product_option_relation.php'; - $data = $data[0]; - $data['productId'] = '18'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($data, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $logs = $this->loggingService->getLoggingArray(); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertEmpty($logs); - } - - public function testConvertWithoutPropertyMapping(): void - { - $relations = require __DIR__ . '/../../../_fixtures/product_option_relation.php'; - $data = $relations[0]; - $data['name'] = 'Invalid property value'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($data, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $logs = $this->loggingService->getLoggingArray(); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertEmpty($logs); - - $data = $relations[0]; - $data['group']['name'] = 'Invalid group name'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($data, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $logs = $this->loggingService->getLoggingArray(); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertEmpty($logs); - } } diff --git a/tests/Profile/Shopware55/Converter/ProductPropertyRelationConverterTest.php b/tests/Profile/Shopware55/Converter/ProductPropertyRelationConverterTest.php index 2ff6f6959..38c47a8df 100644 --- a/tests/Profile/Shopware55/Converter/ProductPropertyRelationConverterTest.php +++ b/tests/Profile/Shopware55/Converter/ProductPropertyRelationConverterTest.php @@ -101,6 +101,7 @@ public function testConvert(): void static::assertNull($convertResult->getUnmapped()); static::assertNotNull($convertResult->getMappingUuid()); + static::assertSame($this->productUuid, $converted['id']); static::assertSame($this->propertyUuids[0], $converted['properties'][0]['id']); @@ -124,48 +125,4 @@ public function testConvert(): void static::assertSame($this->productUuid, $converted['id']); static::assertSame($this->propertyUuids[2], $converted['properties'][0]['id']); } - - public function testConvertWithoutProductMapping(): void - { - $data = require __DIR__ . '/../../../_fixtures/product_property_relation.php'; - $data = $data[0]; - $data['productId'] = '18'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($data, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $logs = $this->loggingService->getLoggingArray(); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertEmpty($logs); - } - - public function testConvertWithoutPropertyMapping(): void - { - $relations = require __DIR__ . '/../../../_fixtures/product_property_relation.php'; - $data = $relations[0]; - $data['name'] = 'Invalid property value'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($data, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $logs = $this->loggingService->getLoggingArray(); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertEmpty($logs); - - $data = $relations[0]; - $data['group']['name'] = 'Invalid group name'; - - $context = Context::createDefaultContext(); - $convertResult = $this->converter->convert($data, $context, $this->migrationContext); - $this->converter->writeMapping($context); - $logs = $this->loggingService->getLoggingArray(); - - static::assertNull($convertResult->getConverted()); - static::assertNotNull($convertResult->getUnmapped()); - static::assertEmpty($logs); - } } diff --git a/tests/Profile/Shopware55/Converter/ProductReviewConverterTest.php b/tests/Profile/Shopware55/Converter/ProductReviewConverterTest.php index e06378388..9e29c30dc 100644 --- a/tests/Profile/Shopware55/Converter/ProductReviewConverterTest.php +++ b/tests/Profile/Shopware55/Converter/ProductReviewConverterTest.php @@ -54,7 +54,7 @@ protected function setUp(): void $this->converter = new Shopware55ProductReviewConverter( $mappingService, $loggingService, - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LanguageLookup::class) ); $connectionId = Uuid::randomHex(); diff --git a/tests/Profile/Shopware55/Converter/PropertyGroupOptionConverterTest.php b/tests/Profile/Shopware55/Converter/PropertyGroupOptionConverterTest.php index d23271dbb..2dbb59f9c 100644 --- a/tests/Profile/Shopware55/Converter/PropertyGroupOptionConverterTest.php +++ b/tests/Profile/Shopware55/Converter/PropertyGroupOptionConverterTest.php @@ -64,17 +64,17 @@ protected function setUp(): void $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LanguageLookup::class) ); $this->productConverter = new Shopware55ProductConverter( $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $this->optionRelationConverter = new Shopware55ProductOptionRelationConverter( diff --git a/tests/Profile/Shopware55/Converter/SalesChannelConverterTest.php b/tests/Profile/Shopware55/Converter/SalesChannelConverterTest.php index cf710474f..e0effd58f 100644 --- a/tests/Profile/Shopware55/Converter/SalesChannelConverterTest.php +++ b/tests/Profile/Shopware55/Converter/SalesChannelConverterTest.php @@ -59,7 +59,7 @@ protected function setUp(): void $countryRepo, $salesChannelRepo, null, - $this->getContainer()->get(CurrencyLookup::class), + static::getContainer()->get(CurrencyLookup::class), $languageLookup, ); diff --git a/tests/Profile/Shopware55/Converter/ShippingMethodConverterTest.php b/tests/Profile/Shopware55/Converter/ShippingMethodConverterTest.php index 0a5d5e148..4b48195da 100644 --- a/tests/Profile/Shopware55/Converter/ShippingMethodConverterTest.php +++ b/tests/Profile/Shopware55/Converter/ShippingMethodConverterTest.php @@ -66,8 +66,8 @@ protected function setUp(): void $this->shippingMethodConverter = new Shopware55ShippingMethodConverter( $this->mappingService, $this->loggingService, - $this->getContainer()->get(CountryLookup::class), - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(CountryLookup::class), + static::getContainer()->get(LanguageLookup::class) ); $runId = Uuid::randomHex(); @@ -141,7 +141,7 @@ public function testConvert(): void $shippingMethodConverter = new Shopware55ShippingMethodConverter( $this->mappingService, $this->loggingService, - $this->getContainer()->get(CountryLookup::class), + static::getContainer()->get(CountryLookup::class), $languageLookup ); diff --git a/tests/Profile/Shopware55/Converter/TranslationConverterTest.php b/tests/Profile/Shopware55/Converter/TranslationConverterTest.php index 79f958a2c..91d06d2f6 100644 --- a/tests/Profile/Shopware55/Converter/TranslationConverterTest.php +++ b/tests/Profile/Shopware55/Converter/TranslationConverterTest.php @@ -156,10 +156,10 @@ public function testConvertProductTranslation(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConverter->convert($productData[0], $context, $this->productMigrationContext); @@ -217,10 +217,10 @@ public function testConvertManufacturerTranslation(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConvertResult = $productConverter->convert($productData[0], $context, $this->productMigrationContext); @@ -261,10 +261,10 @@ public function testConvertManufacturerTranslationWithInvalidTranslationObject() $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConverter->convert($productData[0], $context, $this->productMigrationContext); @@ -290,10 +290,10 @@ public function testConvertUnitTranslation(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConvertResult = $productConverter->convert($productData[0], $context, $this->productMigrationContext); @@ -335,10 +335,10 @@ public function testConvertUnitTranslationWithInvalidTranslationObject(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConverter->convert($productData[0], $context, $this->productMigrationContext); @@ -365,9 +365,9 @@ public function testConvertCategoryTranslation(): void $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LanguageLookup::class) ); $categoryConvertResult = $categoryConverter->convert($categoryData[1], $context, $this->categoryMigrationContext); @@ -411,9 +411,9 @@ public function testConvertCategoryAttributeTranslation(): void $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LanguageLookup::class) ); $categoryConvertResult = $categoryConverter->convert($categoryData[1], $context, $this->categoryMigrationContext); @@ -480,9 +480,9 @@ public function testConvertCategoryTranslationWithInvalidTranslationObject(): vo $this->mappingService, $this->loggingService, $mediaFileService, - $this->getContainer()->get(LowestRootCategoryLookup::class), - $this->getContainer()->get(DefaultCmsPageLookup::class), - $this->getContainer()->get(LanguageLookup::class) + static::getContainer()->get(LowestRootCategoryLookup::class), + static::getContainer()->get(DefaultCmsPageLookup::class), + static::getContainer()->get(LanguageLookup::class) ); $categoryConverter->convert($categoryData[1], $context, $this->categoryMigrationContext); @@ -599,20 +599,20 @@ public function testConvertProductWithoutLocale(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConverter->convert($productData[0], $context, $this->productMigrationContext); $translationData = require __DIR__ . '/../../../_fixtures/translation_data.php'; $convertResult = $this->translationConverter->convert($translationData['productnolocale'], $context, $this->migrationContext); - static::assertNull($convertResult->getConverted()); - static::assertCount(1, $this->loggingService->getLoggingArray()); - $logs = $this->loggingService->getLoggingArray(); - static::assertSame('SWAG_MIGRATION_EMPTY_NECESSARY_FIELD', $logs[0]['code']); + $converted = $convertResult->getConverted(); + static::assertNotNull($converted); + static::assertArrayHasKey('id', $converted); + static::assertArrayHasKey('entityDefinitionClass', $converted); } public function testConvertVariantAttributeTranslation(): void @@ -626,10 +626,10 @@ public function testConvertVariantAttributeTranslation(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConverter->convert($productData[0], $context, $this->productMigrationContext); @@ -762,10 +762,10 @@ public function testConvertProductTranslationsWithSeoData(): void $this->mappingService, $this->loggingService, new DummyMediaFileService(), - $this->getContainer()->get(TaxLookup::class), - $this->getContainer()->get(MediaDefaultFolderLookup::class), - $this->getContainer()->get(LanguageLookup::class), - $this->getContainer()->get(DeliveryTimeLookup::class) + static::getContainer()->get(TaxLookup::class), + static::getContainer()->get(MediaDefaultFolderLookup::class), + static::getContainer()->get(LanguageLookup::class), + static::getContainer()->get(DeliveryTimeLookup::class) ); $productConverter->convert($productData[0], $context, $this->productMigrationContext); diff --git a/tests/Profile/Shopware6/Converter/LanguageConverterConvertDataTest.php b/tests/Profile/Shopware6/Converter/LanguageConverterConvertDataTest.php index 559e23a42..71d47e5d7 100644 --- a/tests/Profile/Shopware6/Converter/LanguageConverterConvertDataTest.php +++ b/tests/Profile/Shopware6/Converter/LanguageConverterConvertDataTest.php @@ -52,7 +52,7 @@ public function testConvertData(): void ]; $result = $languageConverter->convert($data, $context, $migrationContext); - $converted = $result->getConverted() ?? []; + $converted = $result?->getConverted() ?? []; static::assertArrayHasKey('id', $converted); static::assertSame($languageId, $converted['id']); @@ -80,7 +80,7 @@ public function testConvertDataShouldNotOverwriteTheDefaultLanguage(): void ]; $result = $languageConverter->convert($data, $context, $migrationContext); - $converted = $result->getConverted() ?? []; + $converted = $result?->getConverted() ?? []; static::assertArrayHasKey('id', $converted); static::assertNotSame($defaultLanguageId, $converted['id']); @@ -106,7 +106,7 @@ public function testCheckDataForDefaultLanguageShouldReturnDataUnchangedWitNoDef $languageConverter = $this->createLanguageConverter($mappingServiceMock, null, $languageLookupMock); $result = $languageConverter->convert($data, $context, $migrationContext); - $converted = $result->getConverted() ?? []; + $converted = $result?->getConverted() ?? []; static::assertArrayHasKey('id', $converted); static::assertSame($expectedId, $converted['id']); @@ -133,7 +133,7 @@ public function testCheckDataForDefaultLanguageShouldReturnDataUnchangedWitNoDef $languageConverter = $this->createLanguageConverter($mappingServiceMock); $result = $languageConverter->convert($data, $context, $migrationContext); - $converted = $result->getConverted() ?? []; + $converted = $result?->getConverted() ?? []; static::assertArrayHasKey('id', $converted); static::assertSame($expectedId, $converted['id']); @@ -148,8 +148,8 @@ private function createLanguageConverter( return new LanguageConverter( $mappingService ?? new Dummy6MappingService(), $loggingService ?? $this->createMock(LoggingServiceInterface::class), - $languageLookup ?? $this->getContainer()->get(LanguageLookup::class), - $localeLookup ?? $this->getContainer()->get(LocaleLookup::class) + $languageLookup ?? static::getContainer()->get(LanguageLookup::class), + $localeLookup ?? static::getContainer()->get(LocaleLookup::class) ); } diff --git a/tests/Profile/Shopware6/Converter/LanguageConverterTest.php b/tests/Profile/Shopware6/Converter/LanguageConverterTest.php index 639ee685d..1c0d67d36 100644 --- a/tests/Profile/Shopware6/Converter/LanguageConverterTest.php +++ b/tests/Profile/Shopware6/Converter/LanguageConverterTest.php @@ -34,7 +34,7 @@ protected function createConverter( return new LanguageConverter( $mappingService, $loggingService, - $this->getContainer()->get(LanguageLookup::class), + static::getContainer()->get(LanguageLookup::class), $localeLookup ); } diff --git a/tests/Profile/Shopware6/Converter/NumberRangeConverterTest.php b/tests/Profile/Shopware6/Converter/NumberRangeConverterTest.php index aab7ad1c7..e7b90b669 100644 --- a/tests/Profile/Shopware6/Converter/NumberRangeConverterTest.php +++ b/tests/Profile/Shopware6/Converter/NumberRangeConverterTest.php @@ -45,7 +45,7 @@ protected function createConverter( return new NumberRangeConverter( $mappingService, $loggingService, - $this->getContainer()->get('number_range_state.repository'), + static::getContainer()->get('number_range_state.repository'), $numberRangeLookup, $numberRangeTypeLookup ); diff --git a/tests/Profile/Shopware6/Converter/SalesChannelConverterTest.php b/tests/Profile/Shopware6/Converter/SalesChannelConverterTest.php index 054d63776..d31fd732f 100644 --- a/tests/Profile/Shopware6/Converter/SalesChannelConverterTest.php +++ b/tests/Profile/Shopware6/Converter/SalesChannelConverterTest.php @@ -11,6 +11,7 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConverterInterface; +use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet; use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; @@ -44,6 +45,7 @@ public function testConvert(string $fixtureFolderPath): void $context = Context::createDefaultContext(); $convertResult = $this->converter->convert($input, $context, $this->migrationContext); + static::assertInstanceOf(ConvertStruct::class, $convertResult); $output = $convertResult->getConverted(); static::assertNotNull($output); diff --git a/tests/Profile/Shopware6/Converter/SeoUrlConverterConvertDataTest.php b/tests/Profile/Shopware6/Converter/SeoUrlConverterConvertDataTest.php index eca23847e..997657af9 100644 --- a/tests/Profile/Shopware6/Converter/SeoUrlConverterConvertDataTest.php +++ b/tests/Profile/Shopware6/Converter/SeoUrlConverterConvertDataTest.php @@ -23,16 +23,15 @@ class SeoUrlConverterConvertDataTest extends TestCase { use IntegrationTestBehaviour; - public function testConvertSkipConvertionIfSeoUrlIsUnmodified(): void + public function testConvertIfSeoUrlIsUnmodified(): void { $data = [ 'isModified' => false, ]; $seoUrlConverter = $this->createSeoUrlConverter(); - $result = $seoUrlConverter->convert($data, Context::createDefaultContext(), $this->createMigrationContext()); - static::assertNull($result->getConverted()); - static::assertSame($data, $result->getUnmapped()); + + static::assertNull($seoUrlConverter->convert($data, Context::createDefaultContext(), $this->createMigrationContext())); } private function createSeoUrlConverter(): SeoUrlConverter diff --git a/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php b/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php index fe76c80b5..6d9bd13da 100644 --- a/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php +++ b/tests/Profile/Shopware6/Converter/ShopwareConverterTest.php @@ -111,12 +111,13 @@ public function testConvert(string $fixtureFolderPath): void $context = Context::createDefaultContext(); $convertResult = $this->converter->convert($input, $context, $this->migrationContext); - $output = $convertResult->getConverted(); + $output = $convertResult?->getConverted(); $fixtureName = \basename($fixtureFolderPath); if ($output !== null) { - static::assertNotNull($convertResult->getMappingUuid(), $this->getAssertMessage($fixtureName . ': No mappingUuid in converted result struct.')); + static::assertNotNull($convertResult?->getMappingUuid(), $this->getAssertMessage($fixtureName . ': No mappingUuid in converted result struct.')); } + static::assertSame($expectedOutput, $output, $this->getAssertMessage($fixtureName . ': Output of converter does not match.')); $logs = $this->loggingService->getLoggingArray(); @@ -127,6 +128,7 @@ public function testConvert(string $fixtureFolderPath): void $realLog = $logs[$index]; foreach (\array_keys($expectedLog) as $key) { + static::assertArrayHasKey($key, $realLog, $fixtureName . ': Array key: "' . $key . '" not found in converted log result.'); static::assertSame($expectedLog[$key], $realLog[$key], $this->getAssertMessage($fixtureName . ': Log key not as expected (make sure the log array order matches the logging order).')); } } diff --git a/tests/ServiceCorrectArgumentsTest.php b/tests/ServiceCorrectArgumentsTest.php index 43cb4d9b0..9f289e6f1 100644 --- a/tests/ServiceCorrectArgumentsTest.php +++ b/tests/ServiceCorrectArgumentsTest.php @@ -21,7 +21,7 @@ class ServiceCorrectArgumentsTest extends TestCase #[DataProvider('serviceProvider')] public function testServiceShouldHaveCorrectArgumentsInContainer(string $xmlPath, string $serviceId): void { - $service = $this->getContainer()->get($serviceId); + $service = static::getContainer()->get($serviceId); static::assertNotNull($service); } diff --git a/tests/_fixtures/Shopware6/CmsPage/03-LockedLayouts/log.php b/tests/_fixtures/Shopware6/CmsPage/03-LockedLayouts/log.php new file mode 100644 index 000000000..2c3ce3366 --- /dev/null +++ b/tests/_fixtures/Shopware6/CmsPage/03-LockedLayouts/log.php @@ -0,0 +1,8 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return []; diff --git a/tests/_fixtures/Shopware6/CustomerWishlist/02-CustomerNotFound/output.php b/tests/_fixtures/Shopware6/CustomerWishlist/02-CustomerNotFound/output.php index b3b8fd1cb..4d5e8d071 100644 --- a/tests/_fixtures/Shopware6/CustomerWishlist/02-CustomerNotFound/output.php +++ b/tests/_fixtures/Shopware6/CustomerWishlist/02-CustomerNotFound/output.php @@ -5,4 +5,35 @@ * file that was distributed with this source code. */ -return null; +return [ + 'customerId' => null, + 'salesChannelId' => 'a8084cf2687b44db91f3277b57cc3d7a', + 'products' => [ + 0 => [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => 'ea56f971f7da442eaaca1be96b4207ee', + 'id' => '062b658b0e1b43869c290551b6421738', + ], + 1 => [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '41dd1b755e5840fbbe19a632b61c42a0', + 'id' => '2f2b5cd9a0e449c79b71889bd494f412', + ], + 2 => [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '785485416afc4cc4acf44a607a10f67e', + 'id' => '5068f5ad4a744daeba8a0ec68bc3f583', + ], + 3 => [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '9abedec2f3784d57b35a3c15a6ae96d1', + 'id' => '5a8c6a68750b4942b8da0543813aeb5b', + ], + 4 => [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '1ae95316283f43cb917960b5c9822f25', + 'id' => '6f8ff63bfebe4e3485626947d8b769ca', + ], + ], + 'id' => 'd40f6c0ffe2a4e8a8dec97374920ad51', +]; diff --git a/tests/_fixtures/Shopware6/CustomerWishlist/03-SalesChannelNotFound/output.php b/tests/_fixtures/Shopware6/CustomerWishlist/03-SalesChannelNotFound/output.php index b3b8fd1cb..96e855350 100644 --- a/tests/_fixtures/Shopware6/CustomerWishlist/03-SalesChannelNotFound/output.php +++ b/tests/_fixtures/Shopware6/CustomerWishlist/03-SalesChannelNotFound/output.php @@ -5,4 +5,35 @@ * file that was distributed with this source code. */ -return null; +return [ + 'customerId' => '872e88b6d30048e388b018f7a0be6a1e', + 'salesChannelId' => null, + 'products' => [ + [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => 'ea56f971f7da442eaaca1be96b4207ee', + 'id' => '062b658b0e1b43869c290551b6421738', + ], + [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '41dd1b755e5840fbbe19a632b61c42a0', + 'id' => '2f2b5cd9a0e449c79b71889bd494f412', + ], + [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '785485416afc4cc4acf44a607a10f67e', + 'id' => '5068f5ad4a744daeba8a0ec68bc3f583', + ], + [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '9abedec2f3784d57b35a3c15a6ae96d1', + 'id' => '5a8c6a68750b4942b8da0543813aeb5b', + ], + [ + 'wishlistId' => 'd40f6c0ffe2a4e8a8dec97374920ad51', + 'productId' => '1ae95316283f43cb917960b5c9822f25', + 'id' => '6f8ff63bfebe4e3485626947d8b769ca', + ], + ], + 'id' => 'd40f6c0ffe2a4e8a8dec97374920ad51', +]; diff --git a/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/log.php b/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/log.php index 9404a4271..2c3ce3366 100644 --- a/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/log.php +++ b/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/log.php @@ -5,8 +5,4 @@ * file that was distributed with this source code. */ -return [ - [ - 'code' => 'SWAG_MIGRATION__SHOPWARE_UNSUPPORTED_MAIL_TEMPLATE_TYPE', - ], -]; +return []; diff --git a/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/output.php b/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/output.php index b3b8fd1cb..79cdba237 100644 --- a/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/output.php +++ b/tests/_fixtures/Shopware6/MailTemplate/02-MailTypeNotExists/output.php @@ -5,4 +5,109 @@ * file that was distributed with this source code. */ -return null; +return [ + 'id' => 'fee20daa2f2a45178c808f2f69b686d4', + 'mailTemplateTypeId' => null, + 'systemDefault' => true, + 'senderName' => '{{ shopName }}', + 'description' => '', + 'subject' => 'Password recovery', + 'contentHtml' => ' + + Hello {{ customerRecovery.customer.firstName }} {{ customerRecovery.customer.lastName }}, + + You have requested a new password for your {{ shopName }} account. + Click on the following link to reset your password: + + {{ resetUrl }} + + This link is valid for the next 2 hours. + If you don\'t want to reset your password, ignore this email and no changes will be made. + + Yours sincerely + Your {{ shopName }} team + +', + 'contentPlain' => ' Hello {{ customerRecovery.customer.firstName }} {{ customerRecovery.customer.lastName }}, + + You have requested a new password for your {{ shopName }} account. + Click on the following link to reset your password: + + {{ resetUrl }} + + This link is valid for the next 2 hours. + If you don\'t want to reset your password, ignore this email and no changes will be made. + + Yours sincerely + Your {{ shopName }}-Team', + 'translations' => [ + [ + 'senderName' => '{{ shopName }}', + 'description' => '', + 'subject' => 'Password recovery', + 'contentHtml' => ' + + Hello {{ customerRecovery.customer.firstName }} {{ customerRecovery.customer.lastName }}, + + You have requested a new password for your {{ shopName }} account. + Click on the following link to reset your password: + + {{ resetUrl }} + + This link is valid for the next 2 hours. + If you don\'t want to reset your password, ignore this email and no changes will be made. + + Yours sincerely + Your {{ shopName }} team + +', + 'contentPlain' => ' Hello {{ customerRecovery.customer.firstName }} {{ customerRecovery.customer.lastName }}, + + You have requested a new password for your {{ shopName }} account. + Click on the following link to reset your password: + + {{ resetUrl }} + + This link is valid for the next 2 hours. + If you don\'t want to reset your password, ignore this email and no changes will be made. + + Yours sincerely + Your {{ shopName }}-Team', + 'languageId' => '5dd637353d044752ae6a8c6e7f53430b', + ], + [ + 'senderName' => '{{ shopName }}', + 'description' => '', + 'subject' => 'Password Wiederherstellung', + 'contentHtml' => ' + + Hallo {{ customerRecovery.customer.firstName }} {{ customerRecovery.customer.lastName }}, + + Sie haben ein neues Passwort für Ihren {{ shopName }}-Account angefordert. + Klicken Sie auf folgenden Link, um Ihr Passwort zurückzusetzen: + + {{ resetUrl }} + + Dieser Link ist für die nächsten 2 Stunden gültig. + Falls Sie Ihr Passwort nicht zurücksetzen möchten, ignorieren Sie diese E-Mail - es wird dann keine Änderung vorgenommen. + + Mit freundlichen Grüßen + Ihr {{ shopName }}-Team + +', + 'contentPlain' => ' Hallo {{ customerRecovery.customer.firstName }} {{ customerRecovery.customer.lastName }}, + + Sie haben ein neues Passwort für Ihren {{ shopName }}-Account angefordert. + Klicken Sie auf folgenden Link, um Ihr Passwort zurückzusetzen: + + {{ resetUrl }} + + Dieser Link ist für die nächsten 2 Stunden gültig. + Falls Sie Ihr Passwort nicht zurücksetzen möchten, ignorieren Sie diese E-Mail - es wird dann keine Änderung vorgenommen. + + Mit freundlichen Grüßen + Ihr {{ shopName }}-Team', + 'languageId' => '60d637353d044752ae6a8c6e7f53430b', + ], + ], +]; diff --git a/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/log.php b/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/log.php index 88da8232a..2c3ce3366 100644 --- a/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/log.php +++ b/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/log.php @@ -5,8 +5,4 @@ * file that was distributed with this source code. */ -return [ - [ - 'code' => 'SWAG_MIGRATION__SHOPWARE_UNSUPPORTED_NUMBER_RANGE_TYPE', - ], -]; +return []; diff --git a/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/output.php b/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/output.php index b3b8fd1cb..b717c21b8 100644 --- a/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/output.php +++ b/tests/_fixtures/Shopware6/NumberRange/02-TypeNotExists/output.php @@ -5,4 +5,18 @@ * file that was distributed with this source code. */ -return null; +return [ + 'id' => '69ed66543f8d401b82040533984e99ee', + 'typeId' => null, + 'global' => false, + 'name' => 'Coole Number Range', + 'pattern' => 'cool_{n}_best', + 'start' => 100, + 'translations' => [ + [ + 'numberRangeId' => '69ed66543f8d401b82040533984e99ee', + 'name' => 'Coole Number Range', + 'languageId' => '5dd637353d044752ae6a8c6e7f53430b', + ], + ], +]; diff --git a/tests/integration/Migration/ErrorResolution/MigrationFixTest.php b/tests/integration/Migration/ErrorResolution/MigrationFixTest.php index 19bce751d..3f9f13e8d 100644 --- a/tests/integration/Migration/ErrorResolution/MigrationFixTest.php +++ b/tests/integration/Migration/ErrorResolution/MigrationFixTest.php @@ -43,8 +43,8 @@ class MigrationFixTest extends TestCase protected function setUp(): void { - $this->migrationFixRepository = $this->getContainer()->get('swag_migration_fix.repository'); - $this->connectionRepository = $this->getContainer()->get('swag_migration_connection.repository'); + $this->migrationFixRepository = static::getContainer()->get('swag_migration_fix.repository'); + $this->connectionRepository = static::getContainer()->get('swag_migration_connection.repository'); } #[DataProvider('valueData')] diff --git a/tests/integration/Migration/Validation/MigrationValidationServiceTest.php b/tests/integration/Migration/Validation/MigrationValidationServiceTest.php index 76898fbc1..fa4748df4 100644 --- a/tests/integration/Migration/Validation/MigrationValidationServiceTest.php +++ b/tests/integration/Migration/Validation/MigrationValidationServiceTest.php @@ -70,14 +70,14 @@ class MigrationValidationServiceTest extends TestCase protected function setUp(): void { - $this->validationService = $this->getContainer()->get(MigrationValidationService::class); - $this->loggingRepo = $this->getContainer()->get('swag_migration_logging.repository'); - $this->runRepo = $this->getContainer()->get('swag_migration_run.repository'); - $this->mappingRepo = $this->getContainer()->get(SwagMigrationMappingDefinition::ENTITY_NAME . '.repository'); + $this->validationService = static::getContainer()->get(MigrationValidationService::class); + $this->loggingRepo = static::getContainer()->get('swag_migration_logging.repository'); + $this->runRepo = static::getContainer()->get('swag_migration_run.repository'); + $this->mappingRepo = static::getContainer()->get(SwagMigrationMappingDefinition::ENTITY_NAME . '.repository'); $this->context = Context::createDefaultContext(); $this->runId = Uuid::randomHex(); - $this->getContainer()->get('swag_migration_connection.repository')->create( + static::getContainer()->get('swag_migration_connection.repository')->create( [ [ 'id' => self::CONNECTION_ID,