From a026765cd077c354579c6318eafeac98fecebe2b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 21 May 2013 14:21:10 +0200 Subject: [PATCH] Enhanced TagEditor::addSynonym() --- .../files/lib/data/tag/TagEditor.class.php | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/wcfsetup/install/files/lib/data/tag/TagEditor.class.php b/wcfsetup/install/files/lib/data/tag/TagEditor.class.php index 1615e7be31..954ff35b2b 100644 --- a/wcfsetup/install/files/lib/data/tag/TagEditor.class.php +++ b/wcfsetup/install/files/lib/data/tag/TagEditor.class.php @@ -25,35 +25,18 @@ class TagEditor extends DatabaseObjectEditor { * @param wcf\data\tag\Tag $synonym */ public function addSynonym(Tag $synonym) { - // clear up objects with both tags: the target and the synonym - // TODO: Optimize this! - $sql = "SELECT (objectTypeID || '-' || languageID || '-' || objectID || '-' || tagID) AS hash - FROM wcf".WCF_N."_tag_to_object - WHERE tagID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $this->tagID - )); - $parameters = array($this->tagID, $synonym->tagID, $this->tagID, ' '); - $notIn = '?'; - while ($row = $statement->fetchArray()) { - $parameters[] = $row['hash']; - $notIn .= ', ?'; - } - - $sql = "UPDATE wcf".WCF_N."_tag_to_object - SET tagID = ? - WHERE tagID = ? - AND ".str_replace('tagID', '?', $concat)." NOT IN (".$notIn.")"; + // assign all associations for the synonym with this tag + $sql = "UPDATE IGNORE wcf".WCF_N."_tag_to_object + SET tagID = ? + WHERE tagID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($parameters); + $statement->execute(array($this->tagID, $synonym->tagID)); + // remove remaining associations (object was tagged with both tags => duplicate key previously ignored) $sql = "DELETE FROM wcf".WCF_N."_tag_to_object WHERE tagID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $synonym->tagID, - )); + $statement->execute(array($synonym->tagID)); $editor = new TagEditor($synonym); $editor->update(array( -- 2.20.1