diff options
author | Olivier Mehani <shtrom@ssji.net> | 2019-05-10 22:07:55 +1000 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-05-24 15:17:46 +0200 |
commit | 4a5516376bf4c8b0cdc1e81d24ce1cca68425785 (patch) | |
tree | ccf3ced45a2841c5fdfe9010b40528bb365c32b2 /src/Wallabag/CoreBundle/Repository | |
parent | d5744bf0dfdbee4dbbe380d8a076d07b89fc76e6 (diff) | |
download | wallabag-4a5516376bf4c8b0cdc1e81d24ce1cca68425785.tar.gz wallabag-4a5516376bf4c8b0cdc1e81d24ce1cca68425785.tar.zst wallabag-4a5516376bf4c8b0cdc1e81d24ce1cca68425785.zip |
Add Wallabag\CoreBundle\Helper\UrlHasher
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 960b682d..37fc1000 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -9,6 +9,7 @@ use Pagerfanta\Adapter\DoctrineORMAdapter; | |||
9 | use Pagerfanta\Pagerfanta; | 9 | use Pagerfanta\Pagerfanta; |
10 | use Wallabag\CoreBundle\Entity\Entry; | 10 | use Wallabag\CoreBundle\Entity\Entry; |
11 | use Wallabag\CoreBundle\Entity\Tag; | 11 | use Wallabag\CoreBundle\Entity\Tag; |
12 | use Wallabag\CoreBundle\Helper\UrlHasher; | ||
12 | 13 | ||
13 | class EntryRepository extends EntityRepository | 14 | class EntryRepository extends EntityRepository |
14 | { | 15 | { |
@@ -349,7 +350,7 @@ class EntryRepository extends EntityRepository | |||
349 | public function findByUrlAndUserId($url, $userId) | 350 | public function findByUrlAndUserId($url, $userId) |
350 | { | 351 | { |
351 | return $this->findByHashedUrlAndUserId( | 352 | return $this->findByHashedUrlAndUserId( |
352 | hash('sha1', $url), // XXX: the hash logic would better be in a separate util to avoid duplication with GenerateUrlHashesCommand::generateHashedUrls | 353 | UrlHasher::hashUrl($url), |
353 | $userId); | 354 | $userId); |
354 | } | 355 | } |
355 | 356 | ||
@@ -507,6 +508,32 @@ class EntryRepository extends EntityRepository | |||
507 | } | 508 | } |
508 | 509 | ||
509 | /** | 510 | /** |
511 | * Inject a UrlHasher. | ||
512 | * | ||
513 | * @param UrlHasher $hasher | ||
514 | */ | ||
515 | public function setUrlHasher(UrlHasher $hasher) | ||
516 | { | ||
517 | $this->urlHasher = $hasher; | ||
518 | } | ||
519 | |||
520 | /** | ||
521 | * Get the UrlHasher, or create a default one if not injected. | ||
522 | * | ||
523 | * XXX: the default uses the default hash algorithm | ||
524 | * | ||
525 | * @return UrlHasher | ||
526 | */ | ||
527 | protected function getUrlHasher() | ||
528 | { | ||
529 | if (!isset($this->urlHasher)) { | ||
530 | $this->setUrlHasher(new UrlHasher()); | ||
531 | } | ||
532 | |||
533 | return $this->urlHasher; | ||
534 | } | ||
535 | |||
536 | /** | ||
510 | * Return a query builder to be used by other getBuilderFor* method. | 537 | * Return a query builder to be used by other getBuilderFor* method. |
511 | * | 538 | * |
512 | * @param int $userId | 539 | * @param int $userId |