View
136
Download
2
Category
Preview:
Citation preview
Migration from Drupal 6 to Drupal 8My first Drupal 8 migration
Created by / Drupal developerIvan Abramenko CimpleO
ceservices.com
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
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.
Drupal 8.2.x migrationMigrate Drupal UI in core!
Works, but not perfect.
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!
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 migrateimport migration_name drush migraterollback migration_name
Prepare migrations to import drush migrateupgrade legacydburl=mysql://user:password@localhost:3306/db legacydbprefix=drup_ legacyroot=http://www.ceservices.com configureonly
Drupal Upgrade module:
Drupal UpgradeSuccessfully migrated:
User rolesUsersNode types (needed static map)
Failed with:Nodes
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
Process pipeline
Process pipelinehttps://www.drupal.org/node/2129651
Plugins in Migrate UI:
static mapmigrationexplodeiteratorcallbackconcatdedupe_entitydedupebasedefault_valueextractattenmachine_nameskip_on_emptyskip_row_if_not_set
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"
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"
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 ...
Custom migrations are better than MigrateUpgrade
Custom migrationsNodesTaxonomyNodewords, Page Title to Metatag
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 ...
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
Source => Destination
source: plugin: ceservices_blog destination: plugin: entity:node
Source pluginCustom plugin or d6_node?
Our choice is custom one. Extend DrupalSqlBase class, notNode class for Drupal 6.
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"
Why did we use DrupalSqlBase instead ofSourcePluginBase or SqlBase?
Blog source plugin's methods
query()public function query() $query = $this>select('node', 'n') >condition('n.type', 'blog') >fields('n'); $query>orderBy('nid'); return $query;
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;
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)
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);
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';
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
We decided to use old nid/vid values:
process: nid: nid vid: vid
Be sure you deleted all content beforemigration!
Use batch API for any problems aftermigration
Nodewords, Page Title:
https://www.drupal.org/node/2052441
https://www.drupal.org/node/2563649
Thank you! And successful migrations!Migration from Drupal 6 to Drupal 8
My first Drupal 8 migrationCreated by / Drupal developerIvan Abramenko CimpleO
levmyshkin89@gmail.com
Recommended