Enhanced TagEditor::addSynonym()
authorAlexander Ebert <ebert@woltlab.com>
Tue, 21 May 2013 12:21:10 +0000 (14:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 21 May 2013 12:21:10 +0000 (14:21 +0200)
wcfsetup/install/files/lib/data/tag/TagEditor.class.php

index 1615e7be312e3f6ded889012fd6b1e57e7fef3d7..954ff35b2bd6201b5e788652c8834c150f41e65f 100644 (file)
@@ -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(