SlideShare a Scribd company logo
MIGRATING
DATA TO
DRUPAL 8
Nacho Sánchez
CTO@
about.me
@isholgueras
nacho@letshackity.com
drupal.org/u/isholgueras
http://www.isholgueras.com
STEPS
1. Requirements
2. Anatomy of a migration
3. Migration Framework
4. D2D migrations
1.
REQUIREMENTS
Two new modules
▸ Migrate
Handles migrations. Framework.
▸ Migrate Drupal
Contains migrations from D6 & D7.
Migrate in core!
1.
REQUIREMENTS
But… how can I execute that
migration.
UI is not ready?
No Drush command?
UI for D2D migration in progress: https://www.drupal.org/node/2257723
Migrate in core!
1.
REQUIREMENTS
So...
Contrib!
1.
REQUIREMENTS
▸ Drupal 8.0.x
▸ Drush 8
▸ Migrate tools (contrib)
▸ Migrate Plus (contrib)
Needed
1.
REQUIREMENTS
Useful
2.
ANATOMY OF A
MIGRATION
2.
ANATOMY OF
A MIGRATION
DESTINATIONSOURCE
PROCESS
PROCESS
PROCESS
Workflow
PLUGINS
PHP Files
Core files or custom files
Types:
- Source
- Process
- Destination
- Builder
- ID Map
DEFINITIONS
Yaml Files.
Custom files
2.
ANATOMY OF
A MIGRATION
In files
2.
ANATOMY OF
A MIGRATION
The easiest
example
DEFINITIONS
config/install/migrate.migration.article_node.yml
2.
ANATOMY OF
A MIGRATIONid: article_node
label: Migrate posts from CakePHP to Drupal 8
source:
plugin: article_node
key: legacy
#target: legacy
destination:
plugin: entity:node
process:
type:
plugin: default_value
default_value: article
nid: id
title: title
'body/value': description
uid: user_id
status:
plugin: default_value
default_value: true
created:
plugin: callback
source: created
callable: strtotime
PLUGINS
src/Plugin/migrate/source/ArticleNode.php
2.
ANATOMY OF
A MIGRATION<?php
namespace ..
use ..
/**
* Source plugin for beer content.
*
* @MigrateSource(
* id = "article_node"
* )
*/
class ArticleNode extends SqlBase {
public function query() {
$query = $this->select('articles', 'a')
->fields('a', [
'id',
'user_id',
'title',
'description',
'created',
]);
return $query;
}
public function fields() {
$fields = [
'id' => $this->t("Article ID"),
// ...
];
return $fields;
}
public function getIds() {
return [
'id' => [
'type' => 'integer',
'alias' => 'a',
],
];
}
}
CONFIGURATION
sites/local/settings.php
2.
ANATOMY OF
A MIGRATION
<?php
$databases['legacy']['default'] = array(
'database' => 'old_app',
'username' => 'dev',
'password' => 'dev',
'prefix' => '',
'host' => 'localhost',
'port' => '3306',
'namespace' => 'DrupalCoreDatabaseDrivermysql',
'driver' => 'mysql',
);
EXECUTION
Only with Drush8 and migrate_plus enabled
2.
ANATOMY OF
A MIGRATION
vagrant@dev $ drush8 migrate-status
Group: my_group Status Total Imported Unprocessed Last imported
article_node Idle 128 0 128
vagrant@dev $ drush8 migrate-import article_node; d8 ms
Processed 128 item (128 created, 0 updated, 0 failed, 0 ignored) - done with
'article_node' [status]
Group: my_group Status Total Imported Unprocessed Last imported
article_node Idle 128 128 0 2016-02-22 12:34:38
vagrant@dev $ drush8 migrate-rollback article_node; d8 ms
Rolled back 128 items - done with 'article_node'
Group: my_group Status Total Imported Unprocessed Last imported
article_node Idle 128 0 128 2016-02-22 12:34:38
Too easy!
2.
ANATOMY OF
A MIGRATION
3.
MIGRATION
FRAMEWORK
0.- KNOWLEDGE 3.
MIGRATION
FRAMEWORKSource Plugin:
- SqlBase
Process Plugin:
- ProcessPluginBase
Destination Plugin:
- DestinationBase
More plugins in: core/modules/migrate/src/Plugin/migrate
Most
used
0.- KNOWLEDGE 3.
MIGRATION
FRAMEWORKprepareRow !== transform
- extends SqlBase
- Before execution
- extends
ProcessPluginBase
- During execution
1.- SOURCE 3.
MIGRATION
FRAMEWORK
We tell here to SqlBase:
- Which Database is the Source.
#migrate.migration.article_node.yml
source:
plugin: article_node
key: legacy
#target: legacy
#settings.php
$databases['key']['target'] = array(
1.- SOURCE 3.
MIGRATION
FRAMEWORK
- And which Plugin will make the Query
<?php
namespace Drupalcm_migratePluginmigratesource;
use ...
/**
* Source plugin for articles content.
*
* @MigrateSource(
* id = "article_node"
* )
*/
class ArticleNode extends SqlBase {
public function query() {
$query = $this->select('articles', 'a')
->fields('a', [
'id',
'user_id',
'title',
'description',
'created',
]);
return $query;
}
public function fields() {
$fields = [
'id' => $this->t("Article ID"),
// ...
];
return $fields;
}
public function getIds() {
return [
'id' => [
'type' => 'integer',
'alias' => 'a',
],
];
}
public function prepareRow(Row $row) {
$id = $row->getSourceProperty('id');
//print $id . PHP_EOL;
//print_r($row);
$row->setSourceProperty('user_id', 1);
return parent::prepareRow($row);
}
}
2.- DESTINATION 3.
MIGRATION
FRAMEWORK
How and where to save the data
- Where to save the data.
#migrate.migration.article_node.yml
destination:
plugin: entity:node
- entity:<place-here-an-entity>
2.- DESTINATION 3.
MIGRATION
FRAMEWORK
More destination plugins?
Search for “destination:” in core
3.- ID MAPPING 3.
MIGRATION
FRAMEWORKHow Migrate associate old row with new row.
public function getIds() {
return [
'id' => [
'type' => 'string',
'alias' => 'u',
],
];
}
4.- PROCESS 3.
MIGRATION
FRAMEWORKHow we transform each field, each file or data.
- Map fields: Same value as origin.
- Modify: Change o process the value
- Add: Create new fields from other fields or
calculate these fields.
4.- PROCESS 3.
MIGRATION
FRAMEWORKMap fields. Values are equal in both sides
public function query() {
$query = $this
->select('articles', 'a')
->fields('a', [
'created',
'title',
'id',
'body',
'user_id',
]);
return $query;
}
#common mapping
process:
title: title
4.- PROCESS 3.
MIGRATION
FRAMEWORKDefaultValue. Add a default value
public function query() {
$query = $this
->select('articles', 'a')
->fields('a', [
'created',
'title',
'id',
'body',
'user_id',
]);
return $query;
}
#default value
process:
type:
plugin: default_value
default_value: article
'body/format':
plugin: default_value
default_value: plain_text
4.- PROCESS 3.
MIGRATION
FRAMEWORKCallable. Values are similars but a transform is
needed with a php function
public function query() {
$query = $this
->select('articles', 'a')
->fields('a', [
'created_date',
'title',
'id',
'body',
'user_id',
]);
return $query;
}
#'Callable.php' core plugin
process:
created:
plugin: callback
source: created_date
callable: strtotime
4.- PROCESS 3.
MIGRATION
FRAMEWORKDedupeEntity. Values in destination cannot be
equals, but in origin could be.
public function query() {
$query = $this
->select('users', 'u')
->fields('u', [
'user_id',
'user_name',
'mail',
]);
return $query;
}
# DedupeEntity.php' core
# plugin
process:
name:
plugin: dedupe_entity
source: user_name
entity_type: user
field: name
postfix: _
# admin_1, _2, ...
4.- PROCESS 3.
MIGRATION
FRAMEWORKMigration. Values from other migration.
Magic!
# ArticleNode.php
public function query() {
$query = $this
->select('articles', 'a')
->fields('a', [
'created_date',
'title',
'id',
'body',
'user_id',
]);
return $query;
}
# Migration as plugin
process:
field_tags:
plugin: migration
migration: tags_node
source: terms
migration_dependencies:
required:
- tags_node
fields()
4.- PROCESS 3.
MIGRATION
FRAMEWORKMigration. Values from other migration.
Magic!
# ArticleNode.php
public function fields() {
$fields = [
'terms' => $this->t
("New field terms"),
// ...
];
return $fields;
}
# ArticleNode.php
public function prepareRow(Row $row) {
$terms = $this->select('terms')
//...
->fetchCol();
//print_r($terms);
$row->setSourceProperty('terms',
$terms);
return parent::prepareRow($row);
}
}
4.- PROCESS 3.
MIGRATION
FRAMEWORKMigration. Values from other migration.
Magic!
#migrate.migration.tags_node.yml
source:
plugin: tags_node
destination:
plugin: entity:taxonomy_term
process:
name: term
parent:
plugin: migration
migration: tags_node
source: parent_term
# TagsNode.php
public function query() {
// code
->fields('terms', [
'parent_term',
'term']);
}
4.- PROCESS 3.
MIGRATION
FRAMEWORKCustomPlugins. Values are related but a
custom transform for data is needed
public function query() {
$query = $this
->select('articles', 'a')
->fields('a', [
'created_date',
'title',
'id',
'body',
'user_id',
]);
return $query;
}
#CustomUUID.php' custom plugin
process:
uid:
plugin: custom_uuid
source: user_id
4.- PROCESS 3.
MIGRATION
FRAMEWORK<?php
/**
* @MigrateProcessPlugin(id = "custom_uuid")
*/
class CustomUUID extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface
$migrate_executable, Row $row, $destination_property) {
$uid = 0;
$uids = Drupal::entityQuery('user')
->condition('field_user_old_uuid', $row->getSourceProperty("user_id"))
->execute();
if (count($uids) > 0) {
$uid = array_values($uids)[0];
}
return $uid;
}
}
4.- PROCESS 3.
MIGRATION
FRAMEWORKCustomPlugins. We need to copy some files
public function query() {
$query = $this
->select('files', 'f')
->fields('f', [
'id',
'post_id',
'name',
'path',
'dir',
]);
return $query;
}
#CustomFiles.php' custom plugin
destination:
plugin: entity:file
process:
fid: id
filename: name
uri:
plugin: custom_file_uri
source:
- path
- name
4.- PROCESS 3.
MIGRATION
FRAMEWORK// In CustomFiles.php. source plugin.
public function prepareRow(Row $row) {
// Set the complete external path to the image.
$local_path = '/var/www/webroot/files/image/attachments/';
$attachment = $row->getSourceProperty('path');
$dir = $row->getSourceProperty('dir') . "/";
$filepath = $local_path . $dir . $attachment;
$row->setSourceProperty('path', $filepath);
$file_name = basename($attachment);
// Set filename. Not OK in every origin row.
$row->setSourceProperty('name', $file_name);
return parent::prepareRow($row);
}
4.- PROCESS 3.
MIGRATION
FRAMEWORK<?php
/**
* @MigrateProcessPlugin(id = "custom_file_uri")
*/
class CustomFileUri extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row
$row, $destination_property) {
list($filepath, $filename) = $value;
$destination_base_uri = 'public://articles/';
print "TRANSFORM Filepath: $filepath" . PHP_EOL;
print "TRANSFORM Destination: $destination_base_uri" . "$filename" . PHP_EOL;
// public://articles/photo (2).jpg
return $destination_base_uri . $filename;
}
}
4.- PROCESS 3.
MIGRATION
FRAMEWORKMore core plugins:
- concat
- extract
- flatten
- get
- iterator
- machine_name
- menu_link_parent
- route
- skip_on_empty
- skip_row_if_not_set
- static_map
Need an example?
Core is full of examples!
Search in core!
- “plugin: concat”
- “plugin: get”
- …
5.- WANT MORE? 3.
MIGRATION
FRAMEWORKTake a look at:
- core/modules/migrate/src/Plugin/migrate
- core/modules/<any>/src/Plugin/migrate
- core/modules/<any>/config/migration_templates
Or search in core:
- “@MigrateSource(“
- “destination:”
- “migration_tags:”
Drupal 8 core is
full of examples
3.
MIGRATION
FRAMEWORK
Really!
4.
DRUPAL 2 DRUPAL
MIGRATION
THINK THAT MIGRATE IS COMPLEX? 4.
D2D
MIGRATIONMaybe. And sometimes is difficult to debug.
So… Here we have:
Migrate Drupal module
And:
- Migrate Upgrade
- Migrate Plus
- Migrate Tools *experimental
REQUIREMENTS 4.
D2D
MIGRATION- Fresh install of Drupal 8
- Modules enabled:
- Migrate,
- Drupal Migrate,
- Migrate upgrade
- Access to D6 or D7 database
- Access to D6 or D7 files
SET UP 4.
D2D
MIGRATIONGo to: “/upgrade”.
SET UP 4.
D2D
MIGRATION
EXECUTE 4.
D2D
MIGRATION
EXECUTE 4.
D2D
MIGRATION
EXECUTE 4.
D2D
MIGRATION
EXECUTE 4.
D2D
MIGRATION
4.
D2D
MIGRATION
Code?
Maybe
4.
D2D
MIGRATION
#migrate.migration.article_node.yml
source:
plugin: custom_user
key: legacy
#equal as standard migration
1.- SOURCE
We tell here to DrupalSqlBase:
- Which Database is the Source.
4.
D2D
MIGRATION
1.- SOURCE
Class now extends from DrupalSqlBase
class User extends DrupalSqlBase
implements SourceEntityInterface {
public function query() {
return $this->select('users', 'u')
->fields('u', [//Fields])
->condition('uid', 0, '>');
}
4.
D2D
MIGRATION
1.- SOURCE
public function fields() {
$fields = $this->baseFields();
$fields['first_name'] = $this->t('First Name');
$fields['last_name'] = $this->t('Last Name');
$fields['biography'] = $this->t('Biography');
return $fields;
}
- Can use baseFields and add more fields
4.
D2D
MIGRATION
1.- SOURCE
public function prepareRow(Row $row) {
$uid = $row->getSourceProperty('uid');
// first_name
$result = $this->getDatabase()->query('
SELECT fld.field_first_name_value
FROM {field_data_field_first_name} fld
WHERE fld.entity_id = :uid
', array(':uid' => $uid));
foreach ($result as $record) {
$row->setSourceProperty('first_name',
$record->field_first_name_value );
}
- Prepare the Rows
4.
D2D
MIGRATION
Or give a try
to ...
4.
D2D
MIGRATION
drush migrate-manifest --legacy-db-url=... 
D6Manifest-User.yml
migrate-manifest
https://www.youtube.com/watch?v=l4m5msEY-Jg
4.
D2D
MIGRATION
#D6Manifest-User.yml
- d6_user
- d6_user_profile_field
- d6_user_profile_field_instance
- d6_user_profile_entity_display
- d6_user_profile_entity_form_display
- d6_profile_values:user
- d6_filter_format
- d6_user_role
- d6_user_picture_entity_display
- d6_user_picture_entity_form_display
- d6_user_picture_file
- d6_user_picture_field
- d6_user_picture_field_instance
Manifest
List of migrations
4.
D2D
MIGRATION
Manifest
Migrations that are in core.
4.
D2D
MIGRATION
And something is
coming to
8.1.x
THANKS!
@isholgueras
nacho@letshackity.com

More Related Content

What's hot

Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
Drupalcon Paris
 
[drupalday2017] - Speed-up your Drupal instance!
[drupalday2017] - Speed-up your Drupal instance![drupalday2017] - Speed-up your Drupal instance!
[drupalday2017] - Speed-up your Drupal instance!
DrupalDay
 
Drupal 6.x, Drupal 7.x -- Scratching the surface
Drupal 6.x, Drupal 7.x -- Scratching the surfaceDrupal 6.x, Drupal 7.x -- Scratching the surface
Drupal 6.x, Drupal 7.x -- Scratching the surface
Florian Latzel
 
features+
features+features+
features+
Florian Latzel
 
Drupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systemsDrupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systems
Alex S
 
2014 hadoop wrocław jug
2014 hadoop   wrocław jug2014 hadoop   wrocław jug
2014 hadoop wrocław jug
Wojciech Langiewicz
 
Ansible project-deploy
Ansible project-deployAnsible project-deploy
Ansible project-deploy
Ramon de la Fuente
 
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, PuppetPuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
Puppet
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
Fabio Fumarola
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
Fabio Fumarola
 
Learn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLearn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutes
Larry Cai
 
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
camp_drupal_ua
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...
Alex S
 
3 Git
3 Git3 Git
Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013
OpenNebula Project
 
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
DrupalDay
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
Philip Norton
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
Kirk Bushell
 
Yet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment PresentationYet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment Presentation
digital006
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
Mukesh Agarwal
 

What's hot (20)

Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
[drupalday2017] - Speed-up your Drupal instance!
[drupalday2017] - Speed-up your Drupal instance![drupalday2017] - Speed-up your Drupal instance!
[drupalday2017] - Speed-up your Drupal instance!
 
Drupal 6.x, Drupal 7.x -- Scratching the surface
Drupal 6.x, Drupal 7.x -- Scratching the surfaceDrupal 6.x, Drupal 7.x -- Scratching the surface
Drupal 6.x, Drupal 7.x -- Scratching the surface
 
features+
features+features+
features+
 
Drupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systemsDrupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systems
 
2014 hadoop wrocław jug
2014 hadoop   wrocław jug2014 hadoop   wrocław jug
2014 hadoop wrocław jug
 
Ansible project-deploy
Ansible project-deployAnsible project-deploy
Ansible project-deploy
 
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, PuppetPuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
Learn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutesLearn Dashing Widget in 90 minutes
Learn Dashing Widget in 90 minutes
 
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...
 
3 Git
3 Git3 Git
3 Git
 
Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013Getting Started Hacking OpenNebula - Fosdem-2013
Getting Started Hacking OpenNebula - Fosdem-2013
 
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
[drupalday2017] - Drupal come frontend che consuma servizi: HTTP Client Manager
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
Yet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment PresentationYet Another Drupal Development/Deployment Presentation
Yet Another Drupal Development/Deployment Presentation
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 

Viewers also liked

Content migration - CSV to Drupal 8
Content migration -  CSV to Drupal 8Content migration -  CSV to Drupal 8
Content migration - CSV to Drupal 8
Hector Iribarne
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksMigrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Acquia
 
Migrate, una herramienta de trabajo y desarrollo
Migrate, una herramienta de trabajo y desarrolloMigrate, una herramienta de trabajo y desarrollo
Migrate, una herramienta de trabajo y desarrollo
Ymbra
 
Migrate to drupal
Migrate to drupalMigrate to drupal
Migrate to drupal
Srijan Technologies
 
Dc salad
Dc saladDc salad
Migrate in Drupal 8
Migrate in Drupal 8Migrate in Drupal 8
Migrate in Drupal 8
Alexei Gorobets
 
Cms
CmsCms
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
Andy Postnikov
 
Drupal content-migration
Drupal content-migrationDrupal content-migration
Drupal content-migration
Ashok Modi
 
Selfbank - Caso Éxito - DrupalCamp Caceres 2016
Selfbank - Caso Éxito - DrupalCamp Caceres 2016Selfbank - Caso Éxito - DrupalCamp Caceres 2016
Selfbank - Caso Éxito - DrupalCamp Caceres 2016
David Gil Sánchez
 
Migration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalMigration from Legacy CMS to Drupal
Migration from Legacy CMS to Drupal
Rachel Jaro
 
T44u 2015, content migration
T44u 2015, content migrationT44u 2015, content migration
T44u 2015, content migration
Terminalfour
 

Viewers also liked (12)

Content migration - CSV to Drupal 8
Content migration -  CSV to Drupal 8Content migration -  CSV to Drupal 8
Content migration - CSV to Drupal 8
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksMigrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
 
Migrate, una herramienta de trabajo y desarrollo
Migrate, una herramienta de trabajo y desarrolloMigrate, una herramienta de trabajo y desarrollo
Migrate, una herramienta de trabajo y desarrollo
 
Migrate to drupal
Migrate to drupalMigrate to drupal
Migrate to drupal
 
Dc salad
Dc saladDc salad
Dc salad
 
Migrate in Drupal 8
Migrate in Drupal 8Migrate in Drupal 8
Migrate in Drupal 8
 
Cms
CmsCms
Cms
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Drupal content-migration
Drupal content-migrationDrupal content-migration
Drupal content-migration
 
Selfbank - Caso Éxito - DrupalCamp Caceres 2016
Selfbank - Caso Éxito - DrupalCamp Caceres 2016Selfbank - Caso Éxito - DrupalCamp Caceres 2016
Selfbank - Caso Éxito - DrupalCamp Caceres 2016
 
Migration from Legacy CMS to Drupal
Migration from Legacy CMS to DrupalMigration from Legacy CMS to Drupal
Migration from Legacy CMS to Drupal
 
T44u 2015, content migration
T44u 2015, content migrationT44u 2015, content migration
T44u 2015, content migration
 

Similar to Migrating data to drupal 8

Automating Drupal Migrations
Automating Drupal MigrationsAutomating Drupal Migrations
Automating Drupal Migrations
littleMAS
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
Luca Lusso
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
DrupalDay
 
Content Staging in Drupal 8
Content Staging in Drupal 8Content Staging in Drupal 8
Content Staging in Drupal 8
Dick Olsson
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
Alex S
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate module
Johan Gant
 
Getting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGetting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydb
Girish Bapat
 
The Myths, Musts and Migraines of Migrations - DrupalJam 2018
The Myths, Musts and Migraines of Migrations - DrupalJam 2018The Myths, Musts and Migraines of Migrations - DrupalJam 2018
The Myths, Musts and Migraines of Migrations - DrupalJam 2018
LimoenGroen
 
Migration to drupal 8.
Migration to drupal 8.Migration to drupal 8.
Migration to drupal 8.
Anatoliy Polyakov
 
Building mobile applications with DrupalGap
Building mobile applications with DrupalGapBuilding mobile applications with DrupalGap
Building mobile applications with DrupalGap
Alex S
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
Pavel Makhrinsky
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
Alan Pinstein
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Deployer - Deployment tool for PHP
Deployer - Deployment tool for PHPDeployer - Deployment tool for PHP
Deployer - Deployment tool for PHP
hernanibf
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
camp_drupal_ua
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
Ben Hall
 
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on KubernetesApache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
DataWorks Summit
 
Secure your site
Secure your siteSecure your site
Secure your site
Matthew Farina
 
Automating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondAutomating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyond
Nuvole
 

Similar to Migrating data to drupal 8 (20)

Automating Drupal Migrations
Automating Drupal MigrationsAutomating Drupal Migrations
Automating Drupal Migrations
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
Content Staging in Drupal 8
Content Staging in Drupal 8Content Staging in Drupal 8
Content Staging in Drupal 8
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate module
 
Getting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGetting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydb
 
The Myths, Musts and Migraines of Migrations - DrupalJam 2018
The Myths, Musts and Migraines of Migrations - DrupalJam 2018The Myths, Musts and Migraines of Migrations - DrupalJam 2018
The Myths, Musts and Migraines of Migrations - DrupalJam 2018
 
Migration to drupal 8.
Migration to drupal 8.Migration to drupal 8.
Migration to drupal 8.
 
Building mobile applications with DrupalGap
Building mobile applications with DrupalGapBuilding mobile applications with DrupalGap
Building mobile applications with DrupalGap
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Deployer - Deployment tool for PHP
Deployer - Deployment tool for PHPDeployer - Deployment tool for PHP
Deployer - Deployment tool for PHP
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
 
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on KubernetesApache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
 
Secure your site
Secure your siteSecure your site
Secure your site
 
Automating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyondAutomating Drupal Development: Makefiles, features and beyond
Automating Drupal Development: Makefiles, features and beyond
 

Recently uploaded

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 

Recently uploaded (20)

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 

Migrating data to drupal 8

  • 3. STEPS 1. Requirements 2. Anatomy of a migration 3. Migration Framework 4. D2D migrations
  • 5. Two new modules ▸ Migrate Handles migrations. Framework. ▸ Migrate Drupal Contains migrations from D6 & D7. Migrate in core! 1. REQUIREMENTS
  • 6. But… how can I execute that migration. UI is not ready? No Drush command? UI for D2D migration in progress: https://www.drupal.org/node/2257723 Migrate in core! 1. REQUIREMENTS
  • 8. ▸ Drupal 8.0.x ▸ Drush 8 ▸ Migrate tools (contrib) ▸ Migrate Plus (contrib) Needed 1. REQUIREMENTS Useful
  • 11. PLUGINS PHP Files Core files or custom files Types: - Source - Process - Destination - Builder - ID Map DEFINITIONS Yaml Files. Custom files 2. ANATOMY OF A MIGRATION In files
  • 12. 2. ANATOMY OF A MIGRATION The easiest example
  • 13. DEFINITIONS config/install/migrate.migration.article_node.yml 2. ANATOMY OF A MIGRATIONid: article_node label: Migrate posts from CakePHP to Drupal 8 source: plugin: article_node key: legacy #target: legacy destination: plugin: entity:node process: type: plugin: default_value default_value: article nid: id title: title 'body/value': description uid: user_id status: plugin: default_value default_value: true created: plugin: callback source: created callable: strtotime
  • 14. PLUGINS src/Plugin/migrate/source/ArticleNode.php 2. ANATOMY OF A MIGRATION<?php namespace .. use .. /** * Source plugin for beer content. * * @MigrateSource( * id = "article_node" * ) */ class ArticleNode extends SqlBase { public function query() { $query = $this->select('articles', 'a') ->fields('a', [ 'id', 'user_id', 'title', 'description', 'created', ]); return $query; } public function fields() { $fields = [ 'id' => $this->t("Article ID"), // ... ]; return $fields; } public function getIds() { return [ 'id' => [ 'type' => 'integer', 'alias' => 'a', ], ]; } }
  • 15. CONFIGURATION sites/local/settings.php 2. ANATOMY OF A MIGRATION <?php $databases['legacy']['default'] = array( 'database' => 'old_app', 'username' => 'dev', 'password' => 'dev', 'prefix' => '', 'host' => 'localhost', 'port' => '3306', 'namespace' => 'DrupalCoreDatabaseDrivermysql', 'driver' => 'mysql', );
  • 16. EXECUTION Only with Drush8 and migrate_plus enabled 2. ANATOMY OF A MIGRATION vagrant@dev $ drush8 migrate-status Group: my_group Status Total Imported Unprocessed Last imported article_node Idle 128 0 128 vagrant@dev $ drush8 migrate-import article_node; d8 ms Processed 128 item (128 created, 0 updated, 0 failed, 0 ignored) - done with 'article_node' [status] Group: my_group Status Total Imported Unprocessed Last imported article_node Idle 128 128 0 2016-02-22 12:34:38 vagrant@dev $ drush8 migrate-rollback article_node; d8 ms Rolled back 128 items - done with 'article_node' Group: my_group Status Total Imported Unprocessed Last imported article_node Idle 128 0 128 2016-02-22 12:34:38
  • 19. 0.- KNOWLEDGE 3. MIGRATION FRAMEWORKSource Plugin: - SqlBase Process Plugin: - ProcessPluginBase Destination Plugin: - DestinationBase More plugins in: core/modules/migrate/src/Plugin/migrate Most used
  • 20. 0.- KNOWLEDGE 3. MIGRATION FRAMEWORKprepareRow !== transform - extends SqlBase - Before execution - extends ProcessPluginBase - During execution
  • 21. 1.- SOURCE 3. MIGRATION FRAMEWORK We tell here to SqlBase: - Which Database is the Source. #migrate.migration.article_node.yml source: plugin: article_node key: legacy #target: legacy #settings.php $databases['key']['target'] = array(
  • 22. 1.- SOURCE 3. MIGRATION FRAMEWORK - And which Plugin will make the Query <?php namespace Drupalcm_migratePluginmigratesource; use ... /** * Source plugin for articles content. * * @MigrateSource( * id = "article_node" * ) */ class ArticleNode extends SqlBase { public function query() { $query = $this->select('articles', 'a') ->fields('a', [ 'id', 'user_id', 'title', 'description', 'created', ]); return $query; } public function fields() { $fields = [ 'id' => $this->t("Article ID"), // ... ]; return $fields; } public function getIds() { return [ 'id' => [ 'type' => 'integer', 'alias' => 'a', ], ]; } public function prepareRow(Row $row) { $id = $row->getSourceProperty('id'); //print $id . PHP_EOL; //print_r($row); $row->setSourceProperty('user_id', 1); return parent::prepareRow($row); } }
  • 23. 2.- DESTINATION 3. MIGRATION FRAMEWORK How and where to save the data - Where to save the data. #migrate.migration.article_node.yml destination: plugin: entity:node - entity:<place-here-an-entity>
  • 24. 2.- DESTINATION 3. MIGRATION FRAMEWORK More destination plugins? Search for “destination:” in core
  • 25. 3.- ID MAPPING 3. MIGRATION FRAMEWORKHow Migrate associate old row with new row. public function getIds() { return [ 'id' => [ 'type' => 'string', 'alias' => 'u', ], ]; }
  • 26. 4.- PROCESS 3. MIGRATION FRAMEWORKHow we transform each field, each file or data. - Map fields: Same value as origin. - Modify: Change o process the value - Add: Create new fields from other fields or calculate these fields.
  • 27. 4.- PROCESS 3. MIGRATION FRAMEWORKMap fields. Values are equal in both sides public function query() { $query = $this ->select('articles', 'a') ->fields('a', [ 'created', 'title', 'id', 'body', 'user_id', ]); return $query; } #common mapping process: title: title
  • 28. 4.- PROCESS 3. MIGRATION FRAMEWORKDefaultValue. Add a default value public function query() { $query = $this ->select('articles', 'a') ->fields('a', [ 'created', 'title', 'id', 'body', 'user_id', ]); return $query; } #default value process: type: plugin: default_value default_value: article 'body/format': plugin: default_value default_value: plain_text
  • 29. 4.- PROCESS 3. MIGRATION FRAMEWORKCallable. Values are similars but a transform is needed with a php function public function query() { $query = $this ->select('articles', 'a') ->fields('a', [ 'created_date', 'title', 'id', 'body', 'user_id', ]); return $query; } #'Callable.php' core plugin process: created: plugin: callback source: created_date callable: strtotime
  • 30. 4.- PROCESS 3. MIGRATION FRAMEWORKDedupeEntity. Values in destination cannot be equals, but in origin could be. public function query() { $query = $this ->select('users', 'u') ->fields('u', [ 'user_id', 'user_name', 'mail', ]); return $query; } # DedupeEntity.php' core # plugin process: name: plugin: dedupe_entity source: user_name entity_type: user field: name postfix: _ # admin_1, _2, ...
  • 31. 4.- PROCESS 3. MIGRATION FRAMEWORKMigration. Values from other migration. Magic! # ArticleNode.php public function query() { $query = $this ->select('articles', 'a') ->fields('a', [ 'created_date', 'title', 'id', 'body', 'user_id', ]); return $query; } # Migration as plugin process: field_tags: plugin: migration migration: tags_node source: terms migration_dependencies: required: - tags_node fields()
  • 32. 4.- PROCESS 3. MIGRATION FRAMEWORKMigration. Values from other migration. Magic! # ArticleNode.php public function fields() { $fields = [ 'terms' => $this->t ("New field terms"), // ... ]; return $fields; } # ArticleNode.php public function prepareRow(Row $row) { $terms = $this->select('terms') //... ->fetchCol(); //print_r($terms); $row->setSourceProperty('terms', $terms); return parent::prepareRow($row); } }
  • 33. 4.- PROCESS 3. MIGRATION FRAMEWORKMigration. Values from other migration. Magic! #migrate.migration.tags_node.yml source: plugin: tags_node destination: plugin: entity:taxonomy_term process: name: term parent: plugin: migration migration: tags_node source: parent_term # TagsNode.php public function query() { // code ->fields('terms', [ 'parent_term', 'term']); }
  • 34. 4.- PROCESS 3. MIGRATION FRAMEWORKCustomPlugins. Values are related but a custom transform for data is needed public function query() { $query = $this ->select('articles', 'a') ->fields('a', [ 'created_date', 'title', 'id', 'body', 'user_id', ]); return $query; } #CustomUUID.php' custom plugin process: uid: plugin: custom_uuid source: user_id
  • 35. 4.- PROCESS 3. MIGRATION FRAMEWORK<?php /** * @MigrateProcessPlugin(id = "custom_uuid") */ class CustomUUID extends ProcessPluginBase { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $uid = 0; $uids = Drupal::entityQuery('user') ->condition('field_user_old_uuid', $row->getSourceProperty("user_id")) ->execute(); if (count($uids) > 0) { $uid = array_values($uids)[0]; } return $uid; } }
  • 36. 4.- PROCESS 3. MIGRATION FRAMEWORKCustomPlugins. We need to copy some files public function query() { $query = $this ->select('files', 'f') ->fields('f', [ 'id', 'post_id', 'name', 'path', 'dir', ]); return $query; } #CustomFiles.php' custom plugin destination: plugin: entity:file process: fid: id filename: name uri: plugin: custom_file_uri source: - path - name
  • 37. 4.- PROCESS 3. MIGRATION FRAMEWORK// In CustomFiles.php. source plugin. public function prepareRow(Row $row) { // Set the complete external path to the image. $local_path = '/var/www/webroot/files/image/attachments/'; $attachment = $row->getSourceProperty('path'); $dir = $row->getSourceProperty('dir') . "/"; $filepath = $local_path . $dir . $attachment; $row->setSourceProperty('path', $filepath); $file_name = basename($attachment); // Set filename. Not OK in every origin row. $row->setSourceProperty('name', $file_name); return parent::prepareRow($row); }
  • 38. 4.- PROCESS 3. MIGRATION FRAMEWORK<?php /** * @MigrateProcessPlugin(id = "custom_file_uri") */ class CustomFileUri extends ProcessPluginBase { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { list($filepath, $filename) = $value; $destination_base_uri = 'public://articles/'; print "TRANSFORM Filepath: $filepath" . PHP_EOL; print "TRANSFORM Destination: $destination_base_uri" . "$filename" . PHP_EOL; // public://articles/photo (2).jpg return $destination_base_uri . $filename; } }
  • 39. 4.- PROCESS 3. MIGRATION FRAMEWORKMore core plugins: - concat - extract - flatten - get - iterator - machine_name - menu_link_parent - route - skip_on_empty - skip_row_if_not_set - static_map Need an example? Core is full of examples! Search in core! - “plugin: concat” - “plugin: get” - …
  • 40. 5.- WANT MORE? 3. MIGRATION FRAMEWORKTake a look at: - core/modules/migrate/src/Plugin/migrate - core/modules/<any>/src/Plugin/migrate - core/modules/<any>/config/migration_templates Or search in core: - “@MigrateSource(“ - “destination:” - “migration_tags:”
  • 41. Drupal 8 core is full of examples 3. MIGRATION FRAMEWORK Really!
  • 43. THINK THAT MIGRATE IS COMPLEX? 4. D2D MIGRATIONMaybe. And sometimes is difficult to debug. So… Here we have: Migrate Drupal module And: - Migrate Upgrade - Migrate Plus - Migrate Tools *experimental
  • 44. REQUIREMENTS 4. D2D MIGRATION- Fresh install of Drupal 8 - Modules enabled: - Migrate, - Drupal Migrate, - Migrate upgrade - Access to D6 or D7 database - Access to D6 or D7 files
  • 45. SET UP 4. D2D MIGRATIONGo to: “/upgrade”.
  • 52. 4. D2D MIGRATION #migrate.migration.article_node.yml source: plugin: custom_user key: legacy #equal as standard migration 1.- SOURCE We tell here to DrupalSqlBase: - Which Database is the Source.
  • 53. 4. D2D MIGRATION 1.- SOURCE Class now extends from DrupalSqlBase class User extends DrupalSqlBase implements SourceEntityInterface { public function query() { return $this->select('users', 'u') ->fields('u', [//Fields]) ->condition('uid', 0, '>'); }
  • 54. 4. D2D MIGRATION 1.- SOURCE public function fields() { $fields = $this->baseFields(); $fields['first_name'] = $this->t('First Name'); $fields['last_name'] = $this->t('Last Name'); $fields['biography'] = $this->t('Biography'); return $fields; } - Can use baseFields and add more fields
  • 55. 4. D2D MIGRATION 1.- SOURCE public function prepareRow(Row $row) { $uid = $row->getSourceProperty('uid'); // first_name $result = $this->getDatabase()->query(' SELECT fld.field_first_name_value FROM {field_data_field_first_name} fld WHERE fld.entity_id = :uid ', array(':uid' => $uid)); foreach ($result as $record) { $row->setSourceProperty('first_name', $record->field_first_name_value ); } - Prepare the Rows
  • 57. 4. D2D MIGRATION drush migrate-manifest --legacy-db-url=... D6Manifest-User.yml migrate-manifest https://www.youtube.com/watch?v=l4m5msEY-Jg
  • 58. 4. D2D MIGRATION #D6Manifest-User.yml - d6_user - d6_user_profile_field - d6_user_profile_field_instance - d6_user_profile_entity_display - d6_user_profile_entity_form_display - d6_profile_values:user - d6_filter_format - d6_user_role - d6_user_picture_entity_display - d6_user_picture_entity_form_display - d6_user_picture_file - d6_user_picture_field - d6_user_picture_field_instance Manifest List of migrations