]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add originUrl property to Entry, handle that in EntryRestController, handle migration
authorKevin Decherf <kevin@kdecherf.com>
Mon, 4 Sep 2017 21:39:08 +0000 (23:39 +0200)
committerKevin Decherf <kevin@kdecherf.com>
Sun, 19 Nov 2017 14:02:11 +0000 (15:02 +0100)
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
app/DoctrineMigrations/Version20171105202000.php [new file with mode: 0644]
src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/CoreBundle/Entity/Entry.php

diff --git a/app/DoctrineMigrations/Version20171105202000.php b/app/DoctrineMigrations/Version20171105202000.php
new file mode 100644 (file)
index 0000000..b1cff9c
--- /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;
+
+/**
+ * Add origin_url column
+ */
+class Version20171105202000 extends AbstractMigration implements ContainerAwareInterface
+{
+    /**
+     * @var ContainerInterface
+     */
+    private $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->container = $container;
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $entryTable = $schema->getTable($this->getTable('entry'));
+
+        $this->skipIf($entryTable->hasColumn('origin_url'), 'It seems that you already played this migration.');
+
+        $entryTable->addColumn('origin_url', 'text', [
+            'notnull' => false,
+        ]);
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        $entryTable = $schema->getTable($this->getTable('entry'));
+
+        $this->skipIf(!$entryTable->hasColumn('origin_url'), 'It seems that you already played this migration.');
+
+        $entryTable->dropColumn('origin_url');
+    }
+
+    private function getTable($tableName)
+    {
+        return $this->container->getParameter('database_table_prefix') . $tableName;
+    }
+}
index 6f161a081eb436431a26d7854988e1c6d3b7cb6c..5a9afc69847bb931afca3efc01f34ef099bea7ac 100644 (file)
@@ -309,6 +309,7 @@ class EntryRestController extends WallabagRestController
      *          {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
      *          {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
      *          {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
+     *          {"name"="origin_url", "dataType"="string", "required"=false, "format"="http://www.test.com/article.html", "description"="Origin url for the entry."},
      *       }
      * )
      *
@@ -368,6 +369,10 @@ class EntryRestController extends WallabagRestController
             $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']);
         }
 
+        if (!empty($data['origin_url'])) {
+            $entry->setOriginUrl($data['origin_url']);
+        }
+
         if (null !== $data['isPublic']) {
             if (true === (bool) $data['isPublic'] && null === $entry->getUid()) {
                 $entry->generateUid();
@@ -404,6 +409,7 @@ class EntryRestController extends WallabagRestController
      *          {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
      *          {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
      *          {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
+     *          {"name"="origin_url", "dataType"="string", "required"=false, "format"="http://www.test.com/article.html", "description"="Origin url for the entry."},
      *      }
      * )
      *
@@ -480,6 +486,10 @@ class EntryRestController extends WallabagRestController
             }
         }
 
+        if (!empty($data['origin_url'])) {
+            $entry->setOriginUrl($data['origin_url']);
+        }
+
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
         $em->flush();
@@ -778,6 +788,7 @@ class EntryRestController extends WallabagRestController
             'picture' => $request->request->get('preview_picture'),
             'publishedAt' => $request->request->get('published_at'),
             'authors' => $request->request->get('authors', ''),
+            'origin_url' => $request->request->get('origin_url', ''),
         ];
     }
 
index cfb8db75275c2e42d1b994e5f037a58220bd31d5..445cc45e57b9ebfdf2faee457507c6b3cee84b77 100644 (file)
@@ -245,6 +245,15 @@ class Entry
      */
     private $tags;
 
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="origin_url", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    private $originUrl;
+
     /*
      * @param User     $user
      */
@@ -831,4 +840,28 @@ class Entry
 
         return $this;
     }
+    
+    /**
+     * Set origin url.
+     *
+     * @param string $originUrl
+     *
+     * @return Entry
+     */
+    public function setOriginUrl($originUrl)
+    {
+        $this->originUrl = $originUrl;
+
+        return $this;
+    }
+    
+    /**
+     * Get origin url.
+     *
+     * @return string
+     */
+    public function getOriginUrl()
+    {
+        return $this->originUrl;
+    }
 }