mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added feedback to ImportedLinksProcessor
This commit is contained in:
parent
ec3e7212b2
commit
2256f6a9e7
@ -53,7 +53,7 @@
|
|||||||
"shlinkio/shlink-common": "^3.2.0",
|
"shlinkio/shlink-common": "^3.2.0",
|
||||||
"shlinkio/shlink-config": "^1.0",
|
"shlinkio/shlink-config": "^1.0",
|
||||||
"shlinkio/shlink-event-dispatcher": "^1.4",
|
"shlinkio/shlink-event-dispatcher": "^1.4",
|
||||||
"shlinkio/shlink-importer": "^1.0.1",
|
"shlinkio/shlink-importer": "^2.0",
|
||||||
"shlinkio/shlink-installer": "^5.1.0",
|
"shlinkio/shlink-installer": "^5.1.0",
|
||||||
"shlinkio/shlink-ip-geolocation": "^1.5",
|
"shlinkio/shlink-ip-geolocation": "^1.5",
|
||||||
"symfony/console": "^5.1",
|
"symfony/console": "^5.1",
|
||||||
|
@ -59,7 +59,6 @@ class ShortUrl extends AbstractEntity
|
|||||||
|
|
||||||
public static function fromImport(
|
public static function fromImport(
|
||||||
ImportedShlinkUrl $url,
|
ImportedShlinkUrl $url,
|
||||||
string $source,
|
|
||||||
bool $importShortCode,
|
bool $importShortCode,
|
||||||
?DomainResolverInterface $domainResolver = null
|
?DomainResolverInterface $domainResolver = null
|
||||||
): self {
|
): self {
|
||||||
@ -72,7 +71,7 @@ class ShortUrl extends AbstractEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
$instance = new self($url->longUrl(), ShortUrlMeta::fromRawData($meta), $domainResolver);
|
$instance = new self($url->longUrl(), ShortUrlMeta::fromRawData($meta), $domainResolver);
|
||||||
$instance->importSource = $source;
|
$instance->importSource = $url->source();
|
||||||
$instance->dateCreated = Chronos::instance($url->createdAt());
|
$instance->dateCreated = Chronos::instance($url->createdAt());
|
||||||
|
|
||||||
return $instance;
|
return $instance;
|
||||||
|
@ -12,6 +12,8 @@ use Shlinkio\Shlink\Core\Util\DoctrineBatchIterator;
|
|||||||
use Shlinkio\Shlink\Core\Util\TagManagerTrait;
|
use Shlinkio\Shlink\Core\Util\TagManagerTrait;
|
||||||
use Shlinkio\Shlink\Importer\ImportedLinksProcessorInterface;
|
use Shlinkio\Shlink\Importer\ImportedLinksProcessorInterface;
|
||||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
||||||
|
use Symfony\Component\Console\Style\StyleInterface;
|
||||||
|
use function sprintf;
|
||||||
|
|
||||||
class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
||||||
{
|
{
|
||||||
@ -29,7 +31,7 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
|||||||
/**
|
/**
|
||||||
* @param iterable|ImportedShlinkUrl[] $shlinkUrls
|
* @param iterable|ImportedShlinkUrl[] $shlinkUrls
|
||||||
*/
|
*/
|
||||||
public function process(iterable $shlinkUrls, string $source, array $params): void
|
public function process(StyleInterface $io, iterable $shlinkUrls, array $params): void
|
||||||
{
|
{
|
||||||
/** @var ShortUrlRepositoryInterface $shortUrlRepo */
|
/** @var ShortUrlRepositoryInterface $shortUrlRepo */
|
||||||
$shortUrlRepo = $this->em->getRepository(ShortUrl::class);
|
$shortUrlRepo = $this->em->getRepository(ShortUrl::class);
|
||||||
@ -39,16 +41,20 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
|||||||
/** @var ImportedShlinkUrl $url */
|
/** @var ImportedShlinkUrl $url */
|
||||||
foreach ($iterable as $url) {
|
foreach ($iterable as $url) {
|
||||||
// Skip already imported URLs
|
// Skip already imported URLs
|
||||||
if ($shortUrlRepo->importedUrlExists($url, $source, $importShortCodes)) {
|
if ($shortUrlRepo->importedUrlExists($url, $importShortCodes)) {
|
||||||
|
$io->text(sprintf('%s: <comment>Skipped</comment>', $url->longUrl()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$shortUrl = ShortUrl::fromImport($url, $source, $importShortCodes, $this->domainResolver);
|
$shortUrl = ShortUrl::fromImport($url, $importShortCodes, $this->domainResolver);
|
||||||
$shortUrl->setTags($this->tagNamesToEntities($this->em, $url->tags()));
|
$shortUrl->setTags($this->tagNamesToEntities($this->em, $url->tags()));
|
||||||
|
|
||||||
|
|
||||||
// TODO Handle errors while creating short URLs, to avoid making the whole process fail
|
// TODO Handle errors while creating short URLs, to avoid making the whole process fail
|
||||||
// * Duplicated short code
|
// * Duplicated short code
|
||||||
$this->em->persist($shortUrl);
|
$this->em->persist($shortUrl);
|
||||||
|
|
||||||
|
$io->text(sprintf('%s: <info>Imported</info>', $url->longUrl()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,9 +256,9 @@ DQL;
|
|||||||
return $qb->getQuery()->getOneOrNullResult();
|
return $qb->getQuery()->getOneOrNullResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importedUrlExists(ImportedShlinkUrl $url, string $source, bool $importShortCodes): bool
|
public function importedUrlExists(ImportedShlinkUrl $url, bool $importShortCodes): bool
|
||||||
{
|
{
|
||||||
$findConditions = ['importSource' => $source];
|
$findConditions = ['importSource' => $url->source()];
|
||||||
if ($importShortCodes) {
|
if ($importShortCodes) {
|
||||||
$findConditions['shortCode'] = $url->shortCode();
|
$findConditions['shortCode'] = $url->shortCode();
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,5 +32,5 @@ interface ShortUrlRepositoryInterface extends ObjectRepository
|
|||||||
|
|
||||||
public function findOneMatching(string $url, array $tags, ShortUrlMeta $meta): ?ShortUrl;
|
public function findOneMatching(string $url, array $tags, ShortUrlMeta $meta): ?ShortUrl;
|
||||||
|
|
||||||
public function importedUrlExists(ImportedShlinkUrl $url, string $source, bool $importShortCodes): bool;
|
public function importedUrlExists(ImportedShlinkUrl $url, bool $importShortCodes): bool;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user