diff --git a/core/modules/migrate_drupal/config/schema/migrate_drupal.source.schema.yml b/core/modules/migrate_drupal/config/schema/migrate_drupal.source.schema.yml index 9fdf6d8..1b47e86 100644 --- a/core/modules/migrate_drupal/config/schema/migrate_drupal.source.schema.yml +++ b/core/modules/migrate_drupal/config/schema/migrate_drupal.source.schema.yml @@ -278,6 +278,10 @@ migrate.source.d6_user_picture_instance: type: migrate_entity_constant label: 'Constants' +migrate.source.d6_imagecache_presets: + type: migrate_source_sql + label: 'Drupal 6 ImageCache Presets' + migrate_entity_constant: type: mapping mapping: diff --git a/core/modules/migrate_drupal/migration_templates/d6_imagecache_presets.yml b/core/modules/migrate_drupal/migration_templates/d6_imagecache_presets.yml new file mode 100644 index 0000000..91e1201 --- /dev/null +++ b/core/modules/migrate_drupal/migration_templates/d6_imagecache_presets.yml @@ -0,0 +1,24 @@ +id: d6_imagecache_presets +label: Drupal 6 ImageCache Presets +migration_tags: + - Drupal 6 +source: + plugin: d6_imagecache_presets +process: + name: + - + plugin: machine_name + source: presetname + - + plugin: dedupe_entity + entity_type: image_style + field: name + length: 32 + label: presetname + effects: + plugin: d6_imagecache_actions + source: + - @plugin + - data +destination: + plugin: entity:image_style diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php new file mode 100644 index 0000000..f4244f7 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php @@ -0,0 +1,45 @@ +getDestinationProperty('effects')) { + $effects = $row->getDestinationProperty('effects'); + $row->setDestinationProperty('effects', NULL); + } + + $entity_ids = parent::import($row, $old_destination_id_values); + $style = $this->storage->load(reset($entity_ids)); + + foreach ($effects as $effect) { + $style->addImageEffect($effect); + } + + $style->save(); + + return $entity_ids; + } +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php new file mode 100644 index 0000000..4d0f197 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php @@ -0,0 +1,65 @@ +getSourceProperty('actions') as $action) { + switch($action['action']) { + case 'imagecache_resize': + $id = 'image_resize'; + break; + case 'imagecache_scale': + $id = 'image_scale'; + break; + case 'imagecache_scale_and_crop': + $id = 'image_scale_and_crop'; + break; + case 'imagecache_crop': + $id = 'image_crop'; + break; + case 'imagecache_desaturate': + $id = 'image_desaturate'; + break; + case 'imagecache_rotate': + $id = 'image_rotate'; + break; + case 'imagecache_deprecated_scale': + case 'imagecache_sharpen': + default: + $id = null; + break; + } + + if (!empty($id)) { + $effects[] = array( + 'id' => $id, + 'weight' => $action['weight'], + 'data' => $action['data'], + ); + } + } + + return $effects; + } +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ImageCachePreset.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ImageCachePreset.php new file mode 100644 index 0000000..8607ab7 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ImageCachePreset.php @@ -0,0 +1,79 @@ +select('imagecache_preset', 'icp') + ->fields('icp', array( + 'presetid', + 'presetname', + ) + ); + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = array( + 'presetid' => $this->t('Preset ID'), + 'presetname' => $this->t('Preset Name'), + ); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['presetid']['type'] = 'integer'; + return $ids; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $actions = array(); + $results = $this->database + ->select('imagecache_action', 'ica', array('fetch' => \PDO::FETCH_ASSOC)) + ->fields('ica', array( + 'actionid', + 'presetid', + 'weight', + 'action', + 'data',)) + ->condition('presetid', $row->getSourceProperty('presetid')) + ->execute(); + + foreach($results as $key => $result) { + $actions[$key] = $result; + $actions[$key]['data'] = unserialize($result['data']); + } + + $row->setSourceProperty('actions', $actions); + return parent::prepareRow($row); + } +}