/** * 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, '/')))); }
/** * Recovers the $trashedLocation at its original place if possible. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to recover the trash item at the parent location location * * If $newParentLocation is provided, $trashedLocation will be restored under it. * * @param \eZ\Publish\API\Repository\Values\Content\TrashItem $trashItem * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation * * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created or recovered location */ public function recover(TrashItem $trashItem, Location $newParentLocation = null) { $newLocation = $this->service->recover($trashItem, $newParentLocation); $this->signalDispatcher->emit(new RecoverSignal(array('trashItemId' => $trashItem->id, 'newParentLocationId' => $newParentLocation !== null ? $newParentLocation->id : null, 'newLocationId' => $newLocation->id))); return $newLocation; }