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..6207dc6 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php @@ -0,0 +1,57 @@ +getDestinationProperty('effects')) { + $effects = $row->getDestinationProperty('effects'); + $row->setDestinationProperty('effects', NULL); + } + + $style = $this->getEntity($row, $old_destination_id_values); + + // Iterate the effects array so each effect plugin can be initialized. + // Catch any missing plugin exceptions. + foreach ($effects as $effect) { + try { + $style->addImageEffect($effect); + } + catch (PluginNotFoundException $e) { + throw new MigrateException($e->getMessage()); + } + } + + $style->save(); + + return array($style->id); + } +} 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..779bbfd --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php @@ -0,0 +1,37 @@ +getSourceProperty('actions') as $action) { + $effects[] = array( + 'id' => preg_replace('/^imagecache/', 'image', $action['action']), + '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..a405709 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ImageCachePreset.php @@ -0,0 +1,74 @@ +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->select('imagecache_action', 'ica') + ->fields('ica') + ->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); + } +} diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php new file mode 100644 index 0000000..55f3bef --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php @@ -0,0 +1,112 @@ +createTable("imagecache_action", array( + 'primary key' => array( + 'actionid', + ), + 'fields' => array( + 'actionid' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'length' => '10', + 'unsigned' => TRUE, + ), + 'presetid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'length' => '10', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'weight' => array( + 'type' => 'int', + 'not null' => TRUE, + 'length' => '11', + 'default' => '0', + ), + 'module' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '255', + ), + 'action' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '255', + ), + 'data' => array( + 'type' => 'text', + 'not null' => TRUE, + 'length' => 100, + ), + ), + 'mysql_character_set' => 'utf8', + )); + $this->database->insert("imagecache_action")->fields(array( + 'actionid', + 'presetid', + 'weight', + 'module', + 'action', + 'data', + )) + ->values(array( + 'actionid' => '2', + 'presetid' => '1', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_deprecated_scale', + 'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}', + ))->values(array( + 'actionid' => '3', + 'presetid' => '1', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_scale_and_crop', + 'data' => 'a:2:{s:5:"width";s:4:"100%";s:6:"height";s:4:"100%";}', + ))->values(array( + 'actionid' => '4', + 'presetid' => '2', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_crop', + 'data' => 'a:4:{s:5:"width";s:3:"555";s:6:"height";s:4:"5555";s:7:"xoffset";s:6:"center";s:7:"yoffset";s:6:"center";}', + ))->values(array( + 'actionid' => '5', + 'presetid' => '2', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_resize', + 'data' => 'a:2:{s:5:"width";s:3:"55%";s:6:"height";s:3:"55%";}', + ))->values(array( + 'actionid' => '6', + 'presetid' => '2', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_rotate', + 'data' => 'a:3:{s:7:"degrees";s:2:"55";s:6:"random";i:0;s:7:"bgcolor";s:0:"";}', + ))->execute(); + } + +} +#79a19aa7a4e9c76e439882490c8c9bdb diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecachePreset.php b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecachePreset.php new file mode 100644 index 0000000..154662c --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecachePreset.php @@ -0,0 +1,56 @@ +createTable("imagecache_preset", array( + 'primary key' => array( + 'presetid', + ), + 'fields' => array( + 'presetid' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'length' => '10', + 'unsigned' => TRUE, + ), + 'presetname' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '255', + ), + ), + 'mysql_character_set' => 'utf8', + )); + $this->database->insert("imagecache_preset")->fields(array( + 'presetid', + 'presetname', + )) + ->values(array( + 'presetid' => '1', + 'presetname' => 'slackjaw_boys', + ))->values(array( + 'presetid' => '2', + 'presetname' => 'big_blue_cheese', + ))->execute(); + } + +} +#b2102d82ad5b3d8be026fe23cea75674 diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index b277e3b..8ab7f92 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -95,6 +95,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_file', 'd6_filter_format', 'd6_forum_settings', + 'd6_imagecache_presets', 'd6_locale_settings', 'd6_menu_settings', 'd6_menu', @@ -227,6 +228,8 @@ protected function getDumps() { $tests_path . '/Files.php', $tests_path . '/FilterFormats.php', $tests_path . '/Filters.php', + $tests_path . '/ImagecacheAction.php', + $tests_path . '/ImagecachePreset.php', $tests_path . '/MenuCustom.php', $tests_path . '/MenuLinks.php', $tests_path . '/Node.php', @@ -285,6 +288,7 @@ protected function getTestClassesList() { __NAMESPACE__ . '\MigrateFileTest', __NAMESPACE__ . '\MigrateFilterFormatTest', __NAMESPACE__ . '\MigrateForumConfigsTest', + __NAMESPACE__ . '\MigrateImageCacheTest', __NAMESPACE__ . '\MigrateLocaleConfigsTest', __NAMESPACE__ . '\MigrateMenuConfigsTest', __NAMESPACE__ . '\MigrateMenuLinkTest', diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php new file mode 100644 index 0000000..7f9ae90 --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php @@ -0,0 +1,75 @@ +installConfig(array('image')); + $migration = entity_load('migration', 'd6_imagecache_presets'); + + $dumps = array( + $this->getDumpDirectory() . '/ImagecachePreset.php', + $this->getDumpDirectory() . '/ImagecacheAction.php', + ); + + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + public function testImageCache() { + $migration = entity_load('migration', 'd6_imagecache_presets'); + $style = ImageStyle::load('big_blue_cheese'); + + //check for failed style creation due to missing plugin + $this->assertNull(ImageStyle::load('slackjaw_boys')); + + //check basic Style info + $this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly'); + $this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly'); + + //check crop effect + $image_crop = $style->getEffect('image_crop')->getConfiguration(); + $this->assertIdentical('555',$image_crop['data']['width'], 'ImageEffect crop Width set correctly'); + $this->assertIdentical('5555', $image_crop['data']['height'], 'ImageEffect crop Height set correctly'); + $this->assertIdentical('center-center', $image_crop['data']['anchor'], 'ImageEffect crop Anchor set correctly'); + + //check resize effect + $image_resize = $style->getEffect('image_resize')->getConfiguration(); + $this->assertIdentical('55', $image_resize['data']['width'], 'ImageEffect resize Width set correctly'); + $this->assertIdentical('55', $image_resize['data']['height'], 'ImageEffect resize Height set correctly'); + + //check rotate effect + $image_rotate = $style->getEffect('image_rotate')->getConfiguration(); + $this->assertIdentical('55', $image_rotate['data']['degrees'], 'ImageEffect rotate Degrees set correctly'); + $this->assertIdentical('0', $image_rotate['data']['random'], 'ImageEffect rotate Random set correctly'); + $this->assertIdentical('0', $image_resize['data']['bgcolor'], 'ImageEffect rotate color set correctly'); + } +}