From b0458874c85060c992aa1cb78dec91ee85082b74 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 16:06:42 +0200 Subject: Fix relations export for Entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tags & Annotations weren’t really well exported. This is now fixed (+ tests) --- src/Wallabag/AnnotationBundle/Entity/Annotation.php | 7 +++++++ .../CoreBundle/DataFixtures/ORM/LoadEntryData.php | 4 ++++ src/Wallabag/CoreBundle/Entity/Entry.php | 17 +++++++++++++++-- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 12 ++++-------- 4 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php index 90ee7c2d..c48d8731 100644 --- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php +++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php @@ -7,6 +7,7 @@ use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Exclude; use JMS\Serializer\Annotation\VirtualProperty; use JMS\Serializer\Annotation\SerializedName; +use JMS\Serializer\Annotation\Groups; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; @@ -33,6 +34,8 @@ class Annotation * @var string * * @ORM\Column(name="text", type="text") + * + * @Groups({"entries_for_user", "export_all"}) */ private $text; @@ -54,6 +57,8 @@ class Annotation * @var string * * @ORM\Column(name="quote", type="string") + * + * @Groups({"entries_for_user", "export_all"}) */ private $quote; @@ -61,6 +66,8 @@ class Annotation * @var array * * @ORM\Column(name="ranges", type="array") + * + * @Groups({"entries_for_user", "export_all"}) */ private $ranges; diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php index 6c6a331a..fedad009 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php @@ -23,6 +23,9 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry1->setContent('This is my content /o/'); $entry1->setLanguage('en'); + $entry1->addTag($this->getReference('foo-tag')); + $entry1->addTag($this->getReference('baz-tag')); + $manager->persist($entry1); $this->addReference('entry1', $entry1); @@ -96,6 +99,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry6->setContent('This is my content /o/'); $entry6->setArchived(true); $entry6->setLanguage('de'); + $entry6->addTag($this->getReference('bar-tag')); $manager->persist($entry6); diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index a4b0d7a8..f2da3f4d 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -196,8 +196,6 @@ class Entry * @ORM\JoinColumn(name="tag_id", referencedColumnName="id") * } * ) - * - * @Groups({"entries_for_user", "export_all"}) */ private $tags; @@ -541,6 +539,21 @@ class Entry return $this->tags; } + /** + * @VirtualProperty + * @SerializedName("tags") + * @Groups({"entries_for_user", "export_all"}) + */ + public function getSerializedTags() + { + $data = []; + foreach ($this->tags as $tag) { + $data[] = $tag->getLabel(); + } + + return $data; + } + /** * @param Tag $tag */ diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 0c627dcd..d1f1e233 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -53,10 +53,6 @@ class EntriesExport $this->entries = $entries; - foreach ($entries as $entry) { - $this->tags[] = $entry->getTags(); - } - return $this; } @@ -159,8 +155,8 @@ class EntriesExport // set tags as subjects foreach ($this->entries as $entry) { - foreach ($this->tags as $tag) { - $book->setSubject($tag['value']); + foreach ($entry->getTags() as $tag) { + $book->setSubject($tag->getLabel()); } // the reader in Kobo Devices doesn't likes special caracters @@ -265,8 +261,8 @@ class EntriesExport * Adding actual entries */ foreach ($this->entries as $entry) { - foreach ($this->tags as $tag) { - $pdf->SetKeywords($tag['value']); + foreach ($entry->getTags() as $tag) { + $pdf->SetKeywords($tag->getLabel()); } $pdf->AddPage(); -- cgit v1.2.3