Get service object to perform operations on Content objects and it's aggregate members.
public getContentService ( ) : eZ\Publish\API\Repository\ContentService | ||
return | eZ\Publish\API\Repository\ContentService |
/** * Performs a query for a single content object * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if criterion is not valid * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is more than one result matching the criterions * * @todo define structs for the field filters * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter * @param array $fieldFilters - a map of filters for the returned fields. * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function findSingle(Criterion $filter, array $fieldFilters = array(), $filterOnUserPermissions = true) { $this->validateContentCriteria(array($filter), "\$filter"); if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($filter)) { throw new NotFoundException('Content', '*'); } $contentInfo = $this->searchHandler->findSingle($filter, $fieldFilters); return $this->repository->getContentService()->loadContent($contentInfo->id, !empty($fieldFilters['languages']) ? $fieldFilters['languages'] : null, null, isset($fieldFilters['useAlwaysAvailable']) ? $fieldFilters['useAlwaysAvailable'] : true); }
/** * @param SearchResult $searchResult * @return Content * @throws ContentNotFoundException */ protected function fetchSingleContentFromSearchResult($searchResult) { foreach ($searchResult->searchHits as $searchHit) { /** @var Location $location */ $location = $searchHit->valueObject; return $this->repository->getContentService()->loadContent($location->contentId); } throw new ContentNotFoundException(); }
/** * Moves the subtree to $newParentLocation * * If a user has the permission to move the location to a target location * he can do it regardless of an existing descendant on which the user has no permission. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the new parent is in a subtree of the location * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation */ 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 boolean|\eZ\Publish\API\Repository\Values\Content\Query\Criterion $contentReadCriterion */ $contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion(); if ($contentReadCriterion === false) { throw new UnauthorizedException('content', 'read'); } 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(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; } }