Beispiel #1
0
 /**
  * Moves the subtree to $targetParentTag.
  *
  * @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 move this tag
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the target tag is a sub tag of the given tag
  *                                                                        If the target tag is already a parent of the given tag
  *                                                                        If either one of the tags is a synonym
  *
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $targetParentTag
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag The updated root tag of the moved subtree
  */
 public function moveSubtree(Tag $tag, Tag $targetParentTag)
 {
     if ($this->hasAccess('tags', 'edit') !== true) {
         throw new UnauthorizedException('tags', 'edit');
     }
     $spiTagInfo = $this->tagsHandler->loadTagInfo($tag->id);
     $spiParentTagInfo = $this->tagsHandler->loadTagInfo($targetParentTag->id);
     if ($spiTagInfo->mainTagId > 0) {
         throw new InvalidArgumentException('tag', 'Source tag is a synonym');
     }
     if ($spiParentTagInfo->mainTagId > 0) {
         throw new InvalidArgumentException('targetParentTag', 'Target parent tag is a synonym');
     }
     if ($tag->parentTagId == $targetParentTag->id) {
         throw new InvalidArgumentException('targetParentTag', 'Target parent tag is already the parent of the given tag');
     }
     if (strpos($spiParentTagInfo->pathString, $spiTagInfo->pathString) === 0) {
         throw new InvalidArgumentException('targetParentTag', 'Target parent tag is a sub tag of the given tag');
     }
     $this->repository->beginTransaction();
     try {
         $movedTag = $this->tagsHandler->moveSubtree($spiTagInfo->id, $spiParentTagInfo->id);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->buildTagDomainObject($movedTag);
 }