diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index 22af5226..9c656690 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -25,7 +25,6 @@ public function let( ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterLocalesResolverInterface $importerLocalesResolver, ImporterProductsResolverInterface $importerProductsResolver, ImporterTaxonsResolverInterface $importerTaxonsResolver, ImporterProductsInTaxonsResolverInterface $importerProductsInTaxonsResolver, @@ -36,7 +35,6 @@ public function let( $blockResourceResolver, $importerCollectionsResolver, $importerChannelsResolver, - $importerLocalesResolver, $importerProductsResolver, $importerTaxonsResolver, $importerProductsInTaxonsResolver, @@ -55,7 +53,6 @@ public function it_imports_block( ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterLocalesResolverInterface $importerLocalesResolver, ImporterProductsResolverInterface $importerProductsResolver, ImporterTaxonsResolverInterface $importerTaxonsResolver, ImporterProductsInTaxonsResolverInterface $importerProductsInTaxonsResolver, @@ -73,7 +70,6 @@ public function it_imports_block( $importerCollectionsResolver->resolve($block, null)->shouldBeCalled(); $importerChannelsResolver->resolve($block, null)->shouldBeCalled(); - $importerLocalesResolver->resolve($block, null)->shouldBeCalled(); $importerProductsResolver->resolve($block, null)->shouldBeCalled(); $importerTaxonsResolver->resolve($block, null)->shouldBeCalled(); $importerProductsInTaxonsResolver->resolve($block, null)->shouldBeCalled(); diff --git a/spec/Resolver/BlockResourceResolverSpec.php b/spec/Resolver/BlockResourceResolverSpec.php index 45d77c9e..b87eb206 100755 --- a/spec/Resolver/BlockResourceResolverSpec.php +++ b/spec/Resolver/BlockResourceResolverSpec.php @@ -4,7 +4,6 @@ namespace spec\Sylius\CmsPlugin\Resolver; -use Doctrine\Common\Collections\ArrayCollection; use PhpSpec\ObjectBehavior; use Psr\Log\LoggerInterface; use Sylius\CmsPlugin\Entity\BlockInterface; @@ -14,7 +13,6 @@ use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; -use Sylius\Component\Locale\Model\LocaleInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; final class BlockResourceResolverSpec extends ObjectBehavior @@ -39,74 +37,15 @@ public function it_implements_block_resource_resolver_interface(): void $this->shouldHaveType(BlockResourceResolverInterface::class); } - public function it_logs_warning_if_block_was_not_found( - BlockRepositoryInterface $blockRepository, - LoggerInterface $logger, - ChannelContextInterface $channelContext, - ChannelInterface $channel, - ) { - $channel->getCode()->willReturn('WEB'); - $channelContext->getChannel()->willReturn($channel); - $blockRepository->findEnabledByCode('homepage_banner', 'WEB')->willReturn(null); - - $logger - ->warning(sprintf( - 'Block with "%s" code was not found in the database.', - 'homepage_banner', - )) - ->shouldBeCalled() - ; - - $this->findOrLog('homepage_banner'); - } - - public function it_logs_warning_if_block_was_found_but_it_does_not_have_locale( - BlockRepositoryInterface $blockRepository, - LoggerInterface $logger, - ChannelContextInterface $channelContext, - ChannelInterface $channel, - LocaleContextInterface $localeContext, - LocaleInterface $locale, - RepositoryInterface $localeRepository, - BlockInterface $block, - ) { - $channel->getCode()->willReturn('WEB'); - $channelContext->getChannel()->willReturn($channel); - $blockRepository->findEnabledByCode('homepage_banner', 'WEB')->willReturn($block); - $localeContext->getLocaleCode()->willReturn('en_US'); - $locale->getCode()->willReturn('en_US'); - $localeRepository->findOneBy(['code' => 'en_US'])->willReturn($locale); - $block->hasLocale($locale)->willReturn(false); - $block->getLocales()->willReturn(new ArrayCollection(['pl_PL'])); - - $logger - ->warning(sprintf( - 'Block with "%s" code was found in the database, but it does not have "%s" locale.', - 'homepage_banner', - 'en_US', - )) - ->shouldBeCalled() - ; - - $this->findOrLog('homepage_banner'); - } - public function it_returns_block_if_found_in_database( BlockRepositoryInterface $blockRepository, BlockInterface $block, ChannelContextInterface $channelContext, ChannelInterface $channel, - LocaleContextInterface $localeContext, - LocaleInterface $locale, - RepositoryInterface $localeRepository, ) { $channel->getCode()->willReturn('WEB'); $channelContext->getChannel()->willReturn($channel); $blockRepository->findEnabledByCode('homepage_banner', 'WEB')->willReturn($block); - $localeContext->getLocaleCode()->willReturn('en_US'); - $locale->getCode()->willReturn('en_US'); - $localeRepository->findOneBy(['code' => 'en_US'])->willReturn($locale); - $block->hasLocale($locale)->willReturn(true); $this->findOrLog('homepage_banner')->shouldReturn($block); } diff --git a/src/Importer/AbstractImporter.php b/src/Importer/AbstractImporter.php index 7df177e3..e053006b 100755 --- a/src/Importer/AbstractImporter.php +++ b/src/Importer/AbstractImporter.php @@ -35,15 +35,15 @@ protected function getTranslatableColumnValue( protected function getAvailableLocales(array $translatableColumns, array $columns): array { $locales = []; - foreach ($translatableColumns as $translatableColumn) { $translatableColumn = str_replace('__locale__', '_', $translatableColumn); foreach ($columns as $column) { - if ( - str_starts_with($column, $translatableColumn) && - preg_match('/^' . preg_quote($translatableColumn, '/') . '([a-z]{2}_[A-Z]{2})$/', $column, $matches) - ) { - $locales[] = $matches[1]; + if (str_starts_with($column, $translatableColumn)) { + $localePart = substr($column, strlen($translatableColumn)); + + if (preg_match('/^[a-z]{2}(_[A-Z]{2})?$/', $localePart)) { + $locales[] = $localePart; + } } } }