From: Alexander Ebert Date: Tue, 21 May 2013 12:21:10 +0000 (+0200) Subject: Enhanced TagEditor::addSynonym() X-Git-Tag: 2.0.0_Beta_1~102 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a026765cd077c354579c6318eafeac98fecebe2b;p=GitHub%2FWoltLab%2FWCF.git Enhanced TagEditor::addSynonym() --- 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(