/** * Determines the necessary update actions * * @param \eZ\Publish\SPI\Persistence\Content\Type $fromType * @param \eZ\Publish\SPI\Persistence\Content\Type $toType * * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\ContentUpdater\Action[] */ public function determineActions(Type $fromType, Type $toType) { $actions = array(); foreach ($fromType->fieldDefinitions as $fieldDef) { if (!$this->hasFieldDefinition($toType, $fieldDef)) { $actions[] = new ContentUpdater\Action\RemoveField($this->contentGateway, $fieldDef, $this->storageHandler); } } foreach ($toType->fieldDefinitions as $fieldDef) { if (!$this->hasFieldDefinition($fromType, $fieldDef)) { $actions[] = new ContentUpdater\Action\AddField($this->contentGateway, $fieldDef, $this->converterRegistry->getConverter($fieldDef->fieldType), $this->storageHandler); } } return $actions; }
/** * Returns relevant field information for the specified field * * The returned information is returned as an array of the attribute * identifier and the sort column, which should be used. * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given $fieldIdentifier. * @throws \RuntimeException if no converter is found * * @caching * @param string $fieldIdentifier * * @return array */ protected function getFieldsInformation( $fieldIdentifier ) { $fieldMapArray = array(); $fieldMap = $this->contentTypeHandler->getSearchableFieldMap(); foreach ( $fieldMap as $contentTypeIdentifier => $fieldIdentifierMap ) { // First check if field exists in the current ContentType, there is nothing to do if it doesn't if ( !isset( $fieldIdentifierMap[$fieldIdentifier] ) ) { continue; } $fieldTypeIdentifier = $fieldIdentifierMap[$fieldIdentifier]["field_type_identifier"]; $fieldMapArray[$fieldTypeIdentifier]['ids'][] = $fieldIdentifierMap[$fieldIdentifier]["field_definition_id"]; if ( !isset( $fieldMapArray[$fieldTypeIdentifier]['column'] ) ) { $fieldMapArray[$fieldTypeIdentifier]['column'] = $this->fieldConverterRegistry->getConverter( $fieldTypeIdentifier )->getIndexColumn(); } } if ( empty( $fieldMapArray ) ) { throw new InvalidArgumentException( "\$criterion->target", "No searchable fields found for the given criterion target '{$fieldIdentifier}'." ); } return $fieldMapArray; }
/** * Returns relevant field information for the specified field * * The returned information is returned as an array of the attribute * identifier and the sort column, which should be used. * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given $fieldIdentifier. * * @caching * @param string $fieldIdentifier * * @return array */ protected function getFieldsInformation($fieldIdentifier) { $query = $this->dbHandler->createSelectQuery(); $query->select($this->dbHandler->quoteColumn('id', 'ezcontentclass_attribute'), $this->dbHandler->quoteColumn('data_type_string', 'ezcontentclass_attribute'))->from($this->dbHandler->quoteTable('ezcontentclass_attribute'))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('identifier', 'ezcontentclass_attribute'), $query->bindValue($fieldIdentifier)), $query->expr->eq($this->dbHandler->quoteColumn('is_searchable', 'ezcontentclass_attribute'), $query->bindValue(1, null, \PDO::PARAM_INT)))); $statement = $query->prepare(); $statement->execute(); if (!($rows = $statement->fetchAll(\PDO::FETCH_ASSOC))) { throw new InvalidArgumentException("\$criterion->target", "No searchable fields found for the given criterion target '{$fieldIdentifier}'."); } $fieldMapArray = array(); foreach ($rows as $row) { if (!isset($fieldMapArray[$row['data_type_string']])) { $converter = $this->fieldConverterRegistry->getConverter($row['data_type_string']); if (!$converter instanceof Converter) { throw new RuntimeException("getConverter({$row['data_type_string']}) did not return a converter, got: " . gettype($converter)); } $fieldMapArray[$row['data_type_string']] = array('ids' => array(), 'column' => $converter->getIndexColumn()); } $fieldMapArray[$row['data_type_string']]['ids'][] = $row['id']; } return $fieldMapArray; }
/** * Extracts a FieldValue of $type from $row. * * @param array $row * @param string $type * * @return \eZ\Publish\SPI\Persistence\Content\FieldValue * * @throws \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound * if the necessary converter for $type could not be found. */ protected function extractFieldValueFromRow(array $row, $type) { $storageValue = new StorageFieldValue(); // Nullable field $storageValue->dataFloat = isset($row['ezcontentobject_attribute_data_float']) ? (double) $row['ezcontentobject_attribute_data_float'] : null; // Nullable field $storageValue->dataInt = isset($row['ezcontentobject_attribute_data_int']) ? (int) $row['ezcontentobject_attribute_data_int'] : null; $storageValue->dataText = $row['ezcontentobject_attribute_data_text']; // Not nullable field $storageValue->sortKeyInt = (int) $row['ezcontentobject_attribute_sort_key_int']; $storageValue->sortKeyString = $row['ezcontentobject_attribute_sort_key_string']; $fieldValue = new FieldValue(); $converter = $this->converterRegistry->getConverter($type); $converter->toFieldValue($storageValue, $fieldValue); return $fieldValue; }
/** * Maps a FieldDefinition from the given $storageFieldDef * * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageFieldDef * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef * * @return void */ public function toFieldDefinition(StorageFieldDefinition $storageFieldDef, FieldDefinition $fieldDef) { $converter = $this->converterRegistry->getConverter($fieldDef->fieldType); $converter->toFieldDefinition($storageFieldDef, $fieldDef); }
/** * @return void * @covers eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::getConverter * @covers eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound * @expectedException eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound */ public function testGetNotFound() { $registry = new Registry(array()); $registry->getConverter('not-found'); }