SlideShare una empresa de Scribd logo
1 de 33
Migrate API Drupal 7/8 1
Майхер Володимир
EPAM Systems
Модуль migrate
2
Переваги модуля migrate:
• Будь-яке джерело даних (SQL, XML, JSON, CSV)
• Можливість корегувати дані при міграції
• Можливість зробити rollback після імпорту
• Статистика по кожній міграції
• Можливість вказувати залежність міграцій одна від одної
• Інтеграція з drush
• Міграція підчас інсталяції
3
Архітектура модуля migrate:
• MigrateSource
• MigrateDestination
• MigrateMap
• MigrateFieldMapping
4
Архітектура модуля migrate:
5
Запуск міграції:
6
Migrate в Drupal 7
• Migrate_ui
• drush
7
migrate_ui
8
migrate_ui
migrate_ui 9
migrate_ui 10
migrate_ui 11
drush команди
drush migrate-fields-destination (mfd)
drush migrate-fields-source (mfs)
drush migrate-import (mi)
drush migrate-mappings (mm)
drush migrate-messages (mmsg)
drush migrate-reset-status (mrs)
drush migrate-rollback (mr)
drush migrate-status (ms)
drush migrate-stop (mst)
drush migrate-analyze (maz)
drush migrate-audit (ma)
drush migrate-register (mreg)
drush migrate-deregister
drush migrate-wipe (mw)
12
drush опції
--all
--idlist
--instrument
--limit
--stop
--update
13
Приклади використання з drush
• drush migrate-import BrandTerm – виконання міграції з машинною назвою “BrandTerm”
• drush migrate-import BrandTerm --update – імпортує нові елементи і оновлює існуючі
• drush migrate-import BrandTerm --idlist=4,9 – імпорт двох окремих елементів з id = 4 та id
= 9. Id беруться з таблиці мапінгу.
Більше на https://www.drupal.org/node/1561820.
14
Як створити міграцію? 15
galauto_migrate.module
galauto_migrate.migrate.inc
У файлі galauto_migrate.info
вказуємо звичну інформацію.
<?php
/**
* @file
* THIS SPACE INTENTIONALLY LEFT BLANK.
*/
<?php
/**
* Implements hook_migrate_api().
*/
function galauto_migrate_migrate_api() {
$api = array(
'api' => 2,
'migrations' => array(
'BrandTerm' => array('class_name' => 'BrandTermMigration'),
),
);
return $api;
}
Як створити міграцію? 16
brand.inc
<?php
class BrandTermMigration extends Migration {
public function __construct() {
parent::__construct();
Об`являємо клас
Як створити міграцію? 17
brand.inc Source об`єкт
$query = db_select('car_mark', 'mark')
->fields('mark', array('id_car_mark', 'name'));
$this->source = new MigrateSourceSQL($query);
Як створити міграцію? 18
brand.inc Source об`єкт
Source класи: • MigrateSourceSQL
• MigrateSourceList
• MigrateSourceMultiitems
• MigrateSourceXML
• MigrateSourceCSV
• MigrateSourceMSSQL
• MigrateSourceOracle
• MigrateSourceMongoDB
• MigrateListJSON and MigrateItemJSON
• MigrateListFile and MigrateItemFile
Як створити міграцію? 19
brand.inc Destination об`єкт
Destination класи: • MigrateDestinationRole
• MigrateDestinationUser
• MigrateDestinationTerm
• MigrateDestinationNode
• MigrateDestinationComment
• MigrateDestinationFile
• MigrateDestinationNodeRevision
• MigrateDestinationTable
$this->destination = new MigrateDestinationTerm('brands');
Як створити міграцію? 20
brand.inc Об`єкт мапінгу
Клас мапінгу: • MigrateSQLMap
$source_key_schema = array(
'id_car_mark' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
)
);
$this->map = new MigrateSQLMap($this->machineName, $source_key_schema,
MigrateDestinationTerm::getKeySchema());
Як створити міграцію? 21
brand.inc Мапінг полів
$this->addFieldMapping('name', 'name')
->description(t('The incoming name(source) field is the name of the term'));
$this->addFieldMapping('format')
->issueGroup(t('DNM'));
$this->addFieldMapping('weight')
->issueGroup(t('DNM'));
Як створити міграцію?
<?php
class BrandMigration extends Migration {
public function __construct() {
parent::__construct();
$this->description = t('Migrate car brands from the source database to taxonomy terms');
$source_key_schema = array(
'id_car_mark' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
)
);
$this->map = new MigrateSQLMap($this->machineName, $source_key_schema,
MigrateDestinationTerm::getKeySchema());
$query = db_select('car_mark', 'mark')
->fields('mark', array('id_car_mark', 'name'))
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationTerm('brands');
$this->addFieldMapping('name', 'name')
->description(t('The incoming name(source) field is the name of the term parent'));
$this->addFieldMapping('description')
->issueGroup(t('DNM'));
}
}
22
brand.inc
Додаткові методи 23
brand.inc
• function prepareRow($row)
• function prepare($entity, stdClass $row)
• function complete($entity, stdClass $row)
Migrate в Drupal 8 24
• Migrate
• Migrate Drupal
25
Міграція в ядрі
• Для міграції Drupal 6 → Drupal 8 можна використати модуль upgrade або drush
• для інших лише drush
26
Як запустити міграцію?
Містить плагіни для міграції основних компонентів Drupal 6/7, таких як, контент типи,
поля, користувачі, ноди, таксономія та інші.
27
Migrate Drupal
Лише Drupal 6 на даний момент
Для написання міграції обов`язково створити файли:
28
Migrating from Drupal 7
Migrating from Drupal 7 29
migrate.migration.custom_user.yml
Migrating from Drupal 7 30
User.php
Migrating from Drupal 7 31
manifest.yml
Для запуску міграції в консолі пишемо:
drush migrate-manifest <manifest-name> --legacy-db-url=mysql://<username>:<password>@<host>:<portno>/<db_name>
drush migrate-manifest manifest.yml --legacy-db-url=mysql://root:root@localhost/drupal7
Має знаходитись в корені Drupal
- custom_user
32
Запитання?
Дякую за увагу 
Skype: vmaikher
Email:
Volodymyr_Maykher@epam.com
33

Más contenido relacionado

Destacado

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Destacado (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Migrate api drupal 7&8

  • 1. Migrate API Drupal 7/8 1 Майхер Володимир EPAM Systems
  • 3. Переваги модуля migrate: • Будь-яке джерело даних (SQL, XML, JSON, CSV) • Можливість корегувати дані при міграції • Можливість зробити rollback після імпорту • Статистика по кожній міграції • Можливість вказувати залежність міграцій одна від одної • Інтеграція з drush • Міграція підчас інсталяції 3
  • 4. Архітектура модуля migrate: • MigrateSource • MigrateDestination • MigrateMap • MigrateFieldMapping 4
  • 6. Запуск міграції: 6 Migrate в Drupal 7 • Migrate_ui • drush
  • 12. drush команди drush migrate-fields-destination (mfd) drush migrate-fields-source (mfs) drush migrate-import (mi) drush migrate-mappings (mm) drush migrate-messages (mmsg) drush migrate-reset-status (mrs) drush migrate-rollback (mr) drush migrate-status (ms) drush migrate-stop (mst) drush migrate-analyze (maz) drush migrate-audit (ma) drush migrate-register (mreg) drush migrate-deregister drush migrate-wipe (mw) 12
  • 14. Приклади використання з drush • drush migrate-import BrandTerm – виконання міграції з машинною назвою “BrandTerm” • drush migrate-import BrandTerm --update – імпортує нові елементи і оновлює існуючі • drush migrate-import BrandTerm --idlist=4,9 – імпорт двох окремих елементів з id = 4 та id = 9. Id беруться з таблиці мапінгу. Більше на https://www.drupal.org/node/1561820. 14
  • 15. Як створити міграцію? 15 galauto_migrate.module galauto_migrate.migrate.inc У файлі galauto_migrate.info вказуємо звичну інформацію. <?php /** * @file * THIS SPACE INTENTIONALLY LEFT BLANK. */ <?php /** * Implements hook_migrate_api(). */ function galauto_migrate_migrate_api() { $api = array( 'api' => 2, 'migrations' => array( 'BrandTerm' => array('class_name' => 'BrandTermMigration'), ), ); return $api; }
  • 16. Як створити міграцію? 16 brand.inc <?php class BrandTermMigration extends Migration { public function __construct() { parent::__construct(); Об`являємо клас
  • 17. Як створити міграцію? 17 brand.inc Source об`єкт $query = db_select('car_mark', 'mark') ->fields('mark', array('id_car_mark', 'name')); $this->source = new MigrateSourceSQL($query);
  • 18. Як створити міграцію? 18 brand.inc Source об`єкт Source класи: • MigrateSourceSQL • MigrateSourceList • MigrateSourceMultiitems • MigrateSourceXML • MigrateSourceCSV • MigrateSourceMSSQL • MigrateSourceOracle • MigrateSourceMongoDB • MigrateListJSON and MigrateItemJSON • MigrateListFile and MigrateItemFile
  • 19. Як створити міграцію? 19 brand.inc Destination об`єкт Destination класи: • MigrateDestinationRole • MigrateDestinationUser • MigrateDestinationTerm • MigrateDestinationNode • MigrateDestinationComment • MigrateDestinationFile • MigrateDestinationNodeRevision • MigrateDestinationTable $this->destination = new MigrateDestinationTerm('brands');
  • 20. Як створити міграцію? 20 brand.inc Об`єкт мапінгу Клас мапінгу: • MigrateSQLMap $source_key_schema = array( 'id_car_mark' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ) ); $this->map = new MigrateSQLMap($this->machineName, $source_key_schema, MigrateDestinationTerm::getKeySchema());
  • 21. Як створити міграцію? 21 brand.inc Мапінг полів $this->addFieldMapping('name', 'name') ->description(t('The incoming name(source) field is the name of the term')); $this->addFieldMapping('format') ->issueGroup(t('DNM')); $this->addFieldMapping('weight') ->issueGroup(t('DNM'));
  • 22. Як створити міграцію? <?php class BrandMigration extends Migration { public function __construct() { parent::__construct(); $this->description = t('Migrate car brands from the source database to taxonomy terms'); $source_key_schema = array( 'id_car_mark' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ) ); $this->map = new MigrateSQLMap($this->machineName, $source_key_schema, MigrateDestinationTerm::getKeySchema()); $query = db_select('car_mark', 'mark') ->fields('mark', array('id_car_mark', 'name')) $this->source = new MigrateSourceSQL($query); $this->destination = new MigrateDestinationTerm('brands'); $this->addFieldMapping('name', 'name') ->description(t('The incoming name(source) field is the name of the term parent')); $this->addFieldMapping('description') ->issueGroup(t('DNM')); } } 22 brand.inc
  • 23. Додаткові методи 23 brand.inc • function prepareRow($row) • function prepare($entity, stdClass $row) • function complete($entity, stdClass $row)
  • 25. • Migrate • Migrate Drupal 25 Міграція в ядрі
  • 26. • Для міграції Drupal 6 → Drupal 8 можна використати модуль upgrade або drush • для інших лише drush 26 Як запустити міграцію?
  • 27. Містить плагіни для міграції основних компонентів Drupal 6/7, таких як, контент типи, поля, користувачі, ноди, таксономія та інші. 27 Migrate Drupal Лише Drupal 6 на даний момент
  • 28. Для написання міграції обов`язково створити файли: 28 Migrating from Drupal 7
  • 29. Migrating from Drupal 7 29 migrate.migration.custom_user.yml
  • 30. Migrating from Drupal 7 30 User.php
  • 31. Migrating from Drupal 7 31 manifest.yml Для запуску міграції в консолі пишемо: drush migrate-manifest <manifest-name> --legacy-db-url=mysql://<username>:<password>@<host>:<portno>/<db_name> drush migrate-manifest manifest.yml --legacy-db-url=mysql://root:root@localhost/drupal7 Має знаходитись в корені Drupal - custom_user
  • 33. Дякую за увагу  Skype: vmaikher Email: Volodymyr_Maykher@epam.com 33