Basic short-úrl import implementation

This commit is contained in:
Alejandro Celaya
2020-10-24 13:55:54 +02:00
parent 554d9b092f
commit ec3e7212b2
6 changed files with 100 additions and 18 deletions

View File

@@ -11,6 +11,7 @@ use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering;
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
use function array_column;
use function array_key_exists;
@@ -254,4 +255,16 @@ DQL;
return $qb->getQuery()->getOneOrNullResult();
}
public function importedUrlExists(ImportedShlinkUrl $url, string $source, bool $importShortCodes): bool
{
$findConditions = ['importSource' => $source];
if ($importShortCodes) {
$findConditions['shortCode'] = $url->shortCode();
} else {
$findConditions['longUrl'] = $url->longUrl();
}
return $this->count($findConditions) > 0;
}
}

View File

@@ -9,6 +9,7 @@ use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering;
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
interface ShortUrlRepositoryInterface extends ObjectRepository
{
@@ -30,4 +31,6 @@ interface ShortUrlRepositoryInterface extends ObjectRepository
public function shortCodeIsInUse(string $slug, ?string $domain): bool;
public function findOneMatching(string $url, array $tags, ShortUrlMeta $meta): ?ShortUrl;
public function importedUrlExists(ImportedShlinkUrl $url, string $source, bool $importShortCodes): bool;
}