mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 19:11:07 +00:00
Merge pull request #2332 from wallabag/tags-export
Fix relations export for Entry
This commit is contained in:
commit
bf71a734f6
17 changed files with 84 additions and 42 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,6 @@ class EntriesExport
|
|||
private $entries = [];
|
||||
private $authors = ['wallabag'];
|
||||
private $language = '';
|
||||
private $tags = [];
|
||||
private $footerTemplate = '<div style="text-align:center;">
|
||||
<p>Produced by wallabag with %EXPORT_METHOD%</p>
|
||||
<p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p>
|
||||
|
@ -53,10 +52,6 @@ class EntriesExport
|
|||
|
||||
$this->entries = $entries;
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$this->tags[] = $entry->getTags();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -159,8 +154,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 +260,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();
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
# entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
# entry_updated: 'Entry updated'
|
||||
# entry_reloaded: 'Entry reloaded'
|
||||
# entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
# entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'Artikel arkiveret'
|
||||
entry_unarchived: 'Artikel ikke længere arkiveret'
|
||||
entry_starred: 'Artikel markeret som favorit'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
entry_saved_failed: 'Eintrag gespeichert, aber das Abrufen des Inhalts ist fehlgeschlagen'
|
||||
entry_updated: 'Eintrag aktualisiert'
|
||||
entry_reloaded: 'Eintrag neugeladen'
|
||||
entry_reload_failed: 'Eintrag neugeladen, aber das Abrufen des Inhalts ist fehlgeschlagen'
|
||||
entry_reloaded_failed: 'Eintrag neugeladen, aber das Abrufen des Inhalts ist fehlgeschlagen'
|
||||
entry_archived: 'Artikel archiviert'
|
||||
entry_unarchived: 'Artikel dearchiviert'
|
||||
entry_starred: 'Artikel favorisiert'
|
||||
|
|
|
@ -461,7 +461,7 @@ flashes:
|
|||
entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
entry_updated: 'Entry updated'
|
||||
entry_reloaded: 'Entry reloaded'
|
||||
entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'Entry archived'
|
||||
entry_unarchived: 'Entry unarchived'
|
||||
entry_starred: 'Entry starred'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
# entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
entry_updated: 'Entrada actualizada'
|
||||
entry_reloaded: 'Entrada recargada'
|
||||
# entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
# entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'Artículo archivado'
|
||||
entry_unarchived: 'Artículo desarchivado'
|
||||
entry_starred: 'Artículo guardado en los favoritos'
|
||||
|
|
|
@ -461,7 +461,7 @@ flashes:
|
|||
# entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
entry_updated: 'مقاله بهروز شد'
|
||||
entry_reloaded: 'مقاله بهروز شد'
|
||||
# entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
# entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'مقاله بایگانی شد'
|
||||
entry_unarchived: 'مقاله از بایگانی درآمد'
|
||||
entry_starred: 'مقاله برگزیده شد'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
entry_saved_failed: 'Article enregistré mais impossible de récupérer le contenu'
|
||||
entry_updated: 'Article mis à jour'
|
||||
entry_reloaded: 'Article rechargé'
|
||||
entry_reload_failed: "Article mis à jour mais impossible de récupérer le contenu"
|
||||
entry_reloaded_failed: "Article mis à jour mais impossible de récupérer le contenu"
|
||||
entry_archived: 'Article marqué comme lu'
|
||||
entry_unarchived: 'Article marqué comme non lu'
|
||||
entry_starred: 'Article ajouté dans les favoris'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
# entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
entry_updated: 'Contenuto aggiornato'
|
||||
entry_reloaded: 'Contenuto ricaricato'
|
||||
# entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
# entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'Contenuto archiviato'
|
||||
entry_unarchived: 'Contenuto dis-archiviato'
|
||||
entry_starred: 'Contenuto segnato come preferito'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
entry_saved_failed: 'Article salvat mai fracàs de la recuperacion del contengut'
|
||||
entry_updated: 'Article mes a jorn'
|
||||
entry_reloaded: 'Article recargat'
|
||||
entry_reload_failed: "L'article es estat cargat de nòu mai la recuperacion del contengut a fracassat"
|
||||
entry_reloaded_failed: "L'article es estat cargat de nòu mai la recuperacion del contengut a fracassat"
|
||||
entry_archived: 'Article marcat coma legit'
|
||||
entry_unarchived: 'Article marcat coma pas legit'
|
||||
entry_starred: 'Article apondut dins los favorits'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
entry_saved_failed: 'Wpis zapisany, ale wystąpił bład pobierania treści'
|
||||
entry_updated: 'Wpis zaktualizowany'
|
||||
entry_reloaded: 'Wpis ponownie załadowany'
|
||||
entry_reload_failed: 'Wpis ponownie załadowany, ale wystąpił bład pobierania treści'
|
||||
entry_reloaded_failed: 'Wpis ponownie załadowany, ale wystąpił bład pobierania treści'
|
||||
entry_archived: 'Wpis dodany do archiwum'
|
||||
entry_unarchived: 'Wpis usunięty z archiwum'
|
||||
entry_starred: 'Wpis oznaczony gwiazdką'
|
||||
|
|
|
@ -462,7 +462,7 @@ flashes:
|
|||
# entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
# entry_updated: 'Entry updated'
|
||||
# entry_reloaded: 'Entry reloaded'
|
||||
# entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
# entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'Articol arhivat'
|
||||
entry_unarchived: 'Articol dezarhivat'
|
||||
entry_starred: 'Articol adăugat la favorite'
|
||||
|
|
|
@ -461,7 +461,7 @@ flashes:
|
|||
# entry_saved_failed: 'Entry saved but fetching content failed'
|
||||
# entry_updated: 'Entry updated'
|
||||
entry_reloaded: 'Makale içeriği yenilendi'
|
||||
# entry_reload_failed: 'Entry reloaded but fetching content failed'
|
||||
# entry_reloaded_failed: 'Entry reloaded but fetching content failed'
|
||||
entry_archived: 'Makale arşivlendi'
|
||||
entry_unarchived: 'Makale arşivden çıkartıldı'
|
||||
entry_starred: 'Makale favorilere eklendi'
|
||||
|
|
|
@ -146,7 +146,9 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->createQueryBuilder('e')
|
||||
->select('e, t')
|
||||
->leftJoin('e.user', 'u')
|
||||
->leftJoin('e.tags', 't')
|
||||
->where('u.username = :username')->setParameter('username', 'admin')
|
||||
->andWhere('e.isArchived = true')
|
||||
->getQuery()
|
||||
|
@ -169,6 +171,18 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
// +1 for title line
|
||||
$this->assertEquals(count($contentInDB) + 1, count($csv));
|
||||
$this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
|
||||
$this->assertContains($contentInDB[0]['title'], $csv[1]);
|
||||
$this->assertContains($contentInDB[0]['url'], $csv[1]);
|
||||
$this->assertContains($contentInDB[0]['content'], $csv[1]);
|
||||
$this->assertContains($contentInDB[0]['mimetype'], $csv[1]);
|
||||
$this->assertContains($contentInDB[0]['language'], $csv[1]);
|
||||
$this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]);
|
||||
|
||||
$expectedTag = [];
|
||||
foreach ($contentInDB[0]['tags'] as $tag) {
|
||||
$expectedTag[] = $tag['label'];
|
||||
}
|
||||
$this->assertContains(implode(', ', $expectedTag), $csv[1]);
|
||||
}
|
||||
|
||||
public function testJsonExport()
|
||||
|
@ -176,29 +190,23 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
// to be sure results are the same
|
||||
$contentInDB = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('u.username = :username')->setParameter('username', 'admin')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/all.json');
|
||||
$crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json');
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$headers = $client->getResponse()->headers;
|
||||
$this->assertEquals('application/json', $headers->get('content-type'));
|
||||
$this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition'));
|
||||
$this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition'));
|
||||
$this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertEquals(count($contentInDB), count($content));
|
||||
$this->assertArrayHasKey('id', $content[0]);
|
||||
$this->assertArrayHasKey('title', $content[0]);
|
||||
$this->assertArrayHasKey('url', $content[0]);
|
||||
|
@ -212,6 +220,17 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertArrayHasKey('tags', $content[0]);
|
||||
$this->assertArrayHasKey('created_at', $content[0]);
|
||||
$this->assertArrayHasKey('updated_at', $content[0]);
|
||||
|
||||
$this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']);
|
||||
$this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']);
|
||||
$this->assertEquals($contentInDB->getTitle(), $content[0]['title']);
|
||||
$this->assertEquals($contentInDB->getUrl(), $content[0]['url']);
|
||||
$this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']);
|
||||
$this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']);
|
||||
$this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
|
||||
$this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
|
||||
$this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
|
||||
$this->assertEquals(['foo', 'baz'], $content[0]['tags']);
|
||||
}
|
||||
|
||||
public function testXmlExport()
|
||||
|
|
|
@ -26,7 +26,7 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
|
||||
|
||||
$crawler = $client->request('GET', '/view/'.$entry->getId());
|
||||
|
||||
|
@ -43,9 +43,9 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
|
||||
|
||||
$this->assertEquals(1, count($entry->getTags()));
|
||||
$this->assertEquals(3, count($entry->getTags()));
|
||||
|
||||
// tag already exists and already assigned
|
||||
$client->submit($form, $data);
|
||||
|
@ -56,7 +56,7 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->find($entry->getId());
|
||||
|
||||
$this->assertEquals(1, count($newEntry->getTags()));
|
||||
$this->assertEquals(3, count($newEntry->getTags()));
|
||||
|
||||
// tag already exists but still not assigned to this entry
|
||||
$data = [
|
||||
|
@ -71,7 +71,7 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->find($entry->getId());
|
||||
|
||||
$this->assertEquals(2, count($newEntry->getTags()));
|
||||
$this->assertEquals(3, count($newEntry->getTags()));
|
||||
}
|
||||
|
||||
public function testAddMultipleTagToEntry()
|
||||
|
@ -82,7 +82,7 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId());
|
||||
|
||||
$crawler = $client->request('GET', '/view/'.$entry->getId());
|
||||
|
||||
|
@ -101,9 +101,13 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
->find($entry->getId());
|
||||
|
||||
$tags = $newEntry->getTags()->toArray();
|
||||
foreach ($tags as $key => $tag) {
|
||||
$tags[$key] = $tag->getLabel();
|
||||
}
|
||||
|
||||
$this->assertGreaterThanOrEqual(2, count($tags));
|
||||
$this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry');
|
||||
$this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry');
|
||||
$this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry');
|
||||
$this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry');
|
||||
}
|
||||
|
||||
public function testRemoveTagFromEntry()
|
||||
|
@ -114,7 +118,7 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
|
||||
|
||||
$tag = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
|
@ -140,7 +144,7 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
|
||||
|
||||
$tag = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
|
@ -160,6 +164,6 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertCount(0, $crawler->filter('div[class=entry]'));
|
||||
$this->assertCount(1, $crawler->filter('div[class=entry]'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue