aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-07-10 21:32:25 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2017-12-18 14:50:04 +0100
commitc1c0f09949c85218b720280d84eca70dad51b65a (patch)
tree892de551fe0ec2e866cecef82c6602c4fd4bc99a
parentef5c8a7d01d7b3f0041455503499ab67e2206e0d (diff)
downloadwallabag-c1c0f09949c85218b720280d84eca70dad51b65a.tar.gz
wallabag-c1c0f09949c85218b720280d84eca70dad51b65a.tar.zst
wallabag-c1c0f09949c85218b720280d84eca70dad51b65a.zip
Added given_url in entry table
-rw-r--r--app/DoctrineMigrations/Version20170710125843.php55
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php1
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php33
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php5
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php35
5 files changed, 128 insertions, 1 deletions
diff --git a/app/DoctrineMigrations/Version20170710125843.php b/app/DoctrineMigrations/Version20170710125843.php
new file mode 100644
index 00000000..1bac94d8
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170710125843.php
@@ -0,0 +1,55 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Added `given_url` field in entry table.
12 */
13class Version20170710125843 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
25 /**
26 * @param Schema $schema
27 */
28 public function up(Schema $schema)
29 {
30 $entryTable = $schema->getTable($this->getTable('entry'));
31
32 $this->skipIf($entryTable->hasColumn('given_url'), 'It seems that you already played this migration.');
33
34 $entryTable->addColumn('given_url', 'text', [
35 'notnull' => false,
36 ]);
37 }
38
39 /**
40 * @param Schema $schema
41 */
42 public function down(Schema $schema)
43 {
44 $entryTable = $schema->getTable($this->getTable('entry'));
45
46 $this->skipIf(!$entryTable->hasColumn('given_url'), 'It seems that you already played this migration.');
47
48 $entryTable->dropColumn('given_url');
49 }
50
51 private function getTable($tableName)
52 {
53 return $this->container->getParameter('database_table_prefix') . $tableName;
54 }
55}
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index b7fdea27..3ac0f8a6 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -78,6 +78,7 @@ class EntryController extends Controller
78 return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()])); 78 return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()]));
79 } 79 }
80 80
81 $entry->setGivenUrl($entry->getUrl());
81 $this->updateEntry($entry); 82 $this->updateEntry($entry);
82 83
83 $em = $this->getDoctrine()->getManager(); 84 $em = $this->getDoctrine()->getManager();
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 2b1f2e05..58ec51db 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -68,6 +68,15 @@ class Entry
68 /** 68 /**
69 * @var string 69 * @var string
70 * 70 *
71 * @ORM\Column(name="given_url", type="text", nullable=true)
72 *
73 * @Groups({"entries_for_user", "export_all"})
74 */
75 private $givenUrl;
76
77 /**
78 * @var string
79 *
71 * @Assert\NotBlank() 80 * @Assert\NotBlank()
72 * @ORM\Column(name="url", type="text", nullable=true) 81 * @ORM\Column(name="url", type="text", nullable=true)
73 * 82 *
@@ -298,6 +307,30 @@ class Entry
298 } 307 }
299 308
300 /** 309 /**
310 * Set given url.
311 *
312 * @param string $givenUrl
313 *
314 * @return Entry
315 */
316 public function setGivenUrl($givenUrl)
317 {
318 $this->givenUrl = $givenUrl;
319
320 return $this;
321 }
322
323 /**
324 * Get given Url.
325 *
326 * @return string
327 */
328 public function getGivenUrl()
329 {
330 return $this->givenUrl;
331 }
332
333 /**
301 * Set url. 334 * Set url.
302 * 335 *
303 * @param string $url 336 * @param string $url
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index b5e35eff..9e471d3c 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -314,8 +314,11 @@ class EntryRepository extends EntityRepository
314 */ 314 */
315 public function findByUrlAndUserId($url, $userId) 315 public function findByUrlAndUserId($url, $userId)
316 { 316 {
317 $url = urldecode($url);
318
317 $res = $this->createQueryBuilder('e') 319 $res = $this->createQueryBuilder('e')
318 ->where('e.url = :url')->setParameter('url', urldecode($url)) 320 ->where('e.url = :url')->setParameter('url', $url)
321 ->orWhere('e.givenUrl = :url')->setParameter('url', $url)
319 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 322 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
320 ->getQuery() 323 ->getQuery()
321 ->getResult(); 324 ->getResult();
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 0e7e1576..cd63c1ba 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -265,6 +265,41 @@ class EntryControllerTest extends WallabagCoreTestCase
265 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 265 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
266 } 266 }
267 267
268 public function testPostNewOkUrlExistWithRedirection()
269 {
270 $this->logInAs('admin');
271 $client = $this->getClient();
272
273 $url = 'https://fashionunited.com/news/business/jigsaw-posts-8-percent-increase-in-annual-sales/2017070316404';
274
275 $crawler = $client->request('GET', '/new');
276
277 $this->assertSame(200, $client->getResponse()->getStatusCode());
278
279 $form = $crawler->filter('form[name=entry]')->form();
280
281 $data = [
282 'entry[url]' => $url,
283 ];
284
285 $client->submit($form, $data);
286
287 $crawler = $client->request('GET', '/new');
288
289 $this->assertSame(200, $client->getResponse()->getStatusCode());
290
291 $form = $crawler->filter('form[name=entry]')->form();
292
293 $data = [
294 'entry[url]' => $url,
295 ];
296
297 $client->submit($form, $data);
298
299 $this->assertSame(302, $client->getResponse()->getStatusCode());
300 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
301 }
302
268 /** 303 /**
269 * This test will require an internet connection. 304 * This test will require an internet connection.
270 */ 305 */