3 namespace wcf\data\tag
;
5 use wcf\data\DatabaseObjectEditor
;
9 * Provides functions to edit tags.
11 * @author Tim Duesterhus, Marcel Werk
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @method static Tag create(array $parameters = [])
16 * @method Tag getDecoratedObject()
19 class TagEditor
extends DatabaseObjectEditor
24 protected static $baseClass = Tag
::class;
27 * Adds the given tag, and all of it's synonyms as a synonym.
31 public function addSynonym(Tag
$synonym)
33 if ($synonym->tagID
== $this->tagID
) {
37 // assign all associations for the synonym with this tag
38 $sql = "UPDATE IGNORE wcf" . WCF_N
. "_tag_to_object
41 $statement = WCF
::getDB()->prepareStatement($sql);
42 $statement->execute([$this->tagID
, $synonym->tagID
]);
44 // remove remaining associations (object was tagged with both tags => duplicate key previously ignored)
45 $sql = "DELETE FROM wcf" . WCF_N
. "_tag_to_object
47 $statement = WCF
::getDB()->prepareStatement($sql);
48 $statement->execute([$synonym->tagID
]);
50 $editor = new self($synonym);
51 $editor->update(['synonymFor' => $this->tagID
]);
53 $synonymList = new TagList();
54 $synonymList->getConditionBuilder()->add('synonymFor = ?', [$synonym->tagID
]);
55 $synonymList->readObjects();
57 foreach ($synonymList as $synonym) {
58 $this->addSynonym($synonym);