3. Переваги модуля migrate:
• Будь-яке джерело даних (SQL, XML, JSON, CSV)
• Можливість корегувати дані при міграції
• Можливість зробити rollback після імпорту
• Статистика по кожній міграції
• Можливість вказувати залежність міграцій одна від одної
• Інтеграція з drush
• Міграція підчас інсталяції
3
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)
26. • Для міграції Drupal 6 → Drupal 8 можна використати модуль upgrade або drush
• для інших лише drush
26
Як запустити міграцію?
27. Містить плагіни для міграції основних компонентів Drupal 6/7, таких як, контент типи,
поля, користувачі, ноди, таксономія та інші.
27
Migrate Drupal
Лише Drupal 6 на даний момент