From fc031e5706acf89ff21f22ca8004ddc7f9b43089 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 27 Dec 2015 22:26:49 +0100 Subject: Avoid multiple tag creation When a new tag is created but not yet persisted, it can be duplicated. It could happen when multiple rules match the content and at least 2 of them should attach same new tag. Fix #1528 --- src/Wallabag/CoreBundle/Entity/Entry.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Wallabag/CoreBundle/Entity') diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 608ed2f0..2813c944 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -462,6 +462,14 @@ class Entry return; } + // check if tag already exist but has not yet be persisted + // it seems that the previous condition with `contains()` doesn't check that case + foreach ($this->tags as $existingTag) { + if ($existingTag->getUser() !== $tag->getUser() || $existingTag->getLabel() === $tag->getLabel()) { + return; + } + } + $this->tags[] = $tag; $tag->addEntry($this); } -- cgit v1.2.3