public static function addTag($document, $tagId, $updateCache = true, $move = true) { try { $c = new Criteria(); $c->add(TagPeer::TAG_ID, $tagId); $tag = TagPeer::doSelectOne($c); if ($tag->getExclusive()) { $c = new Criteria(); $c->add(TagrelationPeer::TAG_ID, $tag->getId()); $tagRelation = TagrelationPeer::doSelectOne($c); if ($tagRelation) { $tagRelation->delete(); } } $tagRelation = TagrelationPeer::retrieveByPk($document->getId(), $tag->getId()); if (!$tagRelation) { $tagRelation = new Tagrelation(); $tagRelation->setId($document->getId()); $tagRelation->setTagId($tag->getId()); $tagRelation->save(); } if ($updateCache) { Tagrelation::updateTagRelationCache(); } } catch (Exception $e) { throw $e; } }