コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * Updates $location in the content repository.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
  */
 public function updateLocation(APILocation $location, LocationUpdateStruct $locationUpdateStruct)
 {
     if ($locationUpdateStruct->priority !== null && !is_int($locationUpdateStruct->priority)) {
         throw new InvalidArgumentValue('priority', $locationUpdateStruct->priority, 'LocationUpdateStruct');
     }
     if ($locationUpdateStruct->remoteId !== null && (!is_string($locationUpdateStruct->remoteId) || empty($locationUpdateStruct->remoteId))) {
         throw new InvalidArgumentValue('remoteId', $locationUpdateStruct->remoteId, 'LocationUpdateStruct');
     }
     if ($locationUpdateStruct->sortField !== null && !$this->domainMapper->isValidLocationSortField($locationUpdateStruct->sortField)) {
         throw new InvalidArgumentValue('sortField', $locationUpdateStruct->sortField, 'LocationUpdateStruct');
     }
     if ($locationUpdateStruct->sortOrder !== null && !$this->domainMapper->isValidLocationSortOrder($locationUpdateStruct->sortOrder)) {
         throw new InvalidArgumentValue('sortOrder', $locationUpdateStruct->sortOrder, 'LocationUpdateStruct');
     }
     $loadedLocation = $this->loadLocation($location->id);
     if ($locationUpdateStruct->remoteId !== null) {
         try {
             $existingLocation = $this->loadLocationByRemoteId($locationUpdateStruct->remoteId);
             if ($existingLocation !== null && $existingLocation->id !== $loadedLocation->id) {
                 throw new InvalidArgumentException('locationUpdateStruct', 'location with provided remote ID already exists');
             }
         } catch (APINotFoundException $e) {
         }
     }
     if (!$this->repository->canUser('content', 'edit', $loadedLocation->getContentInfo(), $loadedLocation)) {
         throw new UnauthorizedException('content', 'edit');
     }
     $updateStruct = new UpdateStruct();
     $updateStruct->priority = $locationUpdateStruct->priority !== null ? $locationUpdateStruct->priority : $loadedLocation->priority;
     $updateStruct->remoteId = $locationUpdateStruct->remoteId !== null ? trim($locationUpdateStruct->remoteId) : $loadedLocation->remoteId;
     $updateStruct->sortField = $locationUpdateStruct->sortField !== null ? $locationUpdateStruct->sortField : $loadedLocation->sortField;
     $updateStruct->sortOrder = $locationUpdateStruct->sortOrder !== null ? $locationUpdateStruct->sortOrder : $loadedLocation->sortOrder;
     $this->repository->beginTransaction();
     try {
         $this->persistenceHandler->locationHandler()->update($updateStruct, $loadedLocation->id);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->loadLocation($loadedLocation->id);
 }
コード例 #4
0
 /**
  * Adds a relation of type common.
  *
  * The source of the relation is the content and version
  * referenced by $versionInfo.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version
  * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
  *
  * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation
  */
 public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent)
 {
     $sourceVersion = $this->loadVersionInfoById($sourceVersion->contentInfo->id, $sourceVersion->versionNo);
     if ($sourceVersion->status !== APIVersionInfo::STATUS_DRAFT) {
         throw new BadStateException('$sourceVersion', 'Relations of type common can only be added to versions of status draft');
     }
     if (!$this->repository->canUser('content', 'edit', $sourceVersion)) {
         throw new UnauthorizedException('content', 'edit', array('contentId' => $sourceVersion->contentInfo->id));
     }
     $sourceContentInfo = $sourceVersion->getContentInfo();
     $this->repository->beginTransaction();
     try {
         $spiRelation = $this->persistenceHandler->contentHandler()->addRelation(new SPIRelationCreateStruct(array('sourceContentId' => $sourceContentInfo->id, 'sourceContentVersionNo' => $sourceVersion->versionNo, 'sourceFieldDefinitionId' => null, 'destinationContentId' => $destinationContent->id, 'type' => APIRelation::COMMON)));
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->domainMapper->buildRelationDomainObject($spiRelation, $sourceContentInfo, $destinationContent);
 }
コード例 #5
0
 /**
  * Create a Content Type object.
  *
  * The content type is created in the state STATUS_DRAFT.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create a content type
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException In case when
  *         - array of content type groups does not contain at least one content type group
  *         - identifier or remoteId in the content type create struct already exists
  *         - there is a duplicate field identifier in the content type create struct
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
  *         if a field definition in the $contentTypeCreateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeValidationException
  *         if a multiple field definitions of a same singular type are given
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup[] $contentTypeGroups Required array of {@link ContentTypeGroup} to link type with (must contain one)
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
  */
 public function createContentType(APIContentTypeCreateStruct $contentTypeCreateStruct, array $contentTypeGroups)
 {
     if ($this->repository->hasAccess('class', 'create') !== true) {
         throw new UnauthorizedException('ContentType', 'create');
     }
     // Prevent argument mutation
     $contentTypeCreateStruct = clone $contentTypeCreateStruct;
     $this->validateInputContentTypeCreateStruct($contentTypeCreateStruct);
     $this->validateInputContentTypeGroups($contentTypeGroups);
     $initialLanguageId = $this->repository->getContentLanguageService()->loadLanguage($contentTypeCreateStruct->mainLanguageCode)->id;
     try {
         $this->contentTypeHandler->loadByIdentifier($contentTypeCreateStruct->identifier);
         throw new InvalidArgumentException("\$contentTypeCreateStruct", "Another ContentType with identifier '{$contentTypeCreateStruct->identifier}' exists");
     } catch (APINotFoundException $e) {
         // Do nothing
     }
     if ($contentTypeCreateStruct->remoteId !== null) {
         try {
             $this->contentTypeHandler->loadByRemoteId($contentTypeCreateStruct->remoteId);
             throw new InvalidArgumentException("\$contentTypeCreateStruct", "Another ContentType with remoteId '{$contentTypeCreateStruct->remoteId}' exists");
         } catch (APINotFoundException $e) {
             // Do nothing
         }
     }
     $fieldDefinitionIdentifierSet = array();
     $fieldDefinitionPositionSet = array();
     foreach ($contentTypeCreateStruct->fieldDefinitions as $fieldDefinitionCreateStruct) {
         // Check for duplicate identifiers
         if (!isset($fieldDefinitionIdentifierSet[$fieldDefinitionCreateStruct->identifier])) {
             $fieldDefinitionIdentifierSet[$fieldDefinitionCreateStruct->identifier] = true;
         } else {
             throw new InvalidArgumentException("\$contentTypeCreateStruct", "Argument contains duplicate field definition identifier '{$fieldDefinitionCreateStruct->identifier}'");
         }
         // Check for duplicate positions
         if (!isset($fieldDefinitionPositionSet[$fieldDefinitionCreateStruct->position])) {
             $fieldDefinitionPositionSet[$fieldDefinitionCreateStruct->position] = true;
         } else {
             throw new InvalidArgumentException("\$contentTypeCreateStruct", "Argument contains duplicate field definition position '{$fieldDefinitionCreateStruct->position}'");
         }
     }
     $allValidationErrors = array();
     $spiFieldDefinitions = array();
     $fieldTypeIdentifierSet = array();
     foreach ($contentTypeCreateStruct->fieldDefinitions as $fieldDefinitionCreateStruct) {
         /** @var $fieldType \eZ\Publish\SPI\FieldType\FieldType */
         $fieldType = $this->fieldTypeRegistry->getFieldType($fieldDefinitionCreateStruct->fieldTypeIdentifier);
         if ($fieldType->isSingular() && isset($fieldTypeIdentifierSet[$fieldDefinitionCreateStruct->fieldTypeIdentifier])) {
             throw new ContentTypeValidationException("FieldType '{$fieldDefinitionCreateStruct->fieldTypeIdentifier}' is singular and can't be repeated in a ContentType");
         }
         $fieldTypeIdentifierSet[$fieldDefinitionCreateStruct->fieldTypeIdentifier] = true;
         $fieldType->applyDefaultSettings($fieldDefinitionCreateStruct->fieldSettings);
         $fieldType->applyDefaultValidatorConfiguration($fieldDefinitionCreateStruct->validatorConfiguration);
         $validationErrors = $this->validateFieldDefinitionCreateStruct($fieldDefinitionCreateStruct, $fieldType);
         if (!empty($validationErrors)) {
             $allValidationErrors[$fieldDefinitionCreateStruct->identifier] = $validationErrors;
         }
         if (!empty($allValidationErrors)) {
             continue;
         }
         $spiFieldDefinitions[] = $this->buildSPIFieldDefinitionCreate($fieldDefinitionCreateStruct, $fieldType);
     }
     if (!empty($allValidationErrors)) {
         throw new ContentTypeFieldDefinitionValidationException($allValidationErrors);
     }
     $groupIds = array_map(function (ContentTypeGroup $contentTypeGroup) {
         return $contentTypeGroup->id;
     }, $contentTypeGroups);
     if ($contentTypeCreateStruct->creatorId === null) {
         $contentTypeCreateStruct->creatorId = $this->repository->getCurrentUser()->id;
     }
     if ($contentTypeCreateStruct->creationDate === null) {
         $timestamp = time();
     } else {
         $timestamp = $contentTypeCreateStruct->creationDate->getTimestamp();
     }
     if ($contentTypeCreateStruct->remoteId === null) {
         $contentTypeCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentTypeCreateStruct);
     }
     $spiContentTypeCreateStruct = new SPIContentTypeCreateStruct(array('identifier' => $contentTypeCreateStruct->identifier, 'name' => $contentTypeCreateStruct->names, 'status' => APIContentType::STATUS_DRAFT, 'description' => $contentTypeCreateStruct->descriptions === null ? array() : $contentTypeCreateStruct->descriptions, 'created' => $timestamp, 'modified' => $timestamp, 'creatorId' => $contentTypeCreateStruct->creatorId, 'modifierId' => $contentTypeCreateStruct->creatorId, 'remoteId' => $contentTypeCreateStruct->remoteId, 'urlAliasSchema' => $contentTypeCreateStruct->urlAliasSchema === null ? '' : $contentTypeCreateStruct->urlAliasSchema, 'nameSchema' => $contentTypeCreateStruct->nameSchema === null ? '' : $contentTypeCreateStruct->nameSchema, 'isContainer' => $contentTypeCreateStruct->isContainer === null ? false : $contentTypeCreateStruct->isContainer, 'initialLanguageId' => $initialLanguageId, 'sortField' => $contentTypeCreateStruct->defaultSortField === null ? Location::SORT_FIELD_PUBLISHED : $contentTypeCreateStruct->defaultSortField, 'sortOrder' => $contentTypeCreateStruct->defaultSortOrder === null ? Location::SORT_ORDER_DESC : $contentTypeCreateStruct->defaultSortOrder, 'groupIds' => $groupIds, 'fieldDefinitions' => $spiFieldDefinitions, 'defaultAlwaysAvailable' => $contentTypeCreateStruct->defaultAlwaysAvailable));
     $this->repository->beginTransaction();
     try {
         $spiContentType = $this->contentTypeHandler->create($spiContentTypeCreateStruct);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->buildContentTypeDraftDomainObject($spiContentType);
 }