/** * 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(APITrashItem $trashItem, Location $newParentLocation = null) { if (!is_numeric($trashItem->id)) { throw new InvalidArgumentValue("id", $trashItem->id, "TrashItem"); } if ($newParentLocation === null && !is_numeric($trashItem->parentLocationId)) { throw new InvalidArgumentValue("parentLocationId", $trashItem->parentLocationId, "TrashItem"); } if ($newParentLocation !== null && !is_numeric($newParentLocation->id)) { throw new InvalidArgumentValue("parentLocationId", $newParentLocation->id, "Location"); } if ($this->repository->hasAccess('content', 'restore') !== true) { throw new UnauthorizedException('content', 'restore'); } $this->repository->beginTransaction(); try { $newParentLocationId = $newParentLocation ? $newParentLocation->id : $trashItem->parentLocationId; $newLocationId = $this->persistenceHandler->trashHandler()->recover($trashItem->id, $newParentLocationId); $content = $this->repository->getContentService()->loadContent($trashItem->contentId); $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content); // Publish URL aliases for recovered location foreach ($urlAliasNames as $languageCode => $name) { $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation($newLocationId, $newParentLocationId, $name, $languageCode, $content->contentInfo->alwaysAvailable); } $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } return $this->repository->getLocationService()->loadLocation($newLocationId); }
/** * Deletes $location and all its descendants. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant * * @param \eZ\Publish\API\Repository\Values\Content\Location $location */ public function deleteLocation(APILocation $location) { $location = $this->loadLocation($location->id); if (!$this->repository->canUser('content', 'manage_locations', $location->getContentInfo())) { throw new UnauthorizedException('content', 'manage_locations'); } if (!$this->repository->canUser('content', 'remove', $location->getContentInfo(), $location)) { throw new UnauthorizedException('content', 'remove'); } /** Check remove access to descendants * @var boolean|\eZ\Publish\API\Repository\Values\Content\Query\Criterion $contentReadCriterion */ $contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion('content', 'remove'); if ($contentReadCriterion === false) { throw new UnauthorizedException('content', 'remove'); } else { if ($contentReadCriterion !== true) { // Query if there are any content in subtree current user don't have access to $query = new Query(array('limit' => 0, 'filter' => new CriterionLogicalAnd(array(new CriterionSubtree($location->pathString), new CriterionLogicalNot($contentReadCriterion))))); $result = $this->repository->getSearchService()->findContent($query, array(), false); if ($result->totalCount > 0) { throw new UnauthorizedException('content', 'remove'); } } } $this->repository->beginTransaction(); try { $this->persistenceHandler->locationHandler()->removeSubtree($location->id); $this->persistenceHandler->urlAliasHandler()->locationDeleted($location->id); $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } }
/** * Deletes a content object including all its versions and locations including their subtrees. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */ public function deleteContent( ContentInfo $contentInfo ) { $contentInfo = $this->internalLoadContentInfo( $contentInfo->id ); if ( !$this->repository->canUser( 'content', 'remove', $contentInfo ) ) throw new UnauthorizedException( 'content', 'remove', array( 'contentId' => $contentInfo->id ) ); $this->repository->beginTransaction(); try { // Load Locations first as deleting Content also deletes belonging Locations $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent( $contentInfo->id ); $this->persistenceHandler->contentHandler()->deleteContent( $contentInfo->id ); foreach ( $spiLocations as $spiLocation ) { $this->persistenceHandler->urlAliasHandler()->locationDeleted( $spiLocation->id ); } $this->repository->commit(); } catch ( Exception $e ) { $this->repository->rollback(); throw $e; } }
/** * Get URLAliasService * * @return \eZ\Publish\API\Repository\URLAliasService */ public function getURLAliasService() { if ($this->urlAliasService !== null) { return $this->urlAliasService; } $this->urlAliasService = new URLAliasService($this, $this->persistenceHandler->urlAliasHandler(), $this->serviceSettings['urlAlias']); return $this->urlAliasService; }