36
Migration from Drupal 6 to Drupal 8 My first Drupal 8 migration Created by / Drupal developer Ivan Abramenko CimpleO

Migrate drupal 6 to drupal 8. Абраменко Иван

Embed Size (px)

Citation preview

Page 1: Migrate drupal 6 to drupal 8.  Абраменко Иван

Migration from Drupal 6 to Drupal 8My first Drupal 8 migration

Created by / Drupal developerIvan Abramenko CimpleO

Page 2: Migrate drupal 6 to drupal 8.  Абраменко Иван

ceservices.com

Page 3: Migrate drupal 6 to drupal 8.  Абраменко Иван

Drupal 8.0.xMigrate Upgrade / Drupal Upgrade

https://www.drupal.org/project/migrate_upgrade

Drupal Upgrade - Drupal 8.1.x

Migrate Drupal UI - Drupal 8.2.x

Page 4: Migrate drupal 6 to drupal 8.  Абраменко Иван

Drupal 8.1.x migrationMigrate UI didn't work for Drupal 8.1.x and above

https://www.drupal.org/project/migrate_ui

Migrations are core are now plugins, not cong entities.

https://www.drupal.org/node/2677198https://www.drupal.org/node/2625696

Try to use Migrate Drupal UI core module for Drupal 8.2.xand above.

Page 5: Migrate drupal 6 to drupal 8.  Абраменко Иван

Drupal 8.2.x migrationMigrate Drupal UI in core!

Works, but not perfect.

Page 6: Migrate drupal 6 to drupal 8.  Абраменко Иван

Drupal 8.0.x migrationDrupal 8.0.x => Drupal 8.1.x => Drupal 8.2.x

Uninstall drupal migrate modules after migration and beforeupdate to 8.1.x!

Page 7: Migrate drupal 6 to drupal 8.  Абраменко Иван

Why should use migrate module?Migrate mapImport/RollbackStub content

Migrate import (drush support)With Migrate Tools module

https://www.drupal.org/project/migrate_tools

drush migrate­import migration_name drush migrate­rollback migration_name

Page 8: Migrate drupal 6 to drupal 8.  Абраменко Иван

Prepare migrations to import drush migrate­upgrade ­­legacy­db­url=mysql://user:password@localhost:3306/db ­­legacy­db­prefix=drup_ ­­legacy­root=http://www.ceservices.com ­­configure­only

Page 9: Migrate drupal 6 to drupal 8.  Абраменко Иван

Drupal Upgrade module:

Page 10: Migrate drupal 6 to drupal 8.  Абраменко Иван

Drupal UpgradeSuccessfully migrated:

User rolesUsersNode types (needed static map)

Failed with:Nodes

Page 11: Migrate drupal 6 to drupal 8.  Абраменко Иван

Node types (needed static map)blog_entry ­> blog_post

lp ­> landing_page

2 ways to resolve it:Add static map for migration .yml leAdd custom plugin

Page 12: Migrate drupal 6 to drupal 8.  Абраменко Иван

Process pipeline

Page 13: Migrate drupal 6 to drupal 8.  Абраменко Иван

Process pipelinehttps://www.drupal.org/node/2129651

Plugins in Migrate UI:

Page 14: Migrate drupal 6 to drupal 8.  Абраменко Иван

static mapmigrationexplodeiteratorcallbackconcatdedupe_entitydedupebasedefault_valueextractattenmachine_nameskip_on_emptyskip_row_if_not_set

Page 15: Migrate drupal 6 to drupal 8.  Абраменко Иван

Custom plugins/modules/ceservices_migrate/src/Plugin/migrate/process/CeservicesFieldsType.php

<?php /** * @file * Contains \Drupal\ceservices_migrate\Plugin\migrate\process\CeservicesFieldsType.*/

namespace Drupal\ceservices_migrate\Plugin\migrate\process;

use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row;

/** * This plugin replaces old node_types with new. * * @MigrateProcessPlugin( * id = "ceservices_fields_type"

Page 16: Migrate drupal 6 to drupal 8.  Абраменко Иван

Custom plugins/modules/ceservices_migrate/src/Plugin/migrate/process/CeservicesNodeTypes.php

<?php /** * @file * Contains \Drupal\ceservices_migrate\Plugin\migrate\process\CeservicesNodeTypes.*/

namespace Drupal\ceservices_migrate\Plugin\migrate\process;

use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row;

/** * This plugin replaces old node_types with new. * * @MigrateProcessPlugin( * id = "ceservices_node_types"

Page 17: Migrate drupal 6 to drupal 8.  Абраменко Иван

UI doesn't work as you wanthttps://www.drupal.org/node/2708967

Page 18: Migrate drupal 6 to drupal 8.  Абраменко Иван

UI doesn't work as you wanthttps://www.drupal.org/node/2708967

migrate.migration.d6_node_type.yml

... process: type: plugin: static_map source: type map: blog_entry: blog ...

Page 19: Migrate drupal 6 to drupal 8.  Абраменко Иван

Custom migrations are better than MigrateUpgrade

Page 20: Migrate drupal 6 to drupal 8.  Абраменко Иван

Custom migrationsNodesTaxonomyNodewords, Page Title to Metatag

Page 21: Migrate drupal 6 to drupal 8.  Абраменко Иван

Nodes migrationYML-le for each content type:

/modules/ceservices_migrate/cong/install/

migrate.migration.ceservices_blog.yml migrate.migration.ceservices_book.yml migrate.migration.ceservices_page.yml migrate.migration.ceservices_story.yml ...

Page 22: Migrate drupal 6 to drupal 8.  Абраменко Иван

migrate.migration.ceservices_blog.yml:

id: ceservices_blog label: Blog nodes migration from Drupal 6 dependencies: enforced: module: ­ ceservices_migrate source: plugin: ceservices_blog destination: plugin: entity:node process: nid: nid vid: vid type: type langcode: plugin: static_map bypass: true

Page 23: Migrate drupal 6 to drupal 8.  Абраменко Иван

Source => Destination

source: plugin: ceservices_blog destination: plugin: entity:node

Page 24: Migrate drupal 6 to drupal 8.  Абраменко Иван

Source pluginCustom plugin or d6_node?

Our choice is custom one. Extend DrupalSqlBase class, notNode class for Drupal 6.

Page 25: Migrate drupal 6 to drupal 8.  Абраменко Иван

Blog source plugin/modules/ceservices_migrate/src/Plugin/migrate/source/CeservicesBlog.php

<?php

/** * @file * Contains \Drupal\ceservices_migrate\Plugin\migrate\source\CeservicesBlog.*/

namespace Drupal\ceservices_migrate\Plugin\migrate\source;

use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

/** * Drupal 6 Blog node source plugin * * @MigrateSource( * id = "ceservices_blog"

Page 26: Migrate drupal 6 to drupal 8.  Абраменко Иван

Why did we use DrupalSqlBase instead ofSourcePluginBase or SqlBase?

Page 27: Migrate drupal 6 to drupal 8.  Абраменко Иван

Blog source plugin's methods

Page 28: Migrate drupal 6 to drupal 8.  Абраменко Иван

query()public function query() $query = $this­>select('node', 'n') ­>condition('n.type', 'blog') ­>fields('n'); $query­>orderBy('nid'); return $query;

Page 29: Migrate drupal 6 to drupal 8.  Абраменко Иван

fields()public function fields() $fields = $this­>baseFields(); $fields['body/format'] = $this­>t('Format of body'); $fields['body/value'] = $this­>t('Full text of body'); $fields['body/summary'] = $this­>t('Summary of body'); $fields['field_related_testimonial'] = $this­>t('Related testimonial'); $fields['field_related_resources'] = $this­>t('Related Resources'); $fields['field_related_blog'] = $this­>t('Related Blog Posts'); $fields['field_taxonomy'] = $this­>t('Taxonomy'); return $fields;

Page 30: Migrate drupal 6 to drupal 8.  Абраменко Иван

prepareRow(Row $row)public function prepareRow(Row $row) $nid = $row­>getSourceProperty('nid');

// body (compound field with value, summary, and format) $result = $this­>getDatabase()­>query(' SELECT * FROM node_revisions n INNER JOIN node node ON n.vid = node.vid LEFT JOIN content_type_blog t ON t.vid = n.vid LEFT JOIN content_field_related_testimonial r ON r.vid = n.vid WHERE n.nid = :nid LIMIT 0, 1 ', array(':nid' => $nid)); foreach ($result as $record)

Page 31: Migrate drupal 6 to drupal 8.  Абраменко Иван

Single value fields:$row­>setSourceProperty('body_value', $record­>body);

Multiple values fields:// Multiple fields. $result = $this­>getDatabase()­>query(' SELECT * FROM content_field_related_resources r INNER JOIN node node ON r.vid = node.vid WHERE r.nid = :nid ', array(':nid' => $nid)); $related_resources = []; foreach ($result as $record) if (!empty($record­>field_related_resources_nid)) $related_resources[] = $record­>field_related_resources_nid; $row­>setSourceProperty('field_related_resources', $related_resources);

Page 32: Migrate drupal 6 to drupal 8.  Абраменко Иван

And few methods to describe entity:public function getIds() $ids['nid']['type'] = 'integer'; $ids['nid']['alias'] = 'n'; return $ids;

public function bundleMigrationRequired() return FALSE;

public function entityTypeId() return 'node';

Page 33: Migrate drupal 6 to drupal 8.  Абраменко Иван

Process — map between destination => source

process: nid: nid vid: vid type: type langcode: plugin: static_map bypass: true source: language map: und: en en: en title: title uid: uid status: status created: created changed: changed promote: promote

Page 34: Migrate drupal 6 to drupal 8.  Абраменко Иван

We decided to use old nid/vid values:

process: nid: nid vid: vid

Be sure you deleted all content beforemigration!

Page 35: Migrate drupal 6 to drupal 8.  Абраменко Иван

Use batch API for any problems aftermigration

Nodewords, Page Title:

https://www.drupal.org/node/2052441

https://www.drupal.org/node/2563649

Page 36: Migrate drupal 6 to drupal 8.  Абраменко Иван

Thank you! And successful migrations!Migration from Drupal 6 to Drupal 8

My first Drupal 8 migrationCreated by / Drupal developerIvan Abramenko CimpleO

[email protected]