public function moveSubtree(APILocation $location, APILocation $newParentLocation)
{
$location = $this->loadLocation($location->id);
$newParentLocation = $this->loadLocation($newParentLocation->id);
// check create permission on target location
if (!$this->repository->canUser('content', 'create', $location->getContentInfo(), $newParentLocation)) {
throw new UnauthorizedException('content', 'create');
}
/** Check read access to whole source subtree
* @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
*/
$contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion();
if ($contentReadCriterion === false) {
throw new UnauthorizedException('content', 'read');
} 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', 'read');
}
}
if (strpos($newParentLocation->pathString, $location->pathString) === 0) {
throw new InvalidArgumentException('$newParentLocation', 'new parent location is in a subtree of the given $location');
}
$this->repository->beginTransaction();
try {
$this->persistenceHandler->locationHandler()->move($location->id, $newParentLocation->id);
$content = $this->repository->getContentService()->loadContent($location->contentId);
$urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
foreach ($urlAliasNames as $languageCode => $name) {
$this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation($location->id, $newParentLocation->id, $name, $languageCode, $content->contentInfo->alwaysAvailable);
}
$this->persistenceHandler->urlAliasHandler()->locationMoved($location->id, $location->parentLocationId, $newParentLocation->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}