Allowed to optionally import visits from other shlink instance

This commit is contained in:
Alejandro Celaya 2021-04-11 13:30:12 +02:00
parent 1efa973507
commit 09414a8834
2 changed files with 14 additions and 9 deletions

View File

@ -49,7 +49,7 @@
"shlinkio/shlink-common": "dev-main#554e370 as 3.7",
"shlinkio/shlink-config": "^1.0",
"shlinkio/shlink-event-dispatcher": "^2.1",
"shlinkio/shlink-importer": "dev-main#174e352 as 2.3",
"shlinkio/shlink-importer": "dev-main#39928b6 as 2.3",
"shlinkio/shlink-installer": "dev-develop#aa50ea9 as 5.5",
"shlinkio/shlink-ip-geolocation": "^1.5",
"symfony/console": "^5.1",

View File

@ -64,14 +64,7 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface
}
$this->em->persist($shortUrl);
// TODO Process only missing visits when possible: $importedUrl->visitsCount();
// TODO Make importing visits optional based on params
$importedVisits = 0;
foreach ($importedUrl->visits() as $importedVisit) {
$this->em->persist(Visit::fromImport($importedVisit, $shortUrl));
$importedVisits++;
}
$importedVisits = $this->importVisits($importedUrl, $shortUrl);
$io->text(
$importedVisits === 0
@ -105,4 +98,16 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface
return $this->shortCodeHelper->ensureShortCodeUniqueness($shortUrl, false);
}
private function importVisits(ImportedShlinkUrl $importedUrl, ShortUrl $shortUrl): int
{
// TODO Process only missing visits when possible: $importedUrl->visitsCount();
$importedVisits = 0;
foreach ($importedUrl->visits() as $importedVisit) {
$this->em->persist(Visit::fromImport($importedVisit, $shortUrl));
$importedVisits++;
}
return $importedVisits;
}
}