Performs mapping of Content objects.
コード例 #1
0
 /**
  * Applies the action to the given $content.
  *
  * @param int $contentId
  */
 public function apply($contentId)
 {
     $versionNumbers = $this->contentGateway->listVersionNumbers($contentId);
     $fieldIdSet = array();
     $nameRows = $this->contentGateway->loadVersionedNameData(array_map(function ($versionNo) use($contentId) {
         return array('id' => $contentId, 'version' => $versionNo);
     }, $versionNumbers));
     foreach ($versionNumbers as $versionNo) {
         $contentRows = $this->contentGateway->load($contentId, $versionNo);
         $contentList = $this->contentMapper->extractContentFromRows($contentRows, $nameRows);
         $content = $contentList[0];
         $versionFieldIdSet = array();
         foreach ($content->fields as $field) {
             if ($field->fieldDefinitionId == $this->fieldDefinition->id) {
                 $fieldIdSet[$field->id] = true;
                 $versionFieldIdSet[$field->id] = true;
             }
         }
         // Delete from external storage with list of IDs per version
         $this->storageHandler->deleteFieldData($this->fieldDefinition->fieldType, $content->versionInfo, array_keys($versionFieldIdSet));
     }
     // Delete from internal storage -- field is always deleted from _all_ versions
     foreach (array_keys($fieldIdSet) as $fieldId) {
         $this->contentGateway->deleteField($fieldId);
     }
 }
コード例 #2
0
 /**
  * Applies the action to the given $content
  *
  * @param int $contentId
  */
 public function apply($contentId)
 {
     $versionNumbers = $this->contentGateway->listVersionNumbers($contentId);
     $languageCodeToFieldId = array();
     foreach ($versionNumbers as $versionNo) {
         $contentRows = $this->contentGateway->load($contentId, $versionNo);
         $contentList = $this->contentMapper->extractContentFromRows($contentRows);
         $content = $contentList[0];
         $languageCodeSet = array();
         // Each subsequent Content version can have additional language(s)
         foreach ($content->fields as $field) {
             $languageCode = $field->languageCode;
             // Add once for each language per version
             if (isset($languageCodeSet[$languageCode])) {
                 continue;
             }
             $languageCodeSet[$languageCode] = true;
             // Check if field was already inserted for current language code,
             // in that case we need to preserve its ID across versions
             if (isset($languageCodeToFieldId[$languageCode])) {
                 $fieldId = $languageCodeToFieldId[$languageCode];
             } else {
                 $fieldId = null;
             }
             $languageCodeToFieldId[$languageCode] = $this->insertField($content, $this->createField($fieldId, $versionNo, $languageCode));
         }
     }
 }
コード例 #3
0
ファイル: RemoveField.php プロジェクト: CG77/ezpublish-kernel
 /**
  * Applies the action to the given $content
  *
  * @param \eZ\Publish\SPI\Persistence\Content\ContentInfo $contentInfo
  *
  * @return void
  */
 public function apply(ContentInfo $contentInfo)
 {
     $fieldIdsToRemoveMap = array();
     $contentRows = $this->contentGateway->load($contentInfo->id, $contentInfo->currentVersionNo);
     $contentList = $this->contentMapper->extractContentFromRows($contentRows);
     $content = $contentList[0];
     foreach ($content->fields as $field) {
         if ($field->fieldDefinitionId == $this->fieldDefinition->id) {
             $this->contentGateway->deleteField($field->id);
             $fieldIdsToRemoveMap[$field->type][] = $field->id;
         }
     }
     foreach ($fieldIdsToRemoveMap as $fieldType => $ids) {
         $this->storageHandler->deleteFieldData($fieldType, $content->versionInfo, $ids);
     }
 }
コード例 #4
0
ファイル: Handler.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Finds content objects for the given query.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if Query criterion is not applicable to its target
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query $query
  * @param array $languageFilter - a map of language related filters specifying languages query will be performed on.
  *        Also used to define which field languages are loaded for the returned content.
  *        Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code>
  *                            useAlwaysAvailable defaults to true to avoid exceptions on missing translations
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findContent(Query $query, array $languageFilter = array())
 {
     if (!isset($languageFilter['languages'])) {
         $languageFilter['languages'] = array();
     }
     if (!isset($languageFilter['useAlwaysAvailable'])) {
         $languageFilter['useAlwaysAvailable'] = true;
     }
     $start = microtime(true);
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     $query->query = $query->query ?: new Criterion\MatchAll();
     if (count($query->facetBuilders)) {
         throw new NotImplementedException('Facets are not supported by the legacy search engine.');
     }
     // The legacy search does not know about scores, so that we just
     // combine the query with the filter
     $filter = new Criterion\LogicalAnd(array($query->query, $query->filter));
     $data = $this->gateway->find($filter, $query->offset, $query->limit, $query->sortClauses, $languageFilter, $query->performCount);
     $result = new SearchResult();
     $result->time = microtime(true) - $start;
     $result->totalCount = $data['count'];
     $contentInfoList = $this->contentMapper->extractContentInfoFromRows($data['rows'], '', 'main_tree_');
     foreach ($contentInfoList as $index => $contentInfo) {
         $searchHit = new SearchHit();
         $searchHit->valueObject = $contentInfo;
         $searchHit->matchedTranslation = $this->extractMatchedLanguage($data['rows'][$index]['language_mask'], $data['rows'][$index]['initial_language_id'], $languageFilter);
         $result->searchHits[] = $searchHit;
     }
     return $result;
 }
コード例 #5
0
 /**
  * Applies the action to the given $content
  *
  * @param \eZ\Publish\SPI\Persistence\Content\ContentInfo $contentInfo
  */
 public function apply(ContentInfo $contentInfo)
 {
     $languageCodeSet = array();
     $versionNumbers = $this->contentGateway->listVersionNumbers($contentInfo->id);
     $contentRows = $this->contentGateway->load($contentInfo->id, $contentInfo->currentVersionNo);
     $contentList = $this->contentMapper->extractContentFromRows($contentRows);
     $content = $contentList[0];
     foreach ($content->fields as $field) {
         if (isset($languageCodeSet[$field->languageCode])) {
             continue;
         }
         $languageCodeSet[$field->languageCode] = true;
         foreach ($versionNumbers as $versionNo) {
             $this->insertField($content, $this->createField($versionNo, $field->languageCode));
         }
     }
 }
コード例 #6
0
ファイル: TreeHandler.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Returns the versions for $contentId.
  *
  * @param int $contentId
  *
  * @return \eZ\Publish\SPI\Persistence\Content\VersionInfo[]
  */
 public function listVersions($contentId)
 {
     $rows = $this->contentGateway->listVersions($contentId);
     if (empty($rows)) {
         return array();
     }
     $idVersionPairs = array_map(function ($row) use($contentId) {
         return array('id' => $contentId, 'version' => $row['ezcontentobject_version_version']);
     }, $rows);
     $nameRows = $this->contentGateway->loadVersionedNameData($idVersionPairs);
     return $this->contentMapper->extractVersionInfoListFromRows($rows, $nameRows);
 }
コード例 #7
0
 /**
  * Updates a language copy of a non-translatable field.
  *
  * External data is being copied here as some FieldTypes require original field external data.
  * By default copying falls back to storing, it is upon external storage implementation to override
  * the behaviour as needed.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Field $field
  * @param \eZ\Publish\SPI\Persistence\Content\Field $updateField
  * @param \eZ\Publish\SPI\Persistence\Content\Field $originalField
  * @param \eZ\Publish\SPI\Persistence\Content $content
  */
 protected function updateCopiedField(Field $field, Field $updateField, Field $originalField, Content $content)
 {
     $field->versionNo = $content->versionInfo->versionNo;
     $field->value = clone $updateField->value;
     $this->contentGateway->updateField($field, $this->mapper->convertToStorageValue($field));
     // If the storage handler returns true, it means that $field value has been modified
     // So we need to update it in order to store those modifications
     // Field converter is called once again via the Mapper
     if ($this->storageHandler->copyFieldData($content->versionInfo, $field, $originalField) === true) {
         $this->contentGateway->updateField($field, $this->mapper->convertToStorageValue($field));
     }
 }
コード例 #8
0
ファイル: Handler.php プロジェクト: masev/ezpublish-kernel
 /**
  * Finds content objects for the given query.
  *
  * @todo define structs for the field filters
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if Query criterion is not applicable to its target
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query $query
  * @param array $fieldFilters - a map of filters for the returned fields.
  *        Currently supported: <code>array("languages" => array(<language1>,..))</code>.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findContent(Query $query, array $fieldFilters = array())
 {
     $start = microtime(true);
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     $query->query = $query->query ?: new Criterion\MatchAll();
     if (count($query->facetBuilders)) {
         throw new NotImplementedException("Facets are not supported by the legacy search engine.");
     }
     // The legacy search does not know about scores, so that we just
     // combine the query with the filter
     $filter = new Criterion\LogicalAnd(array($query->query, $query->filter));
     $data = $this->gateway->find($filter, $query->offset, $query->limit, $query->sortClauses, null);
     $result = new SearchResult();
     $result->time = microtime(true) - $start;
     $result->totalCount = $data['count'];
     foreach ($this->contentMapper->extractContentInfoFromRows($data['rows'], '', 'main_tree_') as $contentInfo) {
         $searchHit = new SearchHit();
         $searchHit->valueObject = $contentInfo;
         $result->searchHits[] = $searchHit;
     }
     return $result;
 }
コード例 #9
0
 /**
  * @covers eZ\Publish\Core\Persistence\Legacy\Content\Mapper::extractContentInfoFromRow
  * @dataProvider extractContentInfoFromRowProvider
  *
  * @param array $fixtures
  * @param string $prefix
  */
 public function testExtractContentInfoFromRow(array $fixtures, $prefix)
 {
     $contentInfoReference = $this->getContentExtractReference()->versionInfo->contentInfo;
     $mapper = new Mapper($this->getValueConverterRegistryMock(), $this->getLanguageHandler());
     self::assertEquals($contentInfoReference, $mapper->extractContentInfoFromRow($fixtures, $prefix));
 }
コード例 #10
0
ファイル: Handler.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Loads relations from $contentId. Optionally, loads only those with $type.
  *
  * Only loads relations against published versions.
  *
  * @param mixed $destinationContentId Destination Content ID
  * @param int|null $type {@see \eZ\Publish\API\Repository\Values\Content\Relation::COMMON,
  *                 \eZ\Publish\API\Repository\Values\Content\Relation::EMBED,
  *                 \eZ\Publish\API\Repository\Values\Content\Relation::LINK,
  *                 \eZ\Publish\API\Repository\Values\Content\Relation::FIELD}
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Relation[]
  */
 public function loadReverseRelations($destinationContentId, $type = null)
 {
     return $this->mapper->extractRelationsFromRows($this->contentGateway->loadReverseRelations($destinationContentId, $type));
 }
コード例 #11
0
 /**
  * Returns the versions for $contentId
  *
  * @param int $contentId
  *
  * @return \eZ\Publish\SPI\Persistence\Content\VersionInfo[]
  */
 public function listVersions($contentId)
 {
     return $this->contentMapper->extractVersionInfoListFromRows($this->contentGateway->listVersions($contentId));
 }