diff --git a/Core/ComplexField/EzBinaryFile.php b/Core/ComplexField/EzBinaryFile.php index b2050ee9..5560fd9e 100644 --- a/Core/ComplexField/EzBinaryFile.php +++ b/Core/ComplexField/EzBinaryFile.php @@ -3,10 +3,17 @@ namespace Kaliop\eZMigrationBundle\Core\ComplexField; use eZ\Publish\Core\FieldType\BinaryFile\Value as BinaryFileValue; -use Kaliop\eZMigrationBundle\API\FieldValueImporterInterface; +use Kaliop\eZMigrationBundle\API\FieldValueConverterInterface; -class EzBinaryFile extends AbstractComplexField implements FieldValueImporterInterface +class EzBinaryFile extends AbstractComplexField implements FieldValueConverterInterface { + protected $legacyRootDir; + + public function __construct($legacyRootDir) + { + $this->legacyRootDir = $legacyRootDir; + } + /** * @param array|string $fieldValue The path to the file or an array with 'path' key * @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration @@ -48,4 +55,20 @@ public function hashToFieldValue($fieldValue, array $context = array()) ) ); } + + /** + * @param \eZ\Publish\Core\FieldType\BinaryFile\Value $fieldValue + * @param array $context + * @return array + * + * @todo check out if this works in ezplatform + */ + public function fieldValueToHash($fieldValue, array $context = array()) + { + return array( + 'path' => realpath($this->legacyRootDir) . $fieldValue->uri, + 'filename'=> $fieldValue->fileName, + 'mimeType' => $fieldValue->mimeType + ); + } } diff --git a/Core/ComplexField/EzDateAndTime.php b/Core/ComplexField/EzDateAndTime.php index 1f8416ea..9df651a8 100644 --- a/Core/ComplexField/EzDateAndTime.php +++ b/Core/ComplexField/EzDateAndTime.php @@ -39,7 +39,12 @@ public function fieldSettingsToHash($settingsValue, array $context = array()) public function hashToFieldSettings($settingsHash, array $context = array()) { if (is_array($settingsHash) && isset($settingsHash['dateInterval']) && is_string($settingsHash['dateInterval'])) { - $settingsHash['dateInterval'] = \DateInterval::createFromDateString($settingsHash['dateInterval']); + // ISO-8601 format, loose matching because I am lazy + if (preg_match('/^P[0-9YMDWTHS]+$/', $settingsHash['dateInterval'])) { + $settingsHash['dateInterval'] = new \DateInterval($settingsHash['dateInterval']); + } else { + $settingsHash['dateInterval'] = \DateInterval::createFromDateString($settingsHash['dateInterval']); + } } return $settingsHash; } diff --git a/Core/ComplexField/EzImage.php b/Core/ComplexField/EzImage.php index 63de3e26..80af063a 100644 --- a/Core/ComplexField/EzImage.php +++ b/Core/ComplexField/EzImage.php @@ -3,10 +3,17 @@ namespace Kaliop\eZMigrationBundle\Core\ComplexField; use eZ\Publish\Core\FieldType\Image\Value as ImageValue; -use Kaliop\eZMigrationBundle\API\FieldValueImporterInterface; +use Kaliop\eZMigrationBundle\API\FieldValueConverterInterface; -class EzImage extends AbstractComplexField implements FieldValueImporterInterface +class EzImage extends AbstractComplexField implements FieldValueConverterInterface { + protected $legacyRootDir; + + public function __construct($legacyRootDir) + { + $this->legacyRootDir = $legacyRootDir; + } + /** * Creates a value object to use as the field value when setting an image field type. * @@ -50,4 +57,20 @@ public function hashToFieldValue($fieldValue, array $context = array()) ) ); } + + /** + * @param \eZ\Publish\Core\FieldType\Image\Value $fieldValue + * @param array $context + * @return array + * + * @todo check out if this works in ezplatform + */ + public function fieldValueToHash($fieldValue, array $context = array()) + { + return array( + 'path' => realpath($this->legacyRootDir) . $fieldValue->uri, + 'filename'=> $fieldValue->fileName, + 'alternativeText' => $fieldValue->alternativeText + ); + } } diff --git a/Core/ComplexField/EzXmlText.php b/Core/ComplexField/EzXmlText.php index 9ef16172..460aa11a 100644 --- a/Core/ComplexField/EzXmlText.php +++ b/Core/ComplexField/EzXmlText.php @@ -28,6 +28,9 @@ public function hashToFieldValue($fieldValue, array $context = array()) { if (is_string($fieldValue)) { $xmlText = $fieldValue; + } else if (is_array($fieldValue) && isset($fieldValue['xml'])) { + // native export format from eZ + $xmlText = $fieldValue['xml']; } else { $xmlText = $fieldValue['content']; } @@ -55,6 +58,11 @@ public function fieldSettingsToHash($settingsValue, array $context = array()) { // work around https://jira.ez.no/browse/EZP-26916 if (is_array($settingsValue) && isset($settingsValue['tagPreset'])) { + /// @todo this conversion should be based on the value of TagPresets ini legacy setting in ezxml.ini, + /// keeping in mind that at migration execution time only values 0 and 1 are supported anyway... + if ($settingsValue['tagPreset'] == 'mini') { + $settingsValue['tagPreset'] = 1; + } $settingsValue['tagPreset'] = (integer)$settingsValue['tagPreset']; } return $settingsValue; diff --git a/Core/Executor/ContentManager.php b/Core/Executor/ContentManager.php index 44e70ed7..93152af7 100644 --- a/Core/Executor/ContentManager.php +++ b/Core/Executor/ContentManager.php @@ -567,10 +567,11 @@ public function generateMigration(array $matchCondition, $mode) if ($mode != 'delete') { $attributes = array(); - foreach ($content->getFieldsByLanguage($this->getLanguageCode()) as $field) { - $fieldDefinition = $contentType->getFieldDefinition($field->fieldDefIdentifier); - $fieldType = $fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier); - $attributes[$field->fieldDefIdentifier] = $fieldType->toHash($field->value); + foreach ($content->getFieldsByLanguage($this->getLanguageCode()) as $fieldIdentifier => $field) { + $fieldDefinition = $contentType->getFieldDefinition($fieldIdentifier); + $attributes[$field->fieldDefIdentifier] = $this->complexFieldManager->fieldValueToHash( + $fieldDefinition->fieldTypeIdentifier, $contentType->identifier, $field->value + ); } $contentData = array_merge( diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1df4ff38..73272d9d 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -348,6 +348,8 @@ services: ez_migration_bundle.complex_field.ezbinaryfile: parent: ez_migration_bundle.complex_field class: '%ez_migration_bundle.complex_field.ezbinaryfile.class%' + arguments: + - "%ezpublish_legacy.root_dir%" tags: - { name: ez_migration_bundle.complex_field, fieldtype: ezbinaryfile, priority: 0 } @@ -372,6 +374,8 @@ services: ez_migration_bundle.complex_field.ezimage: parent: ez_migration_bundle.complex_field class: '%ez_migration_bundle.complex_field.ezimage.class%' + arguments: + - "%ezpublish_legacy.root_dir%" tags: - { name: ez_migration_bundle.complex_field, fieldtype: ezimage, priority: 0 } diff --git a/Resources/doc/DSL/ManageContent.yml b/Resources/doc/DSL/ManageContent.yml index 590a6d12..f7ee15ec 100644 --- a/Resources/doc/DSL/ManageContent.yml +++ b/Resources/doc/DSL/ManageContent.yml @@ -29,12 +29,12 @@ lines, but new line is not preserved on parsing # ezimage/ezbinaryfile file attribute example attribute5: - path: 'path/to/image' # Relative path from MigrationsVersions/images/ or MigrationsVersions/files/ + path: 'path/to/image' # Relative path from MigrationsVersions/images/ or MigrationsVersions/files/, or absolute path alt_text: xyz # Optional, only used for images filename: abc # Optional, taken from the actual file if not specified mime_type: def # Optional. For ezbinaryfile only. If not specified, the actual file is analyzed using the php function mime_content_type() # ezimage/ezbinaryfile file attribute example, using simplified form - attribute5b: 'path/to/image' + attribute5b: '/path/to/image' # ezxmltext, showing an example of using references attribute6: '
' # Adding values to an ezauthor field