diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-05-31 11:31:16 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-05-31 11:31:16 +0200 |
commit | f329e769fd7795f408643735edccb4dc4215c900 (patch) | |
tree | ed8f64c94c65fa2f8a40dffd6457d8bcd926f7dd /src/Wallabag/CoreBundle/Entity | |
parent | 839475776bdacf7e939984ee8230cb84d34c2289 (diff) | |
parent | 3be047456d6f91d8ef5404c9c7698e0d1f9a057d (diff) | |
download | wallabag-f329e769fd7795f408643735edccb4dc4215c900.tar.gz wallabag-f329e769fd7795f408643735edccb4dc4215c900.tar.zst wallabag-f329e769fd7795f408643735edccb4dc4215c900.zip |
Merge pull request #2122 from wallabag/fix-tags-deletion
Fix the deletion of Tags/Entries relation when delete an entry
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 19 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Tag.php | 23 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 1271f1f5..ceae78b0 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -177,8 +177,16 @@ class Entry | |||
177 | private $user; | 177 | private $user; |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist", "remove"}) | 180 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) |
181 | * @ORM\JoinTable | 181 | * @ORM\JoinTable( |
182 | * name="entry_tag", | ||
183 | * joinColumns={ | ||
184 | * @ORM\JoinColumn(name="entry_id", referencedColumnName="id") | ||
185 | * }, | ||
186 | * inverseJoinColumns={ | ||
187 | * @ORM\JoinColumn(name="tag_id", referencedColumnName="id") | ||
188 | * } | ||
189 | * ) | ||
182 | * | 190 | * |
183 | * @Groups({"entries_for_user", "export_all"}) | 191 | * @Groups({"entries_for_user", "export_all"}) |
184 | */ | 192 | */ |
@@ -526,13 +534,18 @@ class Entry | |||
526 | } | 534 | } |
527 | } | 535 | } |
528 | 536 | ||
529 | $this->tags[] = $tag; | 537 | $this->tags->add($tag); |
530 | $tag->addEntry($this); | 538 | $tag->addEntry($this); |
531 | } | 539 | } |
532 | 540 | ||
533 | public function removeTag(Tag $tag) | 541 | public function removeTag(Tag $tag) |
534 | { | 542 | { |
543 | if (!$this->tags->contains($tag)) { | ||
544 | return; | ||
545 | } | ||
546 | |||
535 | $this->tags->removeElement($tag); | 547 | $this->tags->removeElement($tag); |
548 | $tag->removeEntry($this); | ||
536 | } | 549 | } |
537 | 550 | ||
538 | /** | 551 | /** |
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index b4adbbd3..4b480ff1 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php | |||
@@ -98,9 +98,30 @@ class Tag | |||
98 | return $this->slug; | 98 | return $this->slug; |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | ||
102 | * @param Entry $entry | ||
103 | */ | ||
101 | public function addEntry(Entry $entry) | 104 | public function addEntry(Entry $entry) |
102 | { | 105 | { |
103 | $this->entries[] = $entry; | 106 | if ($this->entries->contains($entry)) { |
107 | return; | ||
108 | } | ||
109 | |||
110 | $this->entries->add($entry); | ||
111 | $entry->addTag($this); | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * @param Entry $entry | ||
116 | */ | ||
117 | public function removeEntry(Entry $entry) | ||
118 | { | ||
119 | if (!$this->entries->contains($entry)) { | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | $this->entries->removeElement($entry); | ||
124 | $entry->removeTag($this); | ||
104 | } | 125 | } |
105 | 126 | ||
106 | public function hasEntry($entry) | 127 | public function hasEntry($entry) |