Beispiel #1
0
 /**
  * Merges the $tag into the $targetTag.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If either of specified tags is not found
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to merge tags
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If either one of the tags is a synonym
  *                                                                        If the target tag is a sub tag of the given tag
  *
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $targetTag
  */
 public function mergeTags(Tag $tag, Tag $targetTag)
 {
     if ($this->hasAccess('tags', 'merge') !== true) {
         throw new UnauthorizedException('tags', 'merge');
     }
     $spiTagInfo = $this->tagsHandler->loadTagInfo($tag->id);
     $spiTargetTagInfo = $this->tagsHandler->loadTagInfo($targetTag->id);
     if ($spiTagInfo->mainTagId > 0) {
         throw new InvalidArgumentException('tag', 'Source tag is a synonym');
     }
     if ($spiTargetTagInfo->mainTagId > 0) {
         throw new InvalidArgumentException('targetTag', 'Target tag is a synonym');
     }
     if (strpos($spiTargetTagInfo->pathString, $spiTagInfo->pathString) === 0) {
         throw new InvalidArgumentException('targetParentTag', 'Target tag is a sub tag of the given tag');
     }
     $this->repository->beginTransaction();
     try {
         foreach ($this->tagsHandler->loadChildren($spiTagInfo->id) as $child) {
             $this->tagsHandler->moveSubtree($child->id, $spiTargetTagInfo->id);
         }
         $this->tagsHandler->merge($spiTagInfo->id, $spiTargetTagInfo->id);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
 }