]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Some cleanup
authorJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 1 Apr 2019 12:34:20 +0000 (14:34 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 1 Apr 2019 12:34:20 +0000 (14:34 +0200)
Also, do not run the hashed_url migration into a Doctrine migration

app/DoctrineMigrations/Version20190401105353.php
src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php

index c1c220537e21be19530301e84adbb52b7af79a2e..94ebb1ab592ea26f89bfa8437b53f48b3c428e68 100644 (file)
@@ -24,11 +24,6 @@ class Version20190401105353 extends WallabagMigration
             'notnull' => false,
         ]);
 
-        // sqlite doesn't have the MD5 function by default
-        if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) {
-            $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)');
-        }
-
         $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id');
     }
 
index 0ecf1a0ea65a2ec18be485c4b3e9f1f6d083058f..ad43b1d464ec081eb590365108d09051ab73665b 100644 (file)
@@ -52,7 +52,6 @@ class EntryRestController extends WallabagRestController
             foreach ($hashedUrls as $hashedUrl) {
                 $res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId());
 
-                // $results[$url] = $this->returnExistInformation($res, $returnId);
                 $results[$hashedUrl] = $this->returnExistInformation($res, $returnId);
             }
 
index 685e1672f17eb9712dc4966772c0e21b913bfb58..45bd8c5ffd08a505120db9c2e28ff4e3fe6316dd 100644 (file)
@@ -20,18 +20,14 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
             ->setName('wallabag:generate-hashed-urls')
             ->setDescription('Generates hashed urls for each entry')
             ->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved')
-            ->addArgument(
-                'username',
-                InputArgument::OPTIONAL,
-                'User to process entries'
-            );
+            ->addArgument('username', InputArgument::OPTIONAL, 'User to process entries');
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
     {
         $this->output = $output;
 
-        $username = $input->getArgument('username');
+        $username = (string) $input->getArgument('username');
 
         if ($username) {
             try {
index 0c175abbbef5c375886cfd7f8a60d71c3910bec1..f5089729643f94c67584445a4a0814c831949c0e 100644 (file)
@@ -350,15 +350,15 @@ class EntryRepository extends EntityRepository
      * Find an entry by its hashed url and its owner.
      * If it exists, return the entry otherwise return false.
      *
-     * @param $hashedUrl
-     * @param $userId
+     * @param string $hashedUrl Url hashed using sha1
+     * @param int    $userId
      *
      * @return Entry|bool
      */
     public function findByHashedUrlAndUserId($hashedUrl, $userId)
     {
         $res = $this->createQueryBuilder('e')
-            ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', urldecode($hashedUrl))
+            ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl)
             ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
             ->getQuery()
             ->getResult();
index 34de8ec8caa954e317f15fe2550ed6512cd507db..8cc12ed379487ab3546416026cbb601112e61fd1 100644 (file)
@@ -1076,6 +1076,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
     }
 
     public function testGetEntriesExistsWhichDoesNotExists()
+    {
+        $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
+
+        $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertFalse($content['exists']);
+    }
+
+    public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl()
     {
         $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2'));
 
@@ -1087,6 +1098,13 @@ class EntryRestControllerTest extends WallabagApiTestCase
     }
 
     public function testGetEntriesExistsWithNoUrl()
+    {
+        $this->client->request('GET', '/api/entries/exists?url=');
+
+        $this->assertSame(403, $this->client->getResponse()->getStatusCode());
+    }
+
+    public function testGetEntriesExistsWithNoHashedUrl()
     {
         $this->client->request('GET', '/api/entries/exists?hashed_url=');