際際滷

際際滷Share a Scribd company logo
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

More Related Content

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