Expects database rows to be indexed by keys of the format
"$tableName_$columnName"
public extractContentFromRows ( array $rows, array $nameRows ) : eZ\Publish\SPI\Persistence\Content[] | ||
$rows | array | |
$nameRows | array | |
Результат | eZ\Publish\SPI\Persistence\Content[] |
/** * 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); } }
/** * 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)); } } }
/** * 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); } }
/** * 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)); } } }
/** * Returns the raw data of a content object identified by $id, in a struct. * * A version to load must be specified. If you want to load the current * version of a content object use SearchHandler::findSingle() with the * ContentId criterion. * * Optionally a translation filter may be specified. If specified only the * translations with the listed language codes will be retrieved. If not, * all translations will be retrieved. * * @param int|string $id * @param int|string $version * @param string[] $translations * * @return \eZ\Publish\SPI\Persistence\Content Content value object */ public function load($id, $version, array $translations = null) { $rows = $this->contentGateway->load($id, $version, $translations); if (empty($rows)) { throw new NotFound('content', "contentId: {$id}, versionNo: {$version}"); } $contentObjects = $this->mapper->extractContentFromRows($rows, $this->contentGateway->loadVersionedNameData(array(array('id' => $id, 'version' => $version)))); $content = $contentObjects[0]; $this->fieldHandler->loadExternalFieldData($content); return $content; }
/** * 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->extractContentFromRows($data['rows']) as $content) { $this->fieldHandler->loadExternalFieldData($content); $searchHit = new SearchHit(); $searchHit->valueObject = $content; $result->searchHits[] = $searchHit; } return $result; }
/** * @covers eZ\Publish\Core\Persistence\Legacy\Content\Mapper::extractContentFromRows */ public function testExtractContentFromRowsMultipleVersions() { $convMock = $this->getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\FieldValue\\Converter'); $convMock->expects($this->any())->method('toFieldValue')->will($this->returnValue(new FieldValue())); $reg = new Registry(array('ezstring' => $convMock, 'ezxmltext' => $convMock, 'ezdatetime' => $convMock)); $rowsFixture = $this->getMultipleVersionsExtractFixture(); $nameRowsFixture = $this->getMultipleVersionsNamesExtractFixture(); $mapper = new Mapper($reg, $this->getLanguageHandler()); $result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture); $this->assertEquals(2, count($result)); $this->assertEquals(11, $result[0]->versionInfo->contentInfo->id); $this->assertEquals(11, $result[1]->versionInfo->contentInfo->id); $this->assertEquals(1, $result[0]->versionInfo->versionNo); $this->assertEquals(2, $result[1]->versionInfo->versionNo); }