aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/DoctrineMigrations/Version20170710125843.php38
-rw-r--r--app/DoctrineMigrations/Version20171218135243.php48
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php36
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php1
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php1
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php36
6 files changed, 158 insertions, 2 deletions
diff --git a/app/DoctrineMigrations/Version20170710125843.php b/app/DoctrineMigrations/Version20170710125843.php
new file mode 100644
index 00000000..2cf8647a
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170710125843.php
@@ -0,0 +1,38 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Schema\Schema;
6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7
8/**
9 * Added `given_url` field in entry table.
10 */
11class Version20170710125843 extends WallabagMigration
12{
13 /**
14 * @param Schema $schema
15 */
16 public function up(Schema $schema)
17 {
18 $entryTable = $schema->getTable($this->getTable('entry'));
19
20 $this->skipIf($entryTable->hasColumn('given_url'), 'It seems that you already played this migration.');
21
22 $entryTable->addColumn('given_url', 'text', [
23 'notnull' => false,
24 ]);
25 }
26
27 /**
28 * @param Schema $schema
29 */
30 public function down(Schema $schema)
31 {
32 $entryTable = $schema->getTable($this->getTable('entry'));
33
34 $this->skipIf(!$entryTable->hasColumn('given_url'), 'It seems that you already played this migration.');
35
36 $entryTable->dropColumn('given_url');
37 }
38}
diff --git a/app/DoctrineMigrations/Version20171218135243.php b/app/DoctrineMigrations/Version20171218135243.php
new file mode 100644
index 00000000..3060c920
--- /dev/null
+++ b/app/DoctrineMigrations/Version20171218135243.php
@@ -0,0 +1,48 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Schema\Schema;
6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7
8/**
9 * Added indexes on wallabag_entry.url and wallabag_entry.given_url and wallabag_entry.user_id.
10 */
11class Version20171218135243 extends WallabagMigration
12{
13 private $indexGivenUrl = 'IDX_entry_given_url';
14
15 /**
16 * @param Schema $schema
17 */
18 public function up(Schema $schema)
19 {
20 $entryTable = $schema->getTable($this->getTable('entry'));
21 $this->skipIf($entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.');
22
23 switch ($this->connection->getDatabasePlatform()->getName()) {
24 case 'sqlite':
25 $sql = 'CREATE UNIQUE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);';
26 break;
27 case 'mysql':
28 $sql = 'CREATE UNIQUE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url (255), given_url (255), user_id);';
29 break;
30 case 'postgresql':
31 $sql = 'CREATE UNIQUE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);';
32 break;
33 }
34
35 $this->addSql($sql);
36 }
37
38 /**
39 * @param Schema $schema
40 */
41 public function down(Schema $schema)
42 {
43 $entryTable = $schema->getTable($this->getTable('entry'));
44 $this->skipIf(false === $entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.');
45
46 $entryTable->dropIndex($this->indexGivenUrl);
47 }
48}
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 1b4367fd..62274136 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -28,7 +28,8 @@ use Wallabag\UserBundle\Entity\User;
28 * @ORM\Index(name="created_at", columns={"created_at"}), 28 * @ORM\Index(name="created_at", columns={"created_at"}),
29 * @ORM\Index(name="uid", columns={"uid"}), 29 * @ORM\Index(name="uid", columns={"uid"}),
30 * @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}) 30 * @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}})
31 * } 31 * },
32 * uniqueConstraints={@ORM\UniqueConstraint(name="IDX_entry_given_url",columns={"url", "given_url", "user_id"})}
32 * ) 33 * )
33 * @ORM\HasLifecycleCallbacks() 34 * @ORM\HasLifecycleCallbacks()
34 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") 35 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
@@ -70,6 +71,15 @@ class Entry
70 /** 71 /**
71 * @var string 72 * @var string
72 * 73 *
74 * @ORM\Column(name="given_url", type="text", nullable=true)
75 *
76 * @Groups({"entries_for_user", "export_all"})
77 */
78 private $givenUrl;
79
80 /**
81 * @var string
82 *
73 * @Assert\NotBlank() 83 * @Assert\NotBlank()
74 * @ORM\Column(name="url", type="text", nullable=true) 84 * @ORM\Column(name="url", type="text", nullable=true)
75 * 85 *
@@ -316,6 +326,30 @@ class Entry
316 } 326 }
317 327
318 /** 328 /**
329 * Set given url.
330 *
331 * @param string $givenUrl
332 *
333 * @return Entry
334 */
335 public function setGivenUrl($givenUrl)
336 {
337 $this->givenUrl = $givenUrl;
338
339 return $this;
340 }
341
342 /**
343 * Get given Url.
344 *
345 * @return string
346 */
347 public function getGivenUrl()
348 {
349 return $this->givenUrl;
350 }
351
352 /**
319 * Set url. 353 * Set url.
320 * 354 *
321 * @param string $url 355 * @param string $url
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index c6fa0d98..0d6a412d 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -76,6 +76,7 @@ class ContentProxy
76 // Not sure what are the other possible cases where this property is empty 76 // Not sure what are the other possible cases where this property is empty
77 if (empty($entry->getUrl()) && !empty($url)) { 77 if (empty($entry->getUrl()) && !empty($url)) {
78 $entry->setUrl($url); 78 $entry->setUrl($url);
79 $entry->setGivenUrl($url);
79 } 80 }
80 81
81 $this->stockEntry($entry, $content); 82 $this->stockEntry($entry, $content);
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 880e7c65..299b0b27 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -368,6 +368,7 @@ class EntryRepository extends EntityRepository
368 { 368 {
369 $res = $this->createQueryBuilder('e') 369 $res = $this->createQueryBuilder('e')
370 ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl) 370 ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl)
371 // ->orWhere('e.givenUrl = :url')->setParameter('url', $url)
371 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 372 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
372 ->getQuery() 373 ->getQuery()
373 ->getResult(); 374 ->getResult();
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 9dee9891..a6fd3fff 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -166,7 +166,6 @@ class EntryControllerTest extends WallabagCoreTestCase
166 $this->assertSame($this->url, $content->getUrl()); 166 $this->assertSame($this->url, $content->getUrl());
167 $this->assertContains('Google', $content->getTitle()); 167 $this->assertContains('Google', $content->getTitle());
168 $this->assertSame('fr', $content->getLanguage()); 168 $this->assertSame('fr', $content->getLanguage());
169 $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
170 $this->assertArrayHasKey('x-frame-options', $content->getHeaders()); 169 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
171 $client->getContainer()->get('craue_config')->set('store_article_headers', 0); 170 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
172 } 171 }
@@ -266,6 +265,41 @@ class EntryControllerTest extends WallabagCoreTestCase
266 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 265 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
267 } 266 }
268 267
268 public function testPostNewOkUrlExistWithRedirection()
269 {
270 $this->logInAs('admin');
271 $client = $this->getClient();
272
273 $url = 'https://wllbg.org/test-redirect/c51c';
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
269 /** 303 /**
270 * This test will require an internet connection. 304 * This test will require an internet connection.
271 */ 305 */