/** * Moves a subtree to a new location. * * @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 moveSubtree($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)); $this->tagsService->moveSubtree($tag, $destinationTag); // Reload the tag to get the new position is subtree $tag = $this->tagsService->loadTag($tag->id); return new BaseValues\ResourceCreated($this->router->generate('ezpublish_rest_eztags_loadTag', array('tagPath' => trim($tag->pathString, '/')))); }
/** * 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) { $returnValue = $this->service->moveSubtree($tag, $targetParentTag); $this->signalDispatcher->emit(new MoveSubtreeSignal(array('sourceTagId' => $tag->id, 'targetParentTagId' => $targetParentTag->id))); return $returnValue; }
/** * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * * @covers \Netgen\TagsBundle\Core\Repository\TagsService::moveSubtree */ public function testMoveSubtreeThrowsUnauthorizedException() { $this->repository->setCurrentUser($this->getStubbedUser(10)); $this->tagsService->moveSubtree(new Tag(array('id' => 16)), new Tag(array('id' => 40))); }