/** * Copies a subtree to a new destination. * * @param string $tagPath * @param \Symfony\Component\HttpFoundation\Request $request * * @throws \eZ\Publish\Core\REST\Server\Exceptions\BadRequestException if the Destination header cannot be parsed as a tag * * @return \eZ\Publish\Core\REST\Server\Values\ResourceCreated */ public function copySubtree($tagPath, Request $request) { $tag = $this->tagsService->loadTag($this->extractTagIdFromPath($tagPath)); $destinationHref = $request->headers->get('Destination'); try { $parsedDestinationHref = $this->requestParser->parseHref($destinationHref, 'tagPath'); } catch (Exceptions\InvalidArgumentException $e) { throw new BadRequestException("{$destinationHref} is not an acceptable destination"); } $destinationTag = $this->tagsService->loadTag($this->extractTagIdFromPath($parsedDestinationHref)); $newTag = $this->tagsService->copySubtree($tag, $destinationTag); return new BaseValues\ResourceCreated($this->router->generate('ezpublish_rest_eztags_loadTag', array('tagPath' => trim($newTag->pathString, '/')))); }
/** * Copies the subtree starting from $tag as a new subtree of $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 read tags * @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 The subtree denoted by the tag to copy * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $targetParentTag The target parent tag for the copy operation * * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag The newly created tag of the copied subtree */ public function copySubtree(Tag $tag, Tag $targetParentTag) { $returnValue = $this->service->copySubtree($tag, $targetParentTag); $this->signalDispatcher->emit(new CopySubtreeSignal(array('sourceTagId' => $tag->id, 'targetParentTagId' => $targetParentTag->id, 'newTagId' => $returnValue->id))); return $returnValue; }
/** * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * * @covers \Netgen\TagsBundle\Core\Repository\TagsService::copySubtree */ public function testCopySubtreeThrowsUnauthorizedException() { $this->repository->setCurrentUser($this->getStubbedUser(10)); $this->tagsService->copySubtree(new Tag(array('id' => 16)), new Tag(array('id' => 40))); }