From dda6a6addc0fd54031514e81d2b55d5066b7157c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 11 May 2017 14:18:21 +0200 Subject: [PATCH 1/2] Added headers field in Entry --- .../Version20170511115400.php | 55 +++++++++++++++++++ src/Wallabag/CoreBundle/Entity/Entry.php | 31 ++++++++++- .../CoreBundle/Helper/ContentProxy.php | 4 ++ .../Controller/EntryControllerTest.php | 1 + 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 app/DoctrineMigrations/Version20170511115400.php diff --git a/app/DoctrineMigrations/Version20170511115400.php b/app/DoctrineMigrations/Version20170511115400.php new file mode 100644 index 000000000..64ee9e0a2 --- /dev/null +++ b/app/DoctrineMigrations/Version20170511115400.php @@ -0,0 +1,55 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix').$tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + + $this->skipIf($entryTable->hasColumn('headers'), 'It seems that you already played this migration.'); + + $entryTable->addColumn('headers', 'text', [ + 'notnull' => false, + ]); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + + $this->skipIf(!$entryTable->hasColumn('headers'), 'It seems that you already played this migration.'); + + $entryTable->dropColumn('headers'); + } +} diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index b71c467cf..f0983b1c0 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -201,6 +201,15 @@ class Entry */ private $httpStatus; + /** + * @var array + * + * @ORM\Column(name="headers", type="json_array", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $headers; + /** * @Exclude * @@ -716,7 +725,7 @@ class Entry } /** - * @return string + * @return array */ public function getPublishedBy() { @@ -734,4 +743,24 @@ class Entry return $this; } + + /** + * @return array + */ + public function getHeaders() + { + return $this->headers; + } + + /** + * @param string $headers + * + * @return Entry + */ + public function setHeaders($headers) + { + $this->headers = $headers; + + return $this; + } } diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index d45aef889..9a08db3d8 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -87,6 +87,10 @@ class ContentProxy $entry->setPublishedBy($content['authors']); } + if (!empty($content['all_headers'])) { + $entry->setHeaders($content['all_headers']); + } + $entry->setLanguage(isset($content['language']) ? $content['language'] : ''); $entry->setMimetype(isset($content['content_type']) ? $content['content_type'] : ''); $entry->setReadingTime(Utils::getReadingTime($html)); diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 35438c839..82ac3ac3f 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -142,6 +142,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('Google', $content->getTitle()); $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); $this->assertEquals('Morgane Tual', $author[0]); + $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); } public function testPostWithMultipleAuthors() From 1517d5772db05ce86b9958dc6545471d8702bf60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 11 May 2017 14:53:56 +0200 Subject: [PATCH 2/2] Replaced json_array with array And fixed failing test due to @j0k3r :trollface: --- src/Wallabag/CoreBundle/Entity/Entry.php | 8 ++++---- .../CoreBundle/Controller/EntryControllerTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index f0983b1c0..08a67c34b 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -133,7 +133,7 @@ class Entry /** * @var array * - * @ORM\Column(name="published_by", type="json_array", nullable=true) + * @ORM\Column(name="published_by", type="array", nullable=true) * * @Groups({"entries_for_user", "export_all"}) */ @@ -204,7 +204,7 @@ class Entry /** * @var array * - * @ORM\Column(name="headers", type="json_array", nullable=true) + * @ORM\Column(name="headers", type="array", nullable=true) * * @Groups({"entries_for_user", "export_all"}) */ @@ -733,7 +733,7 @@ class Entry } /** - * @param string $publishedBy + * @param array $publishedBy * * @return Entry */ @@ -753,7 +753,7 @@ class Entry } /** - * @param string $headers + * @param array $headers * * @return Entry */ diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 82ac3ac3f..698e5e130 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -915,7 +915,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); $this->assertEquals($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); - $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); + $this->assertContains('/c4789a7f.jpeg', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); }