mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Updated ShortUrl importing to take metadata into account
This commit is contained in:
parent
086efe3c63
commit
743bb7a6ee
@ -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": "^2.2",
|
||||
"shlinkio/shlink-importer": "dev-main#d7e2762 as 2.3",
|
||||
"shlinkio/shlink-installer": "dev-develop#aa50ea9 as 5.5",
|
||||
"shlinkio/shlink-ip-geolocation": "^1.5",
|
||||
"symfony/console": "^5.1",
|
||||
|
@ -86,17 +86,29 @@ class ShortUrl extends AbstractEntity
|
||||
?ShortUrlRelationResolverInterface $relationResolver = null
|
||||
): self {
|
||||
$meta = [
|
||||
ShortUrlInputFilter::VALIDATE_URL => false,
|
||||
ShortUrlInputFilter::LONG_URL => $url->longUrl(),
|
||||
ShortUrlInputFilter::DOMAIN => $url->domain(),
|
||||
ShortUrlInputFilter::TAGS => $url->tags(),
|
||||
ShortUrlInputFilter::TITLE => $url->title(),
|
||||
ShortUrlInputFilter::VALIDATE_URL => false,
|
||||
ShortUrlInputFilter::MAX_VISITS => $url->meta()->maxVisits(),
|
||||
];
|
||||
if ($importShortCode) {
|
||||
$meta[ShortUrlInputFilter::CUSTOM_SLUG] = $url->shortCode();
|
||||
}
|
||||
|
||||
$instance = self::fromMeta(ShortUrlMeta::fromRawData($meta), $relationResolver);
|
||||
|
||||
$validSince = $url->meta()->validSince();
|
||||
if ($validSince !== null) {
|
||||
$instance->validSince = Chronos::instance($validSince);
|
||||
}
|
||||
|
||||
$validUntil = $url->meta()->validUntil();
|
||||
if ($validUntil !== null) {
|
||||
$instance->validUntil = Chronos::instance($validUntil);
|
||||
}
|
||||
|
||||
$instance->importSource = $url->source();
|
||||
$instance->importOriginalShortCode = $url->shortCode();
|
||||
$instance->dateCreated = Chronos::instance($url->createdAt());
|
||||
|
@ -51,17 +51,24 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
||||
|
||||
// Skip already imported URLs
|
||||
if ($shortUrlRepo->importedUrlExists($url)) {
|
||||
// TODO If the URL exists, allow to merge visits instead of just skipping completely
|
||||
$io->text(sprintf('%s: <comment>Skipped</comment>', $longUrl));
|
||||
continue;
|
||||
}
|
||||
|
||||
$shortUrl = ShortUrl::fromImport($url, $importShortCodes, $this->relationResolver);
|
||||
if (! $this->handleShortCodeUniqueness($url, $shortUrl, $io, $importShortCodes)) {
|
||||
$io->text(sprintf('%s: <comment>Skipped</comment>', $longUrl));
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->em->persist($shortUrl);
|
||||
$io->text(sprintf('%s: <info>Imported</info>', $longUrl));
|
||||
|
||||
// Process only missing visits when possible
|
||||
if ($url->visitsCount() !== null) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +91,6 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
||||
), ['Generate new short-code', 'Skip'], 1);
|
||||
|
||||
if ($action === 'Skip') {
|
||||
$io->text(sprintf('%s: <comment>Skipped</comment>', $longUrl));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user