Updated to latest shlink-importer, with support to import on a specific domain for YOURLS

This commit is contained in:
Alejandro Celaya 2022-04-13 12:40:21 +02:00
parent ab65593f7d
commit 21534b78cb
3 changed files with 18 additions and 10 deletions

View File

@ -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",

View File

@ -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 */

View File

@ -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],
);
}
}