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 bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
*/
$contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion('content', 'remove');
if ($contentReadCriterion === false) {
throw new UnauthorizedException('content', 'remove');
} elseif ($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;
}
}