aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 14:50:52 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 14:50:52 +0100
commitfc73222723c7a0c9b577805d3ef51eb96b124b92 (patch)
tree002b77b82266b1e497e3683e72f4a457d4353633 /src/Wallabag
parentc997cfcc9c161241a6398b0942a1a869688d807a (diff)
downloadwallabag-fc73222723c7a0c9b577805d3ef51eb96b124b92.tar.gz
wallabag-fc73222723c7a0c9b577805d3ef51eb96b124b92.tar.zst
wallabag-fc73222723c7a0c9b577805d3ef51eb96b124b92.zip
Remove user reference in tag
Fix #1543
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php17
-rw-r--r--src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php3
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php12
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php19
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php41
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php2
-rw-r--r--src/Wallabag/CoreBundle/Entity/Tag.php17
-rw-r--r--src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php13
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php19
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php36
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php4
-rw-r--r--src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php12
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php27
13 files changed, 123 insertions, 99 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 74bfe4dc..587013f6 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -27,7 +27,7 @@ class WallabagRestController extends FOSRestController
27 ->findOneByLabel($label); 27 ->findOneByLabel($label);
28 28
29 if (is_null($tagEntity)) { 29 if (is_null($tagEntity)) {
30 $tagEntity = new Tag($this->getUser()); 30 $tagEntity = new Tag();
31 $tagEntity->setLabel($label); 31 $tagEntity->setLabel($label);
32 } 32 }
33 33
@@ -74,8 +74,7 @@ class WallabagRestController extends FOSRestController
74 $perPage = (int) $request->query->get('perPage', 30); 74 $perPage = (int) $request->query->get('perPage', 30);
75 $tags = $request->query->get('tags', []); 75 $tags = $request->query->get('tags', []);
76 76
77 $pager = $this 77 $pager = $this->getDoctrine()
78 ->getDoctrine()
79 ->getRepository('WallabagCoreBundle:Entry') 78 ->getRepository('WallabagCoreBundle:Entry')
80 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); 79 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
81 80
@@ -311,7 +310,12 @@ class WallabagRestController extends FOSRestController
311 public function getTagsAction() 310 public function getTagsAction()
312 { 311 {
313 $this->validateAuthentication(); 312 $this->validateAuthentication();
314 $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); 313
314 $tags = $this->getDoctrine()
315 ->getRepository('WallabagCoreBundle:Tag')
316 ->findAllTags($this->getUser()->getId());
317
318 $json = $this->get('serializer')->serialize($tags, 'json');
315 319
316 return $this->renderJsonResponse($json); 320 return $this->renderJsonResponse($json);
317 } 321 }
@@ -328,7 +332,10 @@ class WallabagRestController extends FOSRestController
328 public function deleteTagAction(Tag $tag) 332 public function deleteTagAction(Tag $tag)
329 { 333 {
330 $this->validateAuthentication(); 334 $this->validateAuthentication();
331 $this->validateUserAccess($tag->getUser()->getId()); 335
336 $this->getDoctrine()
337 ->getRepository('WallabagCoreBundle:Entry')
338 ->removeTag($this->getUser()->getId(), $tag);
332 339
333 $em = $this->getDoctrine()->getManager(); 340 $em = $this->getDoctrine()->getManager();
334 $em->remove($tag); 341 $em->remove($tag);
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
index bdd36e0c..a7120e83 100644
--- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
+++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
@@ -208,7 +208,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
208 208
209 $tags = array(); 209 $tags = array();
210 foreach ($entry->getTags() as $tag) { 210 foreach ($entry->getTags() as $tag) {
211 $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); 211 $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug());
212 } 212 }
213 213
214 $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags'); 214 $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags');
@@ -309,5 +309,6 @@ class WallabagRestControllerTest extends WallabagApiTestCase
309 309
310 $this->assertArrayHasKey('label', $content); 310 $this->assertArrayHasKey('label', $content);
311 $this->assertEquals($tag['label'], $content['label']); 311 $this->assertEquals($tag['label'], $content['label']);
312 $this->assertEquals($tag['slug'], $content['slug']);
312 } 313 }
313} 314}
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index fd2069e0..64d53f0c 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -20,25 +20,23 @@ class TagController extends Controller
20 */ 20 */
21 public function addTagFormAction(Request $request, Entry $entry) 21 public function addTagFormAction(Request $request, Entry $entry)
22 { 22 {
23 $tag = new Tag($this->getUser()); 23 $tag = new Tag();
24 $form = $this->createForm(new NewTagType(), $tag); 24 $form = $this->createForm(new NewTagType(), $tag);
25 $form->handleRequest($request); 25 $form->handleRequest($request);
26 26
27 if ($form->isValid()) { 27 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine() 28 $existingTag = $this->getDoctrine()
29 ->getRepository('WallabagCoreBundle:Tag') 29 ->getRepository('WallabagCoreBundle:Tag')
30 ->findOneByLabelAndUserId($tag->getLabel(), $this->getUser()->getId()); 30 ->findOneByLabel($tag->getLabel());
31 31
32 $em = $this->getDoctrine()->getManager(); 32 $em = $this->getDoctrine()->getManager();
33 33
34 if (is_null($existingTag)) { 34 if (is_null($existingTag)) {
35 $entry->addTag($tag); 35 $entry->addTag($tag);
36 $em->persist($tag); 36 $em->persist($tag);
37 } else { 37 } elseif (!$existingTag->hasEntry($entry)) {
38 if (!$existingTag->hasEntry($entry)) { 38 $entry->addTag($existingTag);
39 $entry->addTag($existingTag); 39 $em->persist($existingTag);
40 $em->persist($existingTag);
41 }
42 } 40 }
43 41
44 $em->flush(); 42 $em->flush();
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
index 0513cdb8..6c6a331a 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
@@ -6,7 +6,6 @@ use Doctrine\Common\DataFixtures\AbstractFixture;
6use Doctrine\Common\DataFixtures\OrderedFixtureInterface; 6use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7use Doctrine\Common\Persistence\ObjectManager; 7use Doctrine\Common\Persistence\ObjectManager;
8use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
10 9
11class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface 10class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
12{ 11{
@@ -50,13 +49,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
50 $entry3->setContent('This is my content /o/'); 49 $entry3->setContent('This is my content /o/');
51 $entry3->setLanguage('en'); 50 $entry3->setLanguage('en');
52 51
53 $tag1 = new Tag($this->getReference('bob-user')); 52 $entry3->addTag($this->getReference('foo-tag'));
54 $tag1->setLabel('foo'); 53 $entry3->addTag($this->getReference('bar-tag'));
55 $tag2 = new Tag($this->getReference('bob-user'));
56 $tag2->setLabel('bar');
57
58 $entry3->addTag($tag1);
59 $entry3->addTag($tag2);
60 54
61 $manager->persist($entry3); 55 $manager->persist($entry3);
62 56
@@ -71,13 +65,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
71 $entry4->setContent('This is my content /o/'); 65 $entry4->setContent('This is my content /o/');
72 $entry4->setLanguage('en'); 66 $entry4->setLanguage('en');
73 67
74 $tag1 = new Tag($this->getReference('admin-user')); 68 $entry4->addTag($this->getReference('foo-tag'));
75 $tag1->setLabel('foo'); 69 $entry4->addTag($this->getReference('bar-tag'));
76 $tag2 = new Tag($this->getReference('admin-user'));
77 $tag2->setLabel('bar');
78
79 $entry4->addTag($tag1);
80 $entry4->addTag($tag2);
81 70
82 $manager->persist($entry4); 71 $manager->persist($entry4);
83 72
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php
new file mode 100644
index 00000000..8553dced
--- /dev/null
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\CoreBundle\DataFixtures\ORM;
4
5use Doctrine\Common\DataFixtures\AbstractFixture;
6use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7use Doctrine\Common\Persistence\ObjectManager;
8use Wallabag\CoreBundle\Entity\Tag;
9
10class LoadTagData extends AbstractFixture implements OrderedFixtureInterface
11{
12 /**
13 * {@inheritdoc}
14 */
15 public function load(ObjectManager $manager)
16 {
17 $tag1 = new Tag();
18 $tag1->setLabel('foo');
19
20 $manager->persist($tag1);
21
22 $this->addReference('foo-tag', $tag1);
23
24 $tag2 = new Tag();
25 $tag2->setLabel('bar');
26
27 $manager->persist($tag2);
28
29 $this->addReference('bar-tag', $tag2);
30
31 $manager->flush();
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function getOrder()
38 {
39 return 25;
40 }
41}
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 2813c944..b413c489 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -465,7 +465,7 @@ class Entry
465 // check if tag already exist but has not yet be persisted 465 // check if tag already exist but has not yet be persisted
466 // it seems that the previous condition with `contains()` doesn't check that case 466 // it seems that the previous condition with `contains()` doesn't check that case
467 foreach ($this->tags as $existingTag) { 467 foreach ($this->tags as $existingTag) {
468 if ($existingTag->getUser() !== $tag->getUser() || $existingTag->getLabel() === $tag->getLabel()) { 468 if ($existingTag->getLabel() === $tag->getLabel()) {
469 return; 469 return;
470 } 470 }
471 } 471 }
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php
index 4ed588be..0689c7b3 100644
--- a/src/Wallabag/CoreBundle/Entity/Tag.php
+++ b/src/Wallabag/CoreBundle/Entity/Tag.php
@@ -38,6 +38,7 @@ class Tag
38 private $label; 38 private $label;
39 39
40 /** 40 /**
41 * @Expose
41 * @Gedmo\Slug(fields={"label"}) 42 * @Gedmo\Slug(fields={"label"})
42 * @ORM\Column(length=128, unique=true) 43 * @ORM\Column(length=128, unique=true)
43 */ 44 */
@@ -48,14 +49,8 @@ class Tag
48 */ 49 */
49 private $entries; 50 private $entries;
50 51
51 /** 52 public function __construct()
52 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="tags")
53 */
54 private $user;
55
56 public function __construct(\Wallabag\UserBundle\Entity\User $user)
57 { 53 {
58 $this->user = $user;
59 $this->entries = new ArrayCollection(); 54 $this->entries = new ArrayCollection();
60 } 55 }
61 56
@@ -112,12 +107,4 @@ class Tag
112 { 107 {
113 return $this->entries->contains($entry); 108 return $this->entries->contains($entry);
114 } 109 }
115
116 /**
117 * @return User
118 */
119 public function getUser()
120 {
121 return $this->user;
122 }
123} 110}
diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
index 41ef25b8..991c9a56 100644
--- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
+++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
@@ -37,7 +37,7 @@ class RuleBasedTagger
37 } 37 }
38 38
39 foreach ($rule->getTags() as $label) { 39 foreach ($rule->getTags() as $label) {
40 $tag = $this->getTag($entry->getUser(), $label); 40 $tag = $this->getTag($label);
41 41
42 $entry->addTag($tag); 42 $entry->addTag($tag);
43 } 43 }
@@ -62,7 +62,7 @@ class RuleBasedTagger
62 62
63 foreach ($entries as $entry) { 63 foreach ($entries as $entry) {
64 foreach ($rule->getTags() as $label) { 64 foreach ($rule->getTags() as $label) {
65 $tag = $this->getTag($user, $label); 65 $tag = $this->getTag($label);
66 66
67 $entry->addTag($tag); 67 $entry->addTag($tag);
68 } 68 }
@@ -73,19 +73,18 @@ class RuleBasedTagger
73 } 73 }
74 74
75 /** 75 /**
76 * Fetch a tag for a user. 76 * Fetch a tag.
77 * 77 *
78 * @param User $user
79 * @param string $label The tag's label. 78 * @param string $label The tag's label.
80 * 79 *
81 * @return Tag 80 * @return Tag
82 */ 81 */
83 private function getTag(User $user, $label) 82 private function getTag($label)
84 { 83 {
85 $tag = $this->tagRepository->findOneByLabelAndUserId($label, $user->getId()); 84 $tag = $this->tagRepository->findOneByLabel($label);
86 85
87 if (!$tag) { 86 if (!$tag) {
88 $tag = new Tag($user); 87 $tag = new Tag();
89 $tag->setLabel($label); 88 $tag->setLabel($label);
90 } 89 }
91 90
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 57bf8024..9ff80d6e 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Repository;
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Pagerfanta\Adapter\DoctrineORMAdapter; 6use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Pagerfanta; 7use Pagerfanta\Pagerfanta;
8use Wallabag\CoreBundle\Entity\Tag;
8 9
9class EntryRepository extends EntityRepository 10class EntryRepository extends EntityRepository
10{ 11{
@@ -179,4 +180,22 @@ class EntryRepository extends EntityRepository
179 ->getQuery() 180 ->getQuery()
180 ->getSingleResult(); 181 ->getSingleResult();
181 } 182 }
183
184 /**
185 * Remove a tag from all user entries.
186 * We are using a native SQL query because Doctrine doesn't know EntryTag entity because it's a ManyToMany relation.
187 * Instead of that SQL query we should loop on every entry and remove the tag, could be really long ...
188 *
189 * @param int $userId
190 * @param Tag $tag
191 */
192 public function removeTag($userId, Tag $tag)
193 {
194 $sql = 'DELETE et FROM entry_tag et WHERE et.entry_id IN ( SELECT e.id FROM entry e WHERE e.user_id = :userId ) AND et.tag_id = :tagId';
195 $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
196 $stmt->execute([
197 'userId' => $userId,
198 'tagId' => $tag->getId(),
199 ]);
200 }
182} 201}
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
index ac3145a1..c4aeb594 100644
--- a/src/Wallabag/CoreBundle/Repository/TagRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -9,16 +9,29 @@ use Pagerfanta\Pagerfanta;
9class TagRepository extends EntityRepository 9class TagRepository extends EntityRepository
10{ 10{
11 /** 11 /**
12 * Find Tags. 12 * Return only the QueryBuilder to retrieve all tags for a given user.
13 * 13 *
14 * @param int $userId 14 * @param int $userId
15 * 15 *
16 * @return array 16 * @return QueryBuilder
17 */
18 private function getQbForAllTags($userId)
19 {
20 return $this->createQueryBuilder('t')
21 ->leftJoin('t.entries', 'e')
22 ->where('e.user = :userId')->setParameter('userId', $userId);
23 }
24
25 /**
26 * Find Tags and return a Pager.
27 *
28 * @param int $userId
29 *
30 * @return Pagerfanta
17 */ 31 */
18 public function findTags($userId) 32 public function findTags($userId)
19 { 33 {
20 $qb = $this->createQueryBuilder('t') 34 $qb = $this->getQbForAllTags($userId);
21 ->where('t.user =:userId')->setParameter('userId', $userId);
22 35
23 $pagerAdapter = new DoctrineORMAdapter($qb); 36 $pagerAdapter = new DoctrineORMAdapter($qb);
24 37
@@ -26,19 +39,16 @@ class TagRepository extends EntityRepository
26 } 39 }
27 40
28 /** 41 /**
29 * Find a tag by its label and its owner. 42 * Find Tags.
30 * 43 *
31 * @param string $label 44 * @param int $userId
32 * @param int $userId
33 * 45 *
34 * @return Tag|null 46 * @return array
35 */ 47 */
36 public function findOneByLabelAndUserId($label, $userId) 48 public function findAllTags($userId)
37 { 49 {
38 return $this->createQueryBuilder('t') 50 return $this->getQbForAllTags($userId)
39 ->where('t.label = :label')->setParameter('label', $label)
40 ->andWhere('t.user = :user_id')->setParameter('user_id', $userId)
41 ->getQuery() 51 ->getQuery()
42 ->getOneOrNullResult(); 52 ->getResult();
43 } 53 }
44} 54}
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
index 7b32354f..89ca31e2 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
@@ -44,7 +44,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
44 $form = $crawler->filter('button[id=config_save]')->form(); 44 $form = $crawler->filter('button[id=config_save]')->form();
45 45
46 $data = array( 46 $data = array(
47 'config[theme]' => 0, 47 'config[theme]' => 'baggy',
48 'config[items_per_page]' => '30', 48 'config[items_per_page]' => '30',
49 'config[language]' => 'en', 49 'config[language]' => 'en',
50 ); 50 );
@@ -63,7 +63,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
63 { 63 {
64 return array( 64 return array(
65 array(array( 65 array(array(
66 'config[theme]' => 0, 66 'config[theme]' => 'baggy',
67 'config[items_per_page]' => '', 67 'config[items_per_page]' => '',
68 'config[language]' => 'en', 68 'config[language]' => 'en',
69 )), 69 )),
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php
index 1de134b8..cddc8b08 100644
--- a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php
@@ -69,9 +69,7 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
69 69
70 $tags = $entry->getTags(); 70 $tags = $entry->getTags();
71 $this->assertSame('foo', $tags[0]->getLabel()); 71 $this->assertSame('foo', $tags[0]->getLabel());
72 $this->assertSame($user, $tags[0]->getUser());
73 $this->assertSame('bar', $tags[1]->getLabel()); 72 $this->assertSame('bar', $tags[1]->getLabel());
74 $this->assertSame($user, $tags[1]->getUser());
75 } 73 }
76 74
77 public function testTagWithAMixOfMatchingRules() 75 public function testTagWithAMixOfMatchingRules()
@@ -92,7 +90,6 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
92 90
93 $tags = $entry->getTags(); 91 $tags = $entry->getTags();
94 $this->assertSame('foo', $tags[0]->getLabel()); 92 $this->assertSame('foo', $tags[0]->getLabel());
95 $this->assertSame($user, $tags[0]->getUser());
96 } 93 }
97 94
98 public function testWhenTheTagExists() 95 public function testWhenTheTagExists()
@@ -100,7 +97,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
100 $taggingRule = $this->getTaggingRule('rule as string', array('foo')); 97 $taggingRule = $this->getTaggingRule('rule as string', array('foo'));
101 $user = $this->getUser([$taggingRule]); 98 $user = $this->getUser([$taggingRule]);
102 $entry = new Entry($user); 99 $entry = new Entry($user);
103 $tag = new Tag($user); 100 $tag = new Tag();
101 $tag->setLabel('foo');
104 102
105 $this->rulerz 103 $this->rulerz
106 ->expects($this->once()) 104 ->expects($this->once())
@@ -110,7 +108,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
110 108
111 $this->tagRepository 109 $this->tagRepository
112 ->expects($this->once()) 110 ->expects($this->once())
113 ->method('findOneByLabelAndUserId') 111 // the method `findOneByLabel` doesn't exist, EntityRepository will then call `_call` method
112 // to magically call the `findOneBy` with ['label' => 'foo']
113 ->method('__call')
114 ->willReturn($tag); 114 ->willReturn($tag);
115 115
116 $this->tagger->tag($entry); 116 $this->tagger->tag($entry);
@@ -118,7 +118,7 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
118 $this->assertFalse($entry->getTags()->isEmpty()); 118 $this->assertFalse($entry->getTags()->isEmpty());
119 119
120 $tags = $entry->getTags(); 120 $tags = $entry->getTags();
121 $this->assertSame($tag, $tags[0]); 121 $this->assertSame($tag->getLabel(), $tags[0]->getLabel());
122 } 122 }
123 123
124 public function testSameTagWithDifferentfMatchingRules() 124 public function testSameTagWithDifferentfMatchingRules()
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index e3b9a519..e6528420 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -13,7 +13,6 @@ use JMS\Serializer\Annotation\Expose;
13use FOS\UserBundle\Model\User as BaseUser; 13use FOS\UserBundle\Model\User as BaseUser;
14use Wallabag\CoreBundle\Entity\Config; 14use Wallabag\CoreBundle\Entity\Config;
15use Wallabag\CoreBundle\Entity\Entry; 15use Wallabag\CoreBundle\Entity\Entry;
16use Wallabag\CoreBundle\Entity\Tag;
17 16
18/** 17/**
19 * User. 18 * User.
@@ -70,11 +69,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
70 protected $config; 69 protected $config;
71 70
72 /** 71 /**
73 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Tag", mappedBy="user", cascade={"remove"})
74 */
75 protected $tags;
76
77 /**
78 * @ORM\Column(type="integer", nullable=true) 72 * @ORM\Column(type="integer", nullable=true)
79 */ 73 */
80 private $authCode; 74 private $authCode;
@@ -94,7 +88,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
94 { 88 {
95 parent::__construct(); 89 parent::__construct();
96 $this->entries = new ArrayCollection(); 90 $this->entries = new ArrayCollection();
97 $this->tags = new ArrayCollection();
98 $this->roles = array('ROLE_USER'); 91 $this->roles = array('ROLE_USER');
99 } 92 }
100 93
@@ -171,26 +164,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
171 return $this->entries; 164 return $this->entries;
172 } 165 }
173 166
174 /**
175 * @param Entry $entry
176 *
177 * @return User
178 */
179 public function addTag(Tag $tag)
180 {
181 $this->tags[] = $tag;
182
183 return $this;
184 }
185
186 /**
187 * @return ArrayCollection<Tag>
188 */
189 public function getTags()
190 {
191 return $this->tags;
192 }
193
194 public function isEqualTo(UserInterface $user) 167 public function isEqualTo(UserInterface $user)
195 { 168 {
196 return $this->username === $user->getUsername(); 169 return $this->username === $user->getUsername();