Add originUrl property to Entry, handle that in EntryRestController, handle migration

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2017-09-04 23:39:08 +02:00
parent e585dde46c
commit e0ef1a1c8b
3 changed files with 99 additions and 0 deletions

View file

@ -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;
}
}

View 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', ''),
];
}

View 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;
}
}