/** * Converts a tag to synonym. * * @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 convertToSynonym($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"); } $mainTag = $this->tagsService->loadTag($this->extractTagIdFromPath($parsedDestinationHref)); $convertedTag = $this->tagsService->convertToSynonym($tag, $mainTag); return new BaseValues\ResourceCreated($this->router->generate('ezpublish_rest_eztags_loadTag', array('tagPath' => trim($convertedTag->pathString, '/')))); }
/** * Converts $tag to a synonym of $mainTag. * * @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 convert tag to synonym * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If either one of the tags is a synonym * If the main 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 $mainTag * * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag The converted synonym */ public function convertToSynonym(Tag $tag, Tag $mainTag) { $returnValue = $this->service->convertToSynonym($tag, $mainTag); $this->signalDispatcher->emit(new ConvertToSynonymSignal(array('tagId' => $returnValue->id, 'mainTagId' => $returnValue->mainTagId))); return $returnValue; }
/** * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException * * @covers \Netgen\TagsBundle\Core\Repository\TagsService::convertToSynonym */ public function testConvertToSynonymThrowsUnauthorizedException() { $this->repository->setCurrentUser($this->getStubbedUser(10)); $this->tagsService->convertToSynonym(new Tag(array('id' => 16)), new Tag(array('id' => 40))); }