Beispiel #1
0
 /**
  * Restores a trashItem.
  *
  * @param $trashItemId
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  *
  * @return \eZ\Publish\Core\REST\Server\Values\ResourceCreated
  */
 public function restoreTrashItem($trashItemId, Request $request)
 {
     $requestDestination = null;
     try {
         $requestDestination = $request->headers->get('Destination');
     } catch (InvalidArgumentException $e) {
         // No Destination header
     }
     $parentLocation = null;
     if ($request->headers->has('Destination')) {
         $locationPathParts = explode('/', $this->requestParser->parseHref($request->headers->get('Destination'), 'locationPath'));
         try {
             $parentLocation = $this->locationService->loadLocation(array_pop($locationPathParts));
         } catch (NotFoundException $e) {
             throw new ForbiddenException($e->getMessage());
         }
     }
     $trashItem = $this->trashService->loadTrashItem($trashItemId);
     if ($requestDestination === null) {
         // If we're recovering under the original location
         // check if it exists, to return "403 Forbidden" in case it does not
         try {
             $this->locationService->loadLocation($trashItem->parentLocationId);
         } catch (NotFoundException $e) {
             throw new ForbiddenException($e->getMessage());
         }
     }
     $location = $this->trashService->recover($trashItem, $parentLocation);
     return new Values\ResourceCreated($this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => trim($location->pathString, '/'))));
 }
 /**
  * Loads a trashed location object from its $id.
  *
  * Note that $id is identical to original location, which has been previously trashed
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the trashed location
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the location with the given id does not exist
  *
  * @param mixed $trashItemId
  *
  * @return \eZ\Publish\API\Repository\Values\Content\TrashItem
  */
 public function loadTrashItem($trashItemId)
 {
     return $this->service->loadTrashItem($trashItemId);
 }