8 2 x
play

8.2.x DATA TO DRUPAL 8 Ready! about.me Ignacio Snchez Drupal - PowerPoint PPT Presentation

MIGRATING 8.2.x DATA TO DRUPAL 8 Ready! about.me Ignacio Snchez Drupal developer @ @isholgueras nacho@bluespark.com drupal.org/u/isholgueras http://www.isholgueras.com STEPS 1. Requirements 2. Anatomy of a migration 3. Migration


  1. MIGRATING 8.2.x DATA TO DRUPAL 8 Ready!

  2. about.me Ignacio Sánchez Drupal developer @ @isholgueras nacho@bluespark.com drupal.org/u/isholgueras http://www.isholgueras.com

  3. STEPS 1. Requirements 2. Anatomy of a migration 3. Migration Framework 4. Performance tips

  4. 1. REQUIREMENTS

  5. 1. Migrate is in core! REQUIREMENTS Three new modules ▸ Migrate Handles migrations. Framework. ▸ Migrate Drupal Contains migrations from D6 & D7. ▸ Migrate Drupal UI The older migrate update (new in 8.1.x).

  6. 1. Migrate is in core! REQUIREMENTS But … how can I execute my migration. UI is not ready? No Drush command?

  7. 1. REQUIREMENTS So... Contrib!

  8. 1. Needed REQUIREMENTS ▸ Drupal 8.1.x (or superior) ▸ Drush 8 ▸ Migrate tools (contrib) ▸ Migrate Plus (contrib)

  9. 2. ANATOMY OF A MIGRATION

  10. 2. Workflow ANATOMY OF A MIGRATION PROCESS SOURCE DESTINATION PROCESS PROCESS

  11. 2. 2. In files ANATOMY OF ANATOMY OF A MIGRATION A MIGRATION DEFINITIONS PLUGINS PHP Files Yaml Files. Custom files Core or custom files Types: - Source - Process - Destination - Builder - ID Map

  12. 2. ANATOMY OF A MIGRATION The easiest example

  13. 2. DEFINITION ANATOMY OF config/install/migrate_plus.migration.article_node.yml A MIGRATION id: article_node label: Migrate posts from CakePHP to Drupal 8 source: plugin: article_node key: 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 migration_dependencies: {} #new in 8.1.x

  14. 2. PLUGINS ANATOMY OF src/Plugin/migrate/source/ArticleNode.php A MIGRATION <?php namespace .. use .. /** public function fields() { * Source plugin for article content. $fields = [ * 'id' => $this->t("Article ID"), * @MigrateSource( // ... * id = "article_node" ]; * ) return $fields; */ } class ArticleNode extends SqlBase { public function getIds() { return [ public function query() { 'id' => [ $query = $this->select('articles','a') 'type' => 'integer', ->fields('a', [ 'alias' => 'a', 'id', ], 'user_id', ]; 'title', } 'description', } 'created', ]); return $query; }

  15. 2. CONFIGURATION ANATOMY OF sites/local/settings.php A MIGRATION <?php $databases['legacy']['default'] = array( 'database' => 'old_app', 'username' => 'dev', 'password' => 'dev', 'prefix' => '', 'host' => 'localhost', 'port' => '3306', 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', 'driver' => 'mysql', );

  16. 2. EXECUTION ANATOMY OF Only with Drush8 (8.1-dev) and migrate_tools enabled 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; drush8 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; drush8 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

  17. 2. ANATOMY OF Too easy! A MIGRATION

  18. 3. MIGRATION FRAMEWORK

  19. 3. 0.- KNOWLEDGE MIGRATION Most FRAMEWORK Source Plugin: - SqlBase used Process Plugin: - ProcessPluginBase Destination Plugin: - DestinationBase More plugins in: core/modules/migrate/src/Plugin/migrate

  20. 3. 1.- SOURCE MIGRATION FRAMEWORK Here we tell SqlBase: - Which Database is the Source . #migrate_plus.migration.article_node.yml source: plugin: article_node key: legacy #target: default #settings.php //By default [‘default’][‘migration’] $databases['legacy']['default'] = array( // key target

  21. 3. 1.- SOURCE MIGRATION - And which Plugin will make the Query FRAMEWORK <?php public function fields() { namespace Drupal\cm_migrate\Plugin\migrate\source; $fields = [ use ... 'id' => $this->t("Article ID"), /** // ... * @MigrateSource( ]; * id = "article_node" return $fields; * ) } */ public function getIds() { class ArticleNode extends SqlBase { return [ 'id' => [ public function query() { 'type' => 'integer', $query = $this->select('articles', 'a') 'alias' => 'a', ->fields('a', [ ], 'id', ]; 'user_id', } 'title', public function prepareRow(Row $row) { 'description', $id = $row->getSourceProperty('id'); 'created', $row->setSourceProperty('user_id', 1); ]); return parent::prepareRow($row); return $query; } } }

  22. 3. 2.- DESTINATION MIGRATION FRAMEWORK How and where to store the data #migrate_plus.migration.article_node.yml destination: plugin: entity:node - entity:<place-here-an-entity>

  23. 3. 2.- DESTINATION MIGRATION FRAMEWORK Need more destination plugins? Search for “ destination: ” in core

  24. 3. 3.- ID MAPPING MIGRATION FRAMEWORK How Migrate associates old rows with new rows. public function getIds() { return [ 'id' => [ 'type' => 'string', 'alias' => 'u', ], ]; }

  25. 3. 4.- PROCESS MIGRATION FRAMEWORK How we transform each field, each file or data. You are able to: - Map fields : Same value as origin. - Modify : Change or process the value. - Add : Create new fields from other fields or calculate these fields.

  26. 3. 4.- PROCESS MIGRATION FRAMEWORK Map fields . Values are equal in both sides public function query() { $query = $this ->select('articles', 'a') ->fields('a', [ #common mapping 'created', process: ---> 'title', title: title <--- 'id', 'body', 'user_id', ]); return $query; }

  27. 3. 4.- PROCESS MIGRATION FRAMEWORK DefaultValue . Add a default value public function query() { $query = $this #default value ->select('articles', 'a') process: ->fields('a', [ type: 'created', plugin: default_value 'title', default_value: article 'id', 'body/format': 'body', plugin: default_value 'user_id', default_value: plain_text ]); return $query; }

  28. 3. 4.- PROCESS MIGRATION FRAMEWORK Callable . Values are related but a process is needed with a function public function query() { #'Callable.php' core plugin $query = $this process: ->select('articles', 'a') ->fields('a', [ created: 'created_date', plugin: callback 'title', source: created_date 'id', 'body', callable: strtotime 'user_id', ]); return $query; }

  29. 3. 4.- PROCESS MIGRATION FRAMEWORK DedupeEntity . Values in destination cannot be equal, but in origin could be. public function query() { # DedupeEntity.php' core $query = $this # plugin ->select('users', 'u') process: ->fields('u', [ name: 'user_id', plugin: dedupe_entity 'user_name', source: user_name 'mail', entity_type: user ]); field: name return $query; postfix: _ } # admin_1, _2, ...

  30. 3. 4.- PROCESS MIGRATION FRAMEWORK Migration . Values from another migration. Use it! PLEASE! # ArticleNode.php # Migration as plugin public function query() { process: $query = $this field_tags: ->select('articles', 'a') plugin: migration ->fields('a', [ migration: tags_node 'created_date', source: terms fields() 'title', migration_dependencies: 'id', required: 'body', - tags_node 'user_id', ]); return $query; }

  31. 3. 4.- PROCESS MIGRATION FRAMEWORK Migration . Values from another migration. # ArticleNode.php # ArticleNode.php public function fields() { public function prepareRow(Row $row) { $fields = [ $terms = $this->select('terms') 'terms' => //... $this->t("New field terms"), ->fetchCol(); // ... $row->setSourceProperty('terms', ]; $terms); return $fields; return parent::prepareRow($row); } } }

  32. 3. 4.- PROCESS MIGRATION FRAMEWORK Migration . Values from another migration. # TagsNode.php #migrate_plus.migration.tags_node public function query() { .yml // code source: ->fields('terms', [ plugin: tags_node 'parent_term', destination: 'term']); plugin: entity:taxonomy_term } process: name: term parent: plugin: migration migration: tags_node source: parent_term

  33. 3. 4.- PROCESS MIGRATION FRAMEWORK CustomPlugins . We need to copy some files public function query() { #CustomFiles.php' custom plugin $query = $this destination: ->select('files', 'f') plugin: entity:file ->fields('f', [ process: 'id', fid: id 'post_id', filename: name 'name', uri: 'path', plugin: custom_file_uri 'dir', source: ]); - path return $query; - name }

Recommend


More recommend