aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-04-01 11:50:33 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-04-01 13:24:40 +0200
commit9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c (patch)
treeb8b37a0f8b3edd0c4db1678815d906a7b6126f31 /src/Wallabag/CoreBundle
parentbfe02a0b481055bb4e799200c8daa9a0ad987c71 (diff)
downloadwallabag-9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c.tar.gz
wallabag-9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c.tar.zst
wallabag-9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c.zip
Keep url in exists endpoint
- Add migration - Use md5 instead of sha512 (we don't need security here, just a hash) - Update tests
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php19
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php2
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php4
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php24
4 files changed, 40 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
index fe2644f2..fb598390 100644
--- a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
+++ b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
@@ -45,13 +45,13 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
45 } else { 45 } else {
46 $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll(); 46 $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll();
47 47
48 $output->writeln(sprintf('Generating hashed urls for the %d user account entries', count($users))); 48 $output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users)));
49 49
50 foreach ($users as $user) { 50 foreach ($users as $user) {
51 $output->writeln(sprintf('Processing user %s', $user->getUsername())); 51 $output->writeln(sprintf('Processing user: %s', $user->getUsername()));
52 $this->generateHashedUrls($user); 52 $this->generateHashedUrls($user);
53 } 53 }
54 $output->writeln(sprintf('Finished generated hashed urls')); 54 $output->writeln('Finished generated hashed urls');
55 } 55 }
56 56
57 return 0; 57 return 0;
@@ -67,13 +67,20 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
67 67
68 $entries = $repo->findByUser($user->getId()); 68 $entries = $repo->findByUser($user->getId());
69 69
70 $i = 1;
70 foreach ($entries as $entry) { 71 foreach ($entries as $entry) {
71 $entry->setHashedUrl(hash('sha512', $entry->getUrl())); 72 $entry->setHashedUrl(hash('md5', $entry->getUrl()));
72 $em->persist($entry); 73 $em->persist($entry);
73 $em->flush(); 74
75 if (0 === ($i % 20)) {
76 $em->flush();
77 }
78 ++$i;
74 } 79 }
75 80
76 $this->output->writeln(sprintf('Generated hashed urls for user %s', $user->getUserName())); 81 $em->flush();
82
83 $this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName()));
77 } 84 }
78 85
79 /** 86 /**
diff --git a/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php
index 9c10500d..1b18cad6 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php
@@ -30,7 +30,6 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface
30 'entry2' => [ 30 'entry2' => [
31 'user' => 'admin-user', 31 'user' => 'admin-user',
32 'url' => 'http://0.0.0.0/entry2', 32 'url' => 'http://0.0.0.0/entry2',
33 'hashed_url' => hash('md5', 'http://0.0.0.0/entry2'),
34 'reading_time' => 1, 33 'reading_time' => 1,
35 'domain' => 'domain.io', 34 'domain' => 'domain.io',
36 'mime' => 'text/html', 35 'mime' => 'text/html',
@@ -90,6 +89,7 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface
90 foreach ($entries as $reference => $item) { 89 foreach ($entries as $reference => $item) {
91 $entry = new Entry($this->getReference($item['user'])); 90 $entry = new Entry($this->getReference($item['user']));
92 $entry->setUrl($item['url']); 91 $entry->setUrl($item['url']);
92 $entry->setHashedUrl(hash('md5', $item['url']));
93 $entry->setReadingTime($item['reading_time']); 93 $entry->setReadingTime($item['reading_time']);
94 $entry->setDomainName($item['domain']); 94 $entry->setDomainName($item['domain']);
95 $entry->setMimetype($item['mime']); 95 $entry->setMimetype($item['mime']);
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 17a1ed58..a04f101f 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -26,7 +26,7 @@ use Wallabag\UserBundle\Entity\User;
26 * indexes={ 26 * indexes={
27 * @ORM\Index(name="created_at", columns={"created_at"}), 27 * @ORM\Index(name="created_at", columns={"created_at"}),
28 * @ORM\Index(name="uid", columns={"uid"}), 28 * @ORM\Index(name="uid", columns={"uid"}),
29 * @ORM\Index(name="hashedurl", columns={"hashedurl"}) 29 * @ORM\Index(name="hashed_url", columns={"hashed_url"})
30 * } 30 * }
31 * ) 31 * )
32 * @ORM\HasLifecycleCallbacks() 32 * @ORM\HasLifecycleCallbacks()
@@ -79,7 +79,7 @@ class Entry
79 /** 79 /**
80 * @var string 80 * @var string
81 * 81 *
82 * @ORM\Column(name="hashedurl", type="text", nullable=true) 82 * @ORM\Column(name="hashed_url", type="string", length=32, nullable=true)
83 */ 83 */
84 private $hashedUrl; 84 private $hashedUrl;
85 85
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 45366623..0c175abb 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -347,6 +347,30 @@ class EntryRepository extends EntityRepository
347 } 347 }
348 348
349 /** 349 /**
350 * Find an entry by its hashed url and its owner.
351 * If it exists, return the entry otherwise return false.
352 *
353 * @param $hashedUrl
354 * @param $userId
355 *
356 * @return Entry|bool
357 */
358 public function findByHashedUrlAndUserId($hashedUrl, $userId)
359 {
360 $res = $this->createQueryBuilder('e')
361 ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', urldecode($hashedUrl))
362 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
363 ->getQuery()
364 ->getResult();
365
366 if (\count($res)) {
367 return current($res);
368 }
369
370 return false;
371 }
372
373 /**
350 * Count all entries for a user. 374 * Count all entries for a user.
351 * 375 *
352 * @param int $userId 376 * @param int $userId