eZ\Publish\Core\Persistence\Legacy\Content\Mapper::extractContentFromRows PHP Method

extractContentFromRows() public method

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
return eZ\Publish\SPI\Persistence\Content[]
    public function extractContentFromRows(array $rows, array $nameRows)
    {
        $versionedNameData = array();
        foreach ($nameRows as $row) {
            $contentId = (int) $row['ezcontentobject_name_contentobject_id'];
            $versionNo = (int) $row['ezcontentobject_name_content_version'];
            $versionedNameData[$contentId][$versionNo][$row['ezcontentobject_name_content_translation']] = $row['ezcontentobject_name_name'];
        }
        $contentInfos = array();
        $versionInfos = array();
        $fields = array();
        foreach ($rows as $row) {
            $contentId = (int) $row['ezcontentobject_id'];
            if (!isset($contentInfos[$contentId])) {
                $contentInfos[$contentId] = $this->extractContentInfoFromRow($row, 'ezcontentobject_');
            }
            if (!isset($versionInfos[$contentId])) {
                $versionInfos[$contentId] = array();
            }
            $versionId = (int) $row['ezcontentobject_version_id'];
            if (!isset($versionInfos[$contentId][$versionId])) {
                $versionInfos[$contentId][$versionId] = $this->extractVersionInfoFromRow($row);
            }
            $fieldId = (int) $row['ezcontentobject_attribute_id'];
            if (!isset($fields[$contentId][$versionId][$fieldId])) {
                $fields[$contentId][$versionId][$fieldId] = $this->extractFieldFromRow($row);
            }
        }
        $results = array();
        foreach ($contentInfos as $contentId => $contentInfo) {
            foreach ($versionInfos[$contentId] as $versionId => $versionInfo) {
                // Fallback to just main language name if versioned name data is missing
                if (isset($versionedNameData[$contentId][$versionInfo->versionNo])) {
                    $names = $versionedNameData[$contentId][$versionInfo->versionNo];
                } else {
                    $names = [$contentInfo->mainLanguageCode => $contentInfo->name];
                }
                $content = new Content();
                $content->versionInfo = $versionInfo;
                $content->versionInfo->names = $names;
                $content->versionInfo->contentInfo = $contentInfo;
                $content->fields = array_values($fields[$contentId][$versionId]);
                $results[] = $content;
            }
        }
        return $results;
    }

Usage Example

コード例 #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);
     }
 }
All Usage Examples Of eZ\Publish\Core\Persistence\Legacy\Content\Mapper::extractContentFromRows