Builds domain location object from provided persistence location.
public buildLocationDomainObject ( eZ\Publish\SPI\Persistence\Content\Location $spiLocation ) : eZ\Publish\API\Repository\Values\Content\Location | ||
$spiLocation | eZ\Publish\SPI\Persistence\Content\Location | |
return | eZ\Publish\API\Repository\Values\Content\Location |
/** * Finds Locations for the given query. * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid * * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult */ public function findLocations(LocationQuery $query, $filterOnUserPermissions = true) { $query = clone $query; $query->filter = $query->filter ?: new Criterion\MatchAll(); $this->validateSortClauses($query); if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($query->filter)) { return new SearchResult(array('time' => 0, 'totalCount' => 0)); } if ($query->limit === null) { $query->limit = self::MAX_LIMIT; } $result = $this->locationSearchHandler->findLocations($query); foreach ($result->searchHits as $hit) { $hit->valueObject = $this->domainMapper->buildLocationDomainObject($hit->valueObject); } return $result; }
/** * Finds Locations for the given query. * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid * * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> * useAlwaysAvailable defaults to true to avoid exceptions on missing translations * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult */ public function findLocations(LocationQuery $query, array $languageFilter = array(), $filterOnUserPermissions = true) { if (!is_int($query->offset)) { throw new InvalidArgumentType('$query->offset', 'integer', $query->offset); } if (!is_int($query->limit)) { throw new InvalidArgumentType('$query->limit', 'integer', $query->limit); } $query = clone $query; $query->filter = $query->filter ?: new Criterion\MatchAll(); if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($query->filter)) { return new SearchResult(array('time' => 0, 'totalCount' => 0)); } $result = $this->searchHandler->findLocations($query, $languageFilter); foreach ($result->searchHits as $hit) { $hit->valueObject = $this->domainMapper->buildLocationDomainObject($hit->valueObject); } return $result; }
/** * Creates the new $location in the content repository for the given content. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent * or the parent is a sub location of the location of the content * or if set the remoteId exists already * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct * * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location */ public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct) { $content = $this->repository->getContentService()->loadContent($contentInfo->id); $parentLocation = $this->loadLocation($locationCreateStruct->parentLocationId); if (!$this->repository->canUser('content', 'create', $content->contentInfo, $parentLocation)) { throw new UnauthorizedException('content', 'create'); } // Check if the parent is a sub location of one of the existing content locations (this also solves the // situation where parent location actually one of the content locations), // or if the content already has location below given location create struct parent $existingContentLocations = $this->loadLocations($content->contentInfo); if (!empty($existingContentLocations)) { foreach ($existingContentLocations as $existingContentLocation) { if (stripos($parentLocation->pathString, $existingContentLocation->pathString) !== false) { throw new InvalidArgumentException('$locationCreateStruct', 'Specified parent is a sub location of one of the existing content locations.'); } if ($parentLocation->id == $existingContentLocation->parentLocationId) { throw new InvalidArgumentException('$locationCreateStruct', 'Content is already below the specified parent.'); } } } $spiLocationCreateStruct = $this->domainMapper->buildSPILocationCreateStruct($locationCreateStruct, $parentLocation, $content->contentInfo->mainLocationId !== null ? $content->contentInfo->mainLocationId : true, $content->contentInfo->id, $content->contentInfo->currentVersionNo); $this->repository->beginTransaction(); try { $newLocation = $this->persistenceHandler->locationHandler()->create($spiLocationCreateStruct); $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content); foreach ($urlAliasNames as $languageCode => $name) { $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation($newLocation->id, $newLocation->parentId, $name, $languageCode, $content->contentInfo->alwaysAvailable, $languageCode === $content->contentInfo->mainLanguageCode); } $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } return $this->domainMapper->buildLocationDomainObject($newLocation); }