]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added headers field in Entry
authorNicolas Lœuillet <nicolas@loeuillet.org>
Thu, 11 May 2017 12:18:21 +0000 (14:18 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Thu, 11 May 2017 12:18:21 +0000 (14:18 +0200)
app/DoctrineMigrations/Version20170511115400.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Helper/ContentProxy.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php

diff --git a/app/DoctrineMigrations/Version20170511115400.php b/app/DoctrineMigrations/Version20170511115400.php
new file mode 100644 (file)
index 0000000..64ee9e0
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Added `headers` field in entry table.
+ */
+class Version20170511115400 extends AbstractMigration implements ContainerAwareInterface
+{
+    /**
+     * @var ContainerInterface
+     */
+    private $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->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');
+    }
+}
index b71c467cf6ba3942812e670510cccbe00fd14b6f..f0983b1c0ff95f58434098f6f0a5b6d8c22ce1d9 100644 (file)
@@ -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;
+    }
 }
index d45aef8894d6d0fe154efc7fb6344e2840059a30..9a08db3d8e81738fdef20fdcd1871d5f4a81d9de 100644 (file)
@@ -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));
index 35438c839c6dd7847a42c24af0c510f75ef0cfef..82ac3ac3f183c8a6387621cd80309655ac48314b 100644 (file)
@@ -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()