aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/DoctrineMigrations/Version20190401105353.php5
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php1
-rw-r--r--src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php8
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php6
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php18
5 files changed, 23 insertions, 15 deletions
diff --git a/app/DoctrineMigrations/Version20190401105353.php b/app/DoctrineMigrations/Version20190401105353.php
index c1c22053..94ebb1ab 100644
--- a/app/DoctrineMigrations/Version20190401105353.php
+++ b/app/DoctrineMigrations/Version20190401105353.php
@@ -24,11 +24,6 @@ class Version20190401105353 extends WallabagMigration
24 'notnull' => false, 24 'notnull' => false,
25 ]); 25 ]);
26 26
27 // sqlite doesn't have the MD5 function by default
28 if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) {
29 $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)');
30 }
31
32 $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id'); 27 $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id');
33 } 28 }
34 29
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 0ecf1a0e..ad43b1d4 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -52,7 +52,6 @@ class EntryRestController extends WallabagRestController
52 foreach ($hashedUrls as $hashedUrl) { 52 foreach ($hashedUrls as $hashedUrl) {
53 $res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId()); 53 $res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId());
54 54
55 // $results[$url] = $this->returnExistInformation($res, $returnId);
56 $results[$hashedUrl] = $this->returnExistInformation($res, $returnId); 55 $results[$hashedUrl] = $this->returnExistInformation($res, $returnId);
57 } 56 }
58 57
diff --git a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
index 685e1672..45bd8c5f 100644
--- a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
+++ b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
@@ -20,18 +20,14 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
20 ->setName('wallabag:generate-hashed-urls') 20 ->setName('wallabag:generate-hashed-urls')
21 ->setDescription('Generates hashed urls for each entry') 21 ->setDescription('Generates hashed urls for each entry')
22 ->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved') 22 ->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved')
23 ->addArgument( 23 ->addArgument('username', InputArgument::OPTIONAL, 'User to process entries');
24 'username',
25 InputArgument::OPTIONAL,
26 'User to process entries'
27 );
28 } 24 }
29 25
30 protected function execute(InputInterface $input, OutputInterface $output) 26 protected function execute(InputInterface $input, OutputInterface $output)
31 { 27 {
32 $this->output = $output; 28 $this->output = $output;
33 29
34 $username = $input->getArgument('username'); 30 $username = (string) $input->getArgument('username');
35 31
36 if ($username) { 32 if ($username) {
37 try { 33 try {
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 0c175abb..f5089729 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -350,15 +350,15 @@ class EntryRepository extends EntityRepository
350 * Find an entry by its hashed url and its owner. 350 * Find an entry by its hashed url and its owner.
351 * If it exists, return the entry otherwise return false. 351 * If it exists, return the entry otherwise return false.
352 * 352 *
353 * @param $hashedUrl 353 * @param string $hashedUrl Url hashed using sha1
354 * @param $userId 354 * @param int $userId
355 * 355 *
356 * @return Entry|bool 356 * @return Entry|bool
357 */ 357 */
358 public function findByHashedUrlAndUserId($hashedUrl, $userId) 358 public function findByHashedUrlAndUserId($hashedUrl, $userId)
359 { 359 {
360 $res = $this->createQueryBuilder('e') 360 $res = $this->createQueryBuilder('e')
361 ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', urldecode($hashedUrl)) 361 ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl)
362 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 362 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
363 ->getQuery() 363 ->getQuery()
364 ->getResult(); 364 ->getResult();
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 34de8ec8..8cc12ed3 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -1077,6 +1077,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
1077 1077
1078 public function testGetEntriesExistsWhichDoesNotExists() 1078 public function testGetEntriesExistsWhichDoesNotExists()
1079 { 1079 {
1080 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
1081
1082 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1083
1084 $content = json_decode($this->client->getResponse()->getContent(), true);
1085
1086 $this->assertFalse($content['exists']);
1087 }
1088
1089 public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl()
1090 {
1080 $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2')); 1091 $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2'));
1081 1092
1082 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 1093 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
@@ -1088,6 +1099,13 @@ class EntryRestControllerTest extends WallabagApiTestCase
1088 1099
1089 public function testGetEntriesExistsWithNoUrl() 1100 public function testGetEntriesExistsWithNoUrl()
1090 { 1101 {
1102 $this->client->request('GET', '/api/entries/exists?url=');
1103
1104 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
1105 }
1106
1107 public function testGetEntriesExistsWithNoHashedUrl()
1108 {
1091 $this->client->request('GET', '/api/entries/exists?hashed_url='); 1109 $this->client->request('GET', '/api/entries/exists?hashed_url=');
1092 1110
1093 $this->assertSame(403, $this->client->getResponse()->getStatusCode()); 1111 $this->assertSame(403, $this->client->getResponse()->getStatusCode());