diff --git a/composer.json b/composer.json index e0ffd0de..94696f27 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "shlinkio/shlink-common": "^4.4", "shlinkio/shlink-config": "^1.6", "shlinkio/shlink-event-dispatcher": "^2.3", - "shlinkio/shlink-importer": "^2.5", + "shlinkio/shlink-importer": "dev-main#75d50f9 as 3.0", "shlinkio/shlink-installer": "dev-develop#d02f256 as 7.1", "shlinkio/shlink-ip-geolocation": "^2.2", "symfony/console": "^6.0", diff --git a/module/Core/src/Importer/ImportedLinksProcessor.php b/module/Core/src/Importer/ImportedLinksProcessor.php index fe4f24df..2ed57527 100644 --- a/module/Core/src/Importer/ImportedLinksProcessor.php +++ b/module/Core/src/Importer/ImportedLinksProcessor.php @@ -13,6 +13,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Resolver\ShortUrlRelationResolverInterface; use Shlinkio\Shlink\Core\Util\DoctrineBatchHelperInterface; use Shlinkio\Shlink\Importer\ImportedLinksProcessorInterface; use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; +use Shlinkio\Shlink\Importer\Params\ImportParams; use Shlinkio\Shlink\Importer\Sources\ImportSources; use Symfony\Component\Console\Style\StyleInterface; @@ -34,10 +35,10 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface /** * @param iterable|ImportedShlinkUrl[] $shlinkUrls */ - public function process(StyleInterface $io, iterable $shlinkUrls, array $params): void + public function process(StyleInterface $io, iterable $shlinkUrls, ImportParams $params): void { - $importShortCodes = $params['import_short_codes']; - $source = $params['source']; + $importShortCodes = $params->importShortCodes(); + $source = $params->source(); $iterable = $this->batchHelper->wrapIterable($shlinkUrls, $source === ImportSources::SHLINK ? 10 : 100); /** @var ImportedShlinkUrl $importedUrl */ diff --git a/module/Core/test/Importer/ImportedLinksProcessorTest.php b/module/Core/test/Importer/ImportedLinksProcessorTest.php index 70662bb1..4760448c 100644 --- a/module/Core/test/Importer/ImportedLinksProcessorTest.php +++ b/module/Core/test/Importer/ImportedLinksProcessorTest.php @@ -20,6 +20,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Resolver\SimpleShortUrlRelationResolver; use Shlinkio\Shlink\Core\Util\DoctrineBatchHelperInterface; use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; use Shlinkio\Shlink\Importer\Model\ImportedShlinkVisit; +use Shlinkio\Shlink\Importer\Params\ImportParams; use Shlinkio\Shlink\Importer\Sources\ImportSources; use Symfony\Component\Console\Style\StyleInterface; @@ -32,8 +33,6 @@ class ImportedLinksProcessorTest extends TestCase { use ProphecyTrait; - private const PARAMS = ['import_short_codes' => true, 'source' => ImportSources::BITLY]; - private ImportedLinksProcessor $processor; private ObjectProphecy $em; private ObjectProphecy $shortCodeHelper; @@ -74,7 +73,7 @@ class ImportedLinksProcessorTest extends TestCase $ensureUniqueness = $this->shortCodeHelper->ensureShortCodeUniqueness(Argument::cetera())->willReturn(true); $persist = $this->em->persist(Argument::type(ShortUrl::class)); - $this->processor->process($this->io->reveal(), $urls, self::PARAMS); + $this->processor->process($this->io->reveal(), $urls, $this->buildParams()); $importedUrlExists->shouldHaveBeenCalledTimes($expectedCalls); $ensureUniqueness->shouldHaveBeenCalledTimes($expectedCalls); @@ -104,7 +103,7 @@ class ImportedLinksProcessorTest extends TestCase $ensureUniqueness = $this->shortCodeHelper->ensureShortCodeUniqueness(Argument::cetera())->willReturn(true); $persist = $this->em->persist(Argument::type(ShortUrl::class)); - $this->processor->process($this->io->reveal(), $urls, self::PARAMS); + $this->processor->process($this->io->reveal(), $urls, $this->buildParams()); $importedUrlExists->shouldHaveBeenCalledTimes(count($urls)); $ensureUniqueness->shouldHaveBeenCalledTimes(2); @@ -141,7 +140,7 @@ class ImportedLinksProcessorTest extends TestCase }); $persist = $this->em->persist(Argument::type(ShortUrl::class)); - $this->processor->process($this->io->reveal(), $urls, self::PARAMS); + $this->processor->process($this->io->reveal(), $urls, $this->buildParams()); $importedUrlExists->shouldHaveBeenCalledTimes(count($urls)); $failingEnsureUniqueness->shouldHaveBeenCalledTimes(5); @@ -167,7 +166,7 @@ class ImportedLinksProcessorTest extends TestCase $persistUrl = $this->em->persist(Argument::type(ShortUrl::class)); $persistVisits = $this->em->persist(Argument::type(Visit::class)); - $this->processor->process($this->io->reveal(), [$importedUrl], self::PARAMS); + $this->processor->process($this->io->reveal(), [$importedUrl], $this->buildParams()); $findExisting->shouldHaveBeenCalledOnce(); $ensureUniqueness->shouldHaveBeenCalledTimes($foundShortUrl === null ? 1 : 0); @@ -214,4 +213,12 @@ class ImportedLinksProcessorTest extends TestCase ])), ]; } + + private function buildParams(): ImportParams + { + return ImportParams::fromSourceAndCallableMap( + ImportSources::BITLY, + ['import_short_codes' => static fn () => true], + ); + } }