SlideShare una empresa de Scribd logo
1 de 54
Descargar para leer sin conexión
The MythsThe Myths**,,
MustsMusts** and Migrainesand Migraines**
of Migrationsof Migrations
Marc van GendMarc van Gend
@marcvangend
Drupal Tech TalkDrupal Tech Talk
April 26, ezCompany, TilburgApril 26, ezCompany, Tilburg
Who are you?Who are you?
Developers
Project managers
Site owners ("the client")
None of the above
*
*
*
*
QuizQuiz
The key to a successful migration is...
A. Good clean source data
B. A committed, cooperating client
C. Plenty of development time
You were right! You were right!You were right! You were right!
Everybody was right!Everybody was right!
Non-Drupal to Drupal migrationsNon-Drupal to Drupal migrations
Source - Process - Destination
Setup
My First Migration™
Source data
Process plugins
Project context
Tips
*
*
*
*
*
*
*
**MythMyth
Migrations are ComplicatedMigrations are Complicated
Source.Source.
Process.Process.
Destination.Destination.
Migrations are straight-forward.
Literally.
SourceSource
Database, File, URL...
1 result per migration item
Defines unique Source ID
*
*
* PHP:
class MySourcePlugin extends SourcePluginBase
Drupal Console:
drupal generate:plugin:migrate:source {}
ProcessProcess
Get, Concat, MigrateLookup, custom...
Assigns values to fields
Chainable
*
*
* PHP:
class MyProcessPlugin extends ProcessPluginBase {}
Drupal Console:
drupal generate:plugin:migrate:process
DestinationDestination
Node, Term, User, Redirect, Setting, custom...
Writes collected data to Drupal DB
Can support rollback
Maps Source ID -> Destination ID
*
*
*
* PHP:
class MyDestinationPlugin extends DestinationBase {}
Drupal Console:
(nope)
**MustMust
The right toolsThe right tools
Modules
Tools
Custom module
Test site
*
*
*
*
ModulesModules
Migrate (core)Migrate (core)
Migrate API and base functionality
Continuous migrations with ID mapping
Migrate PlusMigrate Plus
Define migrations as config entities
Additional plugins and enhancements
Data parsers and authentication
Examples
Migrate ToolsMigrate Tools
Drush commands and UI
ToolsTools
DrushDrush
Import migration config
Run migrations
Rollback, reset, status, etc.
Drupal ConsoleDrupal Console
Create plugins
Database managerDatabase manager
PhpStorm, phpMyAdmin
Custom moduleCustom module
migrate_demo
├── migrate_demo.info.yml
├── config
│ └── install
│ ├── migrate_plus.migration.demo_node_article.yml
│ └── migrate_plus.migration_group.demo.yml
└── src
└── Plugin
└── migrate
├── process
│ └── TitleCleanup.php
└── source
└── DemoNodeArticle.php
Demo SiteDemo Site
SourceSource
Music database (Chinook):
Artist ⪪ Album
DrupalDrupal
Artist: Title
Album: Title, Artist, Release date, URL
*
*
My First Migration™My First Migration™
Migrate Group
Migration
Go!
*
*
*
**MustMust
Handwritten YAMLHandwritten YAML
# Enough about you, let's talk about me!
name: Marc
favorites:
music: dEUS
beer:
- IPA
- Triple
colleagues:
-
name: Dirk
role: Support engineer
-
name: Joyce
role: Drupal developer
Migration groupsMigration groups
Groups migrations (duh!)
Import all migrations in group
Shared configuration
*
*
*
Migration group configMigration group config
migrate_demo/config/install/migrate_plus.migration_group.demo.yml
id: demo
label: Demo Imports
description: A few demo imports, to demonstrate how to implement migrations.
source_type: SQL database
shared_configuration:
source:
key: migrate
dependencies:
enforced:
module:
- migrate_demo
Migration source: DB settingsMigration source: DB settings
settings.php
$databases['migrate']['default'] = array (
'database' => 'migrate_demo_source',
'username' => 'migrate_demo_source',
'password' => 'Secret!',
'prefix' => '',
'host' => '127.0.0.1',
'port' => '3306',
'namespace' => 'DrupalCoreDatabaseDrivermysql',
'driver' => 'mysql',
);
Migration source: source pluginMigration source: source plugin
migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
/**
* Source plugin for artist content.
*
* @MigrateSource(
* id = "demo_node_artist"
* )
*/
class DemoNodeArtist extends SqlBase {
migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('Artist', 'a')
->fields('a', [
'ArtistId',
'Name',
]);
return $query;
}
migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'ArtistId' => $this->t('Artist ID'),
'Name' => $this->t('Artist name'),
];
return $fields;
}
migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
Migration configMigration config
migrate_demo/config/install/migrate_plus.migration.demo_node_artist.yml
id: demo_node_artist # Migration ID
label: Artists # Human name
migration_group: demo
source:
plugin: demo_node_artist # Data source
process:
title: Name # Use the 'Name' value as title
type:
plugin: default_value
default_value: artist # Node type is 'artist'
destination:
plugin: entity:node # Save as a node
**MustMust
Importing your configImporting your config
$ drush config-import 
--partial 
--source=modules/custom/migrate_demo/config/install
Go!Go!
Or use the UI:
$ drush migrate-import demo_node_artist
Source dataSource data
Human interaction. Where things get messy.
**MythMyth
“The data is clean and complete”“The data is clean and complete”
**MigraineMigraine
Believe me. It's not.Believe me. It's not.
Getting the dataGetting the data
How can we access the data?
Direct access? Export? API?
How do we get updates?
How o en?
Incremental?
With timestamps?
How about assets like PDF's and images?
What size are we talking about?
Number of items, GB's of files
Make some friends at the supplier's side.Make some friends at the supplier's side.
*
*
*
*
*
*
*
*
*
Analyze the provided dataAnalyze the provided data
Ask the most stupid questions you can think of.
What does it all mean?
Does everything have a unique, unchanging ID?
Do users have unique email addresses?
Do all articles have titles?
Are records being added and deleted?
Yes ⇒ Are unique ID's reused?
Does the data contain duplicates?
No ⇒ Really? Did you check?
Do not assume people know their own data.Do not assume people know their own data.
*
*
*
*
*
*
*
*
Start planningStart planning
Make choices
Don't spend 4h automating what takes 8h manually
Agree what you will (not) do
Have the result tested
Functional
Content
Write a plan for the go-live
Content freeze
Pick dates
Instruct editors
*
*
*
*
*
*
*
*
*
*
**MythMyth
Migrations are SimpleMigrations are Simple
(I know. I said migrations are straight-forward.)
Prepare to write custom processors.
(psst, don't forget to start the demo)
Processors are AwesomeProcessors are Awesome
Default process plugin: Get
“Get the 'Name' property from the current row and use it as title”
process:
title: Name
Shorthand for:
process:
title:
plugin: get
source: Name
Processors can haveProcessors can have
configurationconfiguration
process:
type: # Entity type
plugin: default_value # Plugin ID
default_value: album # Fixed value
In the plugin:
$this->configuration['default_value']; // Returns "album".
Linking migrations togetherLinking migrations together
The migration_lookup process plugin
“Get the ID of the entity which was created
when demo_node_artist imported this ArtistID.”
process:
field_artist: # Entity reference field
plugin: migration_lookup
migration: demo_node_artist # Linked migration ID
source: ArtistId # Source ID
Chaining process pluginsChaining process plugins
process:
uid:
-
plugin: author_deduplicate # Custom deduplication processor
source: author_id
-
plugin: migration_lookup # Migration Lookup returns a UID
migration: users
# No 'source' property, because chaining!
-
plugin: default_value # Result is passed to the next processor
default_value: 44 # If empty, use UID 44
A custom processorA custom processor
migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
/**
* Retrieves album info through the Spotify Web API.
*
* @MigrateProcessPlugin(
* id = "spotify_info",
* )
*/
class SpotifyInfo extends ProcessPluginBase {
migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executabl
$type = $this->configuration['type'];
$query_info = $this->getSpotifyQueryInfo($value, $type);
$spotify_result = $this->spotifyQuery($query_info['query'], $type);
$property = $this->configuration['property'];
$data_path = array_merge($query_info['parents'], explode('][', $property));
return NestedArray::getValue($spotify_result, $data_path);
}
migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
protected function getSpotifyQueryInfo($value, $type) {
switch ($type) {
case 'album':
// Expect $value to be an array: [album title, artist name].
list($title, $artist) = $value;
$query = "album:$title artist:$artist";
$parents = ['albums', 'items', 0];
break;
}
if (empty($query)) {
throw new MigrateSkipProcessException('Could not build a query.');
}
return ['query' => $query, 'parents' => $parents];
}
migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
A custom processor: configA custom processor: config
process:
field_release_date:
plugin: spotify_info
source:
- Title
- ArtistName
type: album
property: release_date
field_spotify_url/uri: # Link fields are composed of multiple values
plugin: spotify_info
source:
- Title
- ArtistName
type: album
property: external_urls][spotify # Will be split into an array
**MigraineMigraine
A migration never comes aloneA migration never comes alone
If everything was perfect, there wouldn't be a migration, right?
Client goalsClient goals
What they say What it means
New site New URL's
New design An image on every node
New navigation Revised categories
New workflow Different input filters
...and the existing content will magically fit in.
Complexity = changes²Complexity = changes²
Reduce the number of changes introduced with the migration.
Spotify process plugin = A really bad idea
**MustMust
Start earlyStart early
Adapt your site to old content and future needs.
Migrate early, keep importing.
Estimate generously. Double it.
Tips & tricksTips & tricks
(If we have time)
Save time: performanceSave time: performance
Disable search indexing
Run migrations with Drush
*
*
Save time: reduced datasetSave time: reduced dataset
Imports approximately 1 in every 100 items.
settings.local.php
$settings['my_migration_reduce_factor'] = 100;
mySourcePlugin::query()
$reduce_factor = Settings::get('my_migration_reduce_factor');
if ($reduce_factor && is_int($reduce_factor)) {
$query->where('MOD(a.id, :reduce_factor) = 0',
[':reduce_factor' => $reduce_factor]);
}
Manual edits... now what?Manual edits... now what?
Run a migration on selected fields:
overwrite_properties ignores all values except explicitly listed.
destination:
plugin: 'entity:node'
overwrite_properties:
- category
Shortcut: entity_generateShortcut: entity_generate
No rollbacks, no mappings, no nothing.
Great for things that don't have a source ID.
process:
tags:
-
plugin: explode
source: keywords # Eg. "Foo,Bar,Baz"
delimiter: ',' # Explode comma separated string to array
-
plugin: entity_generate # Generate taxonomy terms that don't exist
Come for the software,Come for the software,
stay for the communitystay for the community
Thank you:Thank you:
Audience | Sponsors | LimoenGroen | Drupal Community
Questions?Questions?

Más contenido relacionado

La actualidad más candente

Stop Worrying & Love the SQL - A Case Study
Stop Worrying & Love the SQL - A Case StudyStop Worrying & Love the SQL - A Case Study
Stop Worrying & Love the SQL - A Case StudyAll Things Open
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11Elizabeth Smith
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Elizabeth Smith
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Stephan Hochdörfer
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stackKris Buytaert
 
Life Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
Life Cycle of Metrics, Alerting, and Performance Monitoring in MicroservicesLife Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
Life Cycle of Metrics, Alerting, and Performance Monitoring in MicroservicesSean Chittenden
 

La actualidad más candente (8)

Stop Worrying & Love the SQL - A Case Study
Stop Worrying & Love the SQL - A Case StudyStop Worrying & Love the SQL - A Case Study
Stop Worrying & Love the SQL - A Case Study
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
Ant vs Phing
Ant vs PhingAnt vs Phing
Ant vs Phing
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stack
 
Life Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
Life Cycle of Metrics, Alerting, and Performance Monitoring in MicroservicesLife Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
Life Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
 

Similar a The Myths, Musts and Migraines of Migrations - DrupalJam 2018

Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014
Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014
Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014Puppet
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-wayRobert Lujo
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Drupal8 migrate
Drupal8 migrateDrupal8 migrate
Drupal8 migrateJohn Doyle
 
Migrate 140123161042-phpapp02
Migrate 140123161042-phpapp02Migrate 140123161042-phpapp02
Migrate 140123161042-phpapp02Gaurav Varshney
 
Migrating to Drupal 8
Migrating to Drupal 8Migrating to Drupal 8
Migrating to Drupal 8Alkuvoima
 
Ideal Deployment In .NET World
Ideal Deployment In .NET WorldIdeal Deployment In .NET World
Ideal Deployment In .NET WorldDima Pasko
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Puppet for Sys Admins
Puppet for Sys AdminsPuppet for Sys Admins
Puppet for Sys AdminsPuppet
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesLeo Loobeek
 
WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...WordPress Trivandrum
 
Help your Enterprise Implement Big Data with Control-M for Hadoop
 Help your Enterprise Implement Big Data with Control-M for Hadoop Help your Enterprise Implement Big Data with Control-M for Hadoop
Help your Enterprise Implement Big Data with Control-M for HadoopBMC Software
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebMikel Torres Ugarte
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBo-Yi Wu
 

Similar a The Myths, Musts and Migraines of Migrations - DrupalJam 2018 (20)

Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014
Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014
Delegated Configuration with Multiple Hiera Databases - PuppetConf 2014
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
R sharing 101
R sharing 101R sharing 101
R sharing 101
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Drupal8 migrate
Drupal8 migrateDrupal8 migrate
Drupal8 migrate
 
Migrate 140123161042-phpapp02
Migrate 140123161042-phpapp02Migrate 140123161042-phpapp02
Migrate 140123161042-phpapp02
 
Migrating to Drupal 8
Migrating to Drupal 8Migrating to Drupal 8
Migrating to Drupal 8
 
Migrate to Drupal 8
Migrate to Drupal 8Migrate to Drupal 8
Migrate to Drupal 8
 
Ideal Deployment In .NET World
Ideal Deployment In .NET WorldIdeal Deployment In .NET World
Ideal Deployment In .NET World
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Puppet for Sys Admins
Puppet for Sys AdminsPuppet for Sys Admins
Puppet for Sys Admins
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
 
WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...WordPress Internationalization and Localization - WordPress Translation Day 3...
WordPress Internationalization and Localization - WordPress Translation Day 3...
 
Help your Enterprise Implement Big Data with Control-M for Hadoop
 Help your Enterprise Implement Big Data with Control-M for Hadoop Help your Enterprise Implement Big Data with Control-M for Hadoop
Help your Enterprise Implement Big Data with Control-M for Hadoop
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 

Más de LimoenGroen

Managing Drupal interface translation
Managing Drupal interface translationManaging Drupal interface translation
Managing Drupal interface translationLimoenGroen
 
Drupal Quick wins for an accessible website
Drupal Quick wins for an accessible websiteDrupal Quick wins for an accessible website
Drupal Quick wins for an accessible websiteLimoenGroen
 
Open drupal DrupalCamp Gent 2018
Open drupal DrupalCamp Gent 2018Open drupal DrupalCamp Gent 2018
Open drupal DrupalCamp Gent 2018LimoenGroen
 
24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)
24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)
24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)LimoenGroen
 
Being a better mentor
Being a better mentorBeing a better mentor
Being a better mentorLimoenGroen
 
Panels in Drupal: een EYE-opener
Panels in Drupal: een EYE-openerPanels in Drupal: een EYE-opener
Panels in Drupal: een EYE-openerLimoenGroen
 
Drupal is Traag: handvatten voor een snelle site.
Drupal is Traag: handvatten voor een snelle site.Drupal is Traag: handvatten voor een snelle site.
Drupal is Traag: handvatten voor een snelle site.LimoenGroen
 
Front-end Performance in Drupal
Front-end Performance in DrupalFront-end Performance in Drupal
Front-end Performance in DrupalLimoenGroen
 
Wat is Drupal? Over Drupal in musea.
Wat is Drupal? Over Drupal in musea.Wat is Drupal? Over Drupal in musea.
Wat is Drupal? Over Drupal in musea.LimoenGroen
 
Continuous Integration & Drupal
Continuous Integration & DrupalContinuous Integration & Drupal
Continuous Integration & DrupalLimoenGroen
 

Más de LimoenGroen (10)

Managing Drupal interface translation
Managing Drupal interface translationManaging Drupal interface translation
Managing Drupal interface translation
 
Drupal Quick wins for an accessible website
Drupal Quick wins for an accessible websiteDrupal Quick wins for an accessible website
Drupal Quick wins for an accessible website
 
Open drupal DrupalCamp Gent 2018
Open drupal DrupalCamp Gent 2018Open drupal DrupalCamp Gent 2018
Open drupal DrupalCamp Gent 2018
 
24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)
24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)
24Kitchen, the no. 1 platform for food lovers (Showcase LimoenGroen)
 
Being a better mentor
Being a better mentorBeing a better mentor
Being a better mentor
 
Panels in Drupal: een EYE-opener
Panels in Drupal: een EYE-openerPanels in Drupal: een EYE-opener
Panels in Drupal: een EYE-opener
 
Drupal is Traag: handvatten voor een snelle site.
Drupal is Traag: handvatten voor een snelle site.Drupal is Traag: handvatten voor een snelle site.
Drupal is Traag: handvatten voor een snelle site.
 
Front-end Performance in Drupal
Front-end Performance in DrupalFront-end Performance in Drupal
Front-end Performance in Drupal
 
Wat is Drupal? Over Drupal in musea.
Wat is Drupal? Over Drupal in musea.Wat is Drupal? Over Drupal in musea.
Wat is Drupal? Over Drupal in musea.
 
Continuous Integration & Drupal
Continuous Integration & DrupalContinuous Integration & Drupal
Continuous Integration & Drupal
 

Último

The Science of Landing Page Messaging.pdf
The Science of Landing Page Messaging.pdfThe Science of Landing Page Messaging.pdf
The Science of Landing Page Messaging.pdfVWO
 
BLOOM_April2024. Balmer Lawrie Online Monthly Bulletin
BLOOM_April2024. Balmer Lawrie Online Monthly BulletinBLOOM_April2024. Balmer Lawrie Online Monthly Bulletin
BLOOM_April2024. Balmer Lawrie Online Monthly BulletinBalmerLawrie
 
Unraveling the Mystery of the Hinterkaifeck Murders.pptx
Unraveling the Mystery of the Hinterkaifeck Murders.pptxUnraveling the Mystery of the Hinterkaifeck Murders.pptx
Unraveling the Mystery of the Hinterkaifeck Murders.pptxelizabethella096
 
Social Media Marketing PPT-Includes Paid media
Social Media Marketing PPT-Includes Paid mediaSocial Media Marketing PPT-Includes Paid media
Social Media Marketing PPT-Includes Paid mediaadityabelde2
 
Call Us ➥9654467111▻Call Girls In Delhi NCR
Call Us ➥9654467111▻Call Girls In Delhi NCRCall Us ➥9654467111▻Call Girls In Delhi NCR
Call Us ➥9654467111▻Call Girls In Delhi NCRSapana Sha
 
Aryabhata I, II of mathematics of both.pptx
Aryabhata I, II of mathematics of both.pptxAryabhata I, II of mathematics of both.pptx
Aryabhata I, II of mathematics of both.pptxtegevi9289
 
BDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...
VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...
VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...aditipandeya
 
What is Google Search Console and What is it provide?
What is Google Search Console and What is it provide?What is Google Search Console and What is it provide?
What is Google Search Console and What is it provide?riteshhsociall
 
How to Leverage Behavioral Science Insights for Direct Mail Success
How to Leverage Behavioral Science Insights for Direct Mail SuccessHow to Leverage Behavioral Science Insights for Direct Mail Success
How to Leverage Behavioral Science Insights for Direct Mail SuccessAggregage
 
Brighton SEO April 2024 - The Good, the Bad & the Ugly of SEO Success
Brighton SEO April 2024 - The Good, the Bad & the Ugly of SEO SuccessBrighton SEO April 2024 - The Good, the Bad & the Ugly of SEO Success
Brighton SEO April 2024 - The Good, the Bad & the Ugly of SEO SuccessVarn
 
Moving beyond multi-touch attribution - DigiMarCon CanWest 2024
Moving beyond multi-touch attribution - DigiMarCon CanWest 2024Moving beyond multi-touch attribution - DigiMarCon CanWest 2024
Moving beyond multi-touch attribution - DigiMarCon CanWest 2024Richard Ingilby
 
Major SEO Trends in 2024 - Banyanbrain Digital
Major SEO Trends in 2024 - Banyanbrain DigitalMajor SEO Trends in 2024 - Banyanbrain Digital
Major SEO Trends in 2024 - Banyanbrain DigitalBanyanbrain
 
CALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service Onlineanilsa9823
 
Factors-Influencing-Branding-Strategies.pptx
Factors-Influencing-Branding-Strategies.pptxFactors-Influencing-Branding-Strategies.pptx
Factors-Influencing-Branding-Strategies.pptxVikasTiwari846641
 
BDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 

Último (20)

The Science of Landing Page Messaging.pdf
The Science of Landing Page Messaging.pdfThe Science of Landing Page Messaging.pdf
The Science of Landing Page Messaging.pdf
 
BLOOM_April2024. Balmer Lawrie Online Monthly Bulletin
BLOOM_April2024. Balmer Lawrie Online Monthly BulletinBLOOM_April2024. Balmer Lawrie Online Monthly Bulletin
BLOOM_April2024. Balmer Lawrie Online Monthly Bulletin
 
The Future of Brands on LinkedIn - Alison Kaltman
The Future of Brands on LinkedIn - Alison KaltmanThe Future of Brands on LinkedIn - Alison Kaltman
The Future of Brands on LinkedIn - Alison Kaltman
 
Unraveling the Mystery of the Hinterkaifeck Murders.pptx
Unraveling the Mystery of the Hinterkaifeck Murders.pptxUnraveling the Mystery of the Hinterkaifeck Murders.pptx
Unraveling the Mystery of the Hinterkaifeck Murders.pptx
 
Social Media Marketing PPT-Includes Paid media
Social Media Marketing PPT-Includes Paid mediaSocial Media Marketing PPT-Includes Paid media
Social Media Marketing PPT-Includes Paid media
 
Call Us ➥9654467111▻Call Girls In Delhi NCR
Call Us ➥9654467111▻Call Girls In Delhi NCRCall Us ➥9654467111▻Call Girls In Delhi NCR
Call Us ➥9654467111▻Call Girls In Delhi NCR
 
Aryabhata I, II of mathematics of both.pptx
Aryabhata I, II of mathematics of both.pptxAryabhata I, II of mathematics of both.pptx
Aryabhata I, II of mathematics of both.pptx
 
BDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 150 Noida Escorts >༒8448380779 Escort Service
 
Creator Influencer Strategy Master Class - Corinne Rose Guirgis
Creator Influencer Strategy Master Class - Corinne Rose GuirgisCreator Influencer Strategy Master Class - Corinne Rose Guirgis
Creator Influencer Strategy Master Class - Corinne Rose Guirgis
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...
VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...
VIP 7001035870 Find & Meet Hyderabad Call Girls Film Nagar high-profile Call ...
 
What is Google Search Console and What is it provide?
What is Google Search Console and What is it provide?What is Google Search Console and What is it provide?
What is Google Search Console and What is it provide?
 
How to Leverage Behavioral Science Insights for Direct Mail Success
How to Leverage Behavioral Science Insights for Direct Mail SuccessHow to Leverage Behavioral Science Insights for Direct Mail Success
How to Leverage Behavioral Science Insights for Direct Mail Success
 
Brighton SEO April 2024 - The Good, the Bad & the Ugly of SEO Success
Brighton SEO April 2024 - The Good, the Bad & the Ugly of SEO SuccessBrighton SEO April 2024 - The Good, the Bad & the Ugly of SEO Success
Brighton SEO April 2024 - The Good, the Bad & the Ugly of SEO Success
 
Moving beyond multi-touch attribution - DigiMarCon CanWest 2024
Moving beyond multi-touch attribution - DigiMarCon CanWest 2024Moving beyond multi-touch attribution - DigiMarCon CanWest 2024
Moving beyond multi-touch attribution - DigiMarCon CanWest 2024
 
Major SEO Trends in 2024 - Banyanbrain Digital
Major SEO Trends in 2024 - Banyanbrain DigitalMajor SEO Trends in 2024 - Banyanbrain Digital
Major SEO Trends in 2024 - Banyanbrain Digital
 
No Cookies No Problem - Steve Krull, Be Found Online
No Cookies No Problem - Steve Krull, Be Found OnlineNo Cookies No Problem - Steve Krull, Be Found Online
No Cookies No Problem - Steve Krull, Be Found Online
 
CALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Hazratganj Lucknow best sexual service Online
 
Factors-Influencing-Branding-Strategies.pptx
Factors-Influencing-Branding-Strategies.pptxFactors-Influencing-Branding-Strategies.pptx
Factors-Influencing-Branding-Strategies.pptx
 
How to Create a Social Media Plan Like a Pro - Jordan Scheltgen
How to Create a Social Media Plan Like a Pro - Jordan ScheltgenHow to Create a Social Media Plan Like a Pro - Jordan Scheltgen
How to Create a Social Media Plan Like a Pro - Jordan Scheltgen
 
BDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 128 Noida Escorts >༒8448380779 Escort Service
 

The Myths, Musts and Migraines of Migrations - DrupalJam 2018

  • 1. The MythsThe Myths**,, MustsMusts** and Migrainesand Migraines** of Migrationsof Migrations
  • 2. Marc van GendMarc van Gend @marcvangend
  • 3. Drupal Tech TalkDrupal Tech Talk April 26, ezCompany, TilburgApril 26, ezCompany, Tilburg
  • 4. Who are you?Who are you? Developers Project managers Site owners ("the client") None of the above * * * *
  • 5. QuizQuiz The key to a successful migration is... A. Good clean source data B. A committed, cooperating client C. Plenty of development time
  • 6. You were right! You were right!You were right! You were right! Everybody was right!Everybody was right!
  • 7. Non-Drupal to Drupal migrationsNon-Drupal to Drupal migrations Source - Process - Destination Setup My First Migration™ Source data Process plugins Project context Tips * * * * * * *
  • 10. SourceSource Database, File, URL... 1 result per migration item Defines unique Source ID * * * PHP: class MySourcePlugin extends SourcePluginBase Drupal Console: drupal generate:plugin:migrate:source {}
  • 11. ProcessProcess Get, Concat, MigrateLookup, custom... Assigns values to fields Chainable * * * PHP: class MyProcessPlugin extends ProcessPluginBase {} Drupal Console: drupal generate:plugin:migrate:process
  • 12. DestinationDestination Node, Term, User, Redirect, Setting, custom... Writes collected data to Drupal DB Can support rollback Maps Source ID -> Destination ID * * * * PHP: class MyDestinationPlugin extends DestinationBase {} Drupal Console: (nope)
  • 13. **MustMust The right toolsThe right tools Modules Tools Custom module Test site * * * *
  • 14. ModulesModules Migrate (core)Migrate (core) Migrate API and base functionality Continuous migrations with ID mapping Migrate PlusMigrate Plus Define migrations as config entities Additional plugins and enhancements Data parsers and authentication Examples Migrate ToolsMigrate Tools Drush commands and UI
  • 15. ToolsTools DrushDrush Import migration config Run migrations Rollback, reset, status, etc. Drupal ConsoleDrupal Console Create plugins Database managerDatabase manager PhpStorm, phpMyAdmin
  • 16. Custom moduleCustom module migrate_demo ├── migrate_demo.info.yml ├── config │ └── install │ ├── migrate_plus.migration.demo_node_article.yml │ └── migrate_plus.migration_group.demo.yml └── src └── Plugin └── migrate ├── process │ └── TitleCleanup.php └── source └── DemoNodeArticle.php
  • 17. Demo SiteDemo Site SourceSource Music database (Chinook): Artist ⪪ Album DrupalDrupal Artist: Title Album: Title, Artist, Release date, URL * *
  • 18. My First Migration™My First Migration™ Migrate Group Migration Go! * * *
  • 19. **MustMust Handwritten YAMLHandwritten YAML # Enough about you, let's talk about me! name: Marc favorites: music: dEUS beer: - IPA - Triple colleagues: - name: Dirk role: Support engineer - name: Joyce role: Drupal developer
  • 20. Migration groupsMigration groups Groups migrations (duh!) Import all migrations in group Shared configuration * * *
  • 21.
  • 22. Migration group configMigration group config migrate_demo/config/install/migrate_plus.migration_group.demo.yml id: demo label: Demo Imports description: A few demo imports, to demonstrate how to implement migrations. source_type: SQL database shared_configuration: source: key: migrate dependencies: enforced: module: - migrate_demo
  • 23. Migration source: DB settingsMigration source: DB settings settings.php $databases['migrate']['default'] = array ( 'database' => 'migrate_demo_source', 'username' => 'migrate_demo_source', 'password' => 'Secret!', 'prefix' => '', 'host' => '127.0.0.1', 'port' => '3306', 'namespace' => 'DrupalCoreDatabaseDrivermysql', 'driver' => 'mysql', );
  • 24. Migration source: source pluginMigration source: source plugin migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php /** * Source plugin for artist content. * * @MigrateSource( * id = "demo_node_artist" * ) */ class DemoNodeArtist extends SqlBase { migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
  • 25. /** * {@inheritdoc} */ public function query() { $query = $this->select('Artist', 'a') ->fields('a', [ 'ArtistId', 'Name', ]); return $query; } migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
  • 26. /** * {@inheritdoc} */ public function fields() { $fields = [ 'ArtistId' => $this->t('Artist ID'), 'Name' => $this->t('Artist name'), ]; return $fields; } migrate_demo/src/Plugin/migrate/source/DemoNodeArtist.php
  • 27. Migration configMigration config migrate_demo/config/install/migrate_plus.migration.demo_node_artist.yml id: demo_node_artist # Migration ID label: Artists # Human name migration_group: demo source: plugin: demo_node_artist # Data source process: title: Name # Use the 'Name' value as title type: plugin: default_value default_value: artist # Node type is 'artist' destination: plugin: entity:node # Save as a node
  • 28. **MustMust Importing your configImporting your config $ drush config-import --partial --source=modules/custom/migrate_demo/config/install
  • 29. Go!Go! Or use the UI: $ drush migrate-import demo_node_artist
  • 30. Source dataSource data Human interaction. Where things get messy.
  • 31. **MythMyth “The data is clean and complete”“The data is clean and complete” **MigraineMigraine Believe me. It's not.Believe me. It's not.
  • 32. Getting the dataGetting the data How can we access the data? Direct access? Export? API? How do we get updates? How o en? Incremental? With timestamps? How about assets like PDF's and images? What size are we talking about? Number of items, GB's of files Make some friends at the supplier's side.Make some friends at the supplier's side. * * * * * * * * *
  • 33. Analyze the provided dataAnalyze the provided data Ask the most stupid questions you can think of. What does it all mean? Does everything have a unique, unchanging ID? Do users have unique email addresses? Do all articles have titles? Are records being added and deleted? Yes ⇒ Are unique ID's reused? Does the data contain duplicates? No ⇒ Really? Did you check? Do not assume people know their own data.Do not assume people know their own data. * * * * * * * *
  • 34. Start planningStart planning Make choices Don't spend 4h automating what takes 8h manually Agree what you will (not) do Have the result tested Functional Content Write a plan for the go-live Content freeze Pick dates Instruct editors * * * * * * * * * *
  • 35. **MythMyth Migrations are SimpleMigrations are Simple (I know. I said migrations are straight-forward.) Prepare to write custom processors.
  • 36. (psst, don't forget to start the demo)
  • 37. Processors are AwesomeProcessors are Awesome Default process plugin: Get “Get the 'Name' property from the current row and use it as title” process: title: Name Shorthand for: process: title: plugin: get source: Name
  • 38. Processors can haveProcessors can have configurationconfiguration process: type: # Entity type plugin: default_value # Plugin ID default_value: album # Fixed value In the plugin: $this->configuration['default_value']; // Returns "album".
  • 39. Linking migrations togetherLinking migrations together The migration_lookup process plugin “Get the ID of the entity which was created when demo_node_artist imported this ArtistID.” process: field_artist: # Entity reference field plugin: migration_lookup migration: demo_node_artist # Linked migration ID source: ArtistId # Source ID
  • 40. Chaining process pluginsChaining process plugins process: uid: - plugin: author_deduplicate # Custom deduplication processor source: author_id - plugin: migration_lookup # Migration Lookup returns a UID migration: users # No 'source' property, because chaining! - plugin: default_value # Result is passed to the next processor default_value: 44 # If empty, use UID 44
  • 41. A custom processorA custom processor migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php /** * Retrieves album info through the Spotify Web API. * * @MigrateProcessPlugin( * id = "spotify_info", * ) */ class SpotifyInfo extends ProcessPluginBase { migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
  • 42. /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executabl $type = $this->configuration['type']; $query_info = $this->getSpotifyQueryInfo($value, $type); $spotify_result = $this->spotifyQuery($query_info['query'], $type); $property = $this->configuration['property']; $data_path = array_merge($query_info['parents'], explode('][', $property)); return NestedArray::getValue($spotify_result, $data_path); } migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
  • 43. protected function getSpotifyQueryInfo($value, $type) { switch ($type) { case 'album': // Expect $value to be an array: [album title, artist name]. list($title, $artist) = $value; $query = "album:$title artist:$artist"; $parents = ['albums', 'items', 0]; break; } if (empty($query)) { throw new MigrateSkipProcessException('Could not build a query.'); } return ['query' => $query, 'parents' => $parents]; } migrate_demo/src/Plugin/migrate/process/SpotifyInfo.php
  • 44. A custom processor: configA custom processor: config process: field_release_date: plugin: spotify_info source: - Title - ArtistName type: album property: release_date field_spotify_url/uri: # Link fields are composed of multiple values plugin: spotify_info source: - Title - ArtistName type: album property: external_urls][spotify # Will be split into an array
  • 45. **MigraineMigraine A migration never comes aloneA migration never comes alone If everything was perfect, there wouldn't be a migration, right?
  • 46. Client goalsClient goals What they say What it means New site New URL's New design An image on every node New navigation Revised categories New workflow Different input filters ...and the existing content will magically fit in.
  • 47. Complexity = changes²Complexity = changes² Reduce the number of changes introduced with the migration. Spotify process plugin = A really bad idea
  • 48. **MustMust Start earlyStart early Adapt your site to old content and future needs. Migrate early, keep importing. Estimate generously. Double it.
  • 49. Tips & tricksTips & tricks (If we have time) Save time: performanceSave time: performance Disable search indexing Run migrations with Drush * *
  • 50. Save time: reduced datasetSave time: reduced dataset Imports approximately 1 in every 100 items. settings.local.php $settings['my_migration_reduce_factor'] = 100; mySourcePlugin::query() $reduce_factor = Settings::get('my_migration_reduce_factor'); if ($reduce_factor && is_int($reduce_factor)) { $query->where('MOD(a.id, :reduce_factor) = 0', [':reduce_factor' => $reduce_factor]); }
  • 51. Manual edits... now what?Manual edits... now what? Run a migration on selected fields: overwrite_properties ignores all values except explicitly listed. destination: plugin: 'entity:node' overwrite_properties: - category
  • 52. Shortcut: entity_generateShortcut: entity_generate No rollbacks, no mappings, no nothing. Great for things that don't have a source ID. process: tags: - plugin: explode source: keywords # Eg. "Foo,Bar,Baz" delimiter: ',' # Explode comma separated string to array - plugin: entity_generate # Generate taxonomy terms that don't exist
  • 53. Come for the software,Come for the software, stay for the communitystay for the community Thank you:Thank you: Audience | Sponsors | LimoenGroen | Drupal Community