From e0ef1a1c8b6badd2f52acbdcf928469ef1a15b3e Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 4 Sep 2017 23:39:08 +0200 Subject: [PATCH] Add originUrl property to Entry, handle that in EntryRestController, handle migration Signed-off-by: Kevin Decherf --- .../Version20171105202000.php | 55 +++++++++++++++++++ .../Controller/EntryRestController.php | 11 ++++ src/Wallabag/CoreBundle/Entity/Entry.php | 33 +++++++++++ 3 files changed, 99 insertions(+) create mode 100644 app/DoctrineMigrations/Version20171105202000.php diff --git a/app/DoctrineMigrations/Version20171105202000.php b/app/DoctrineMigrations/Version20171105202000.php new file mode 100644 index 000000000..b1cff9cea --- /dev/null +++ b/app/DoctrineMigrations/Version20171105202000.php @@ -0,0 +1,55 @@ +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; + } +} diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 6f161a081..5a9afc698 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -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', ''), ]; } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index cfb8db752..445cc45e5 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -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; + } }