migrate - new way site upgrade

14

Click here to load reader

Upload: drupalcampdn

Post on 08-May-2015

177 views

Category:

Internet


0 download

DESCRIPTION

Рассмотрим сам фреймворк, определим основные юзкейсы использования, базовые требования для использования, а так же посмотрим на код на примере миграции Drupal 7 - Drupal 7. Думаю так же доклад будет интересен для всех, кто планирует использовать будущий релиз Drupal, ввиду того, что Migrate частично мигрировал в ядро и будет инструментом по умолчанию для апгрейда не только с 7 версии, но и с 6(возможно даже с 5!!!).

TRANSCRIPT

Page 1: Migrate - new way site upgrade

25 -27 April, 2014 http://camp2014.drupal.dn.ua

Migrate - new way site upgrade

Kirill Roskoliy

Email: [email protected]: https://drupal.org/user/325151

Trellon, LLC

Page 2: Migrate - new way site upgrade

WHAT IS THIS ALL ABOUT:

1. How it was and how it will be2. Migrate structure3. Use cases4. Requirements5. Examples

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 3: Migrate - new way site upgrade

How it was and how it will be

•In place upgrade - Drupal 7.x =<•Migrate way

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 4: Migrate - new way site upgrade

In place upgrade

This is standard upgrade path in Drupal 7 and previous. What does it mean? Lets take a closer look:1. We need to stage current site

1. Code2. DB3. Files4. Done some pre-upgrade configuration

2. Put in place upgraded code1. Remove old one2. Put new

3. Start update.php4. Pray that everything will go well, no? - Go to #15. Profit

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 5: Migrate - new way site upgrade

Migrate way of upgrade

1.No direct pruduction site modifications2.Build new version of your site3.Migrate4.Issues ? - Go to #25.Profit

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 6: Migrate - new way site upgrade

Migrate module architecture

● Migration○ MigrateSource○ MigrateDestination○ MigrateMap○ MigrateFieldMapping

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 7: Migrate - new way site upgrade

Use cases

● Major version upgrade● Site structure redesign● Migration from other CMS● Migration from static HTML● Initial data import

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 8: Migrate - new way site upgrade

Requerments

Sources:● DB access● Files access

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 9: Migrate - new way site upgrade

Example: Content type migration 1

<?phpclass SomeArticlesMigration extends DrupalNode7Migration {

public function __construct($arguments) { $files_path = $arguments['source_domain_root'] . '/sites/default/files'; $this->description = t('Import article nodes.');

// Pulling extra fields to source row. $this->sourceFields['field_tags'] = 'Tags for the article'; $this->sourceFields['field_image'] = 'Header Image'; $this->sourceFields['field_multi_images_upload'] = 'Multi images upload'; $this->sourceFields['field_article_comment_header'] = 'Comment Header'; $this->sourceFields['field_juicebox_gallery'] = 'Juicebox Gallery'; $this->sourceFields['field_embed_map'] = 'Embed Map'; $this->sourceFields['field_map_location'] = 'Map Location';

parent::__construct($arguments);

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 10: Migrate - new way site upgrade

Example: Content type migration 2

// Field mappings. // Field field_tags. $this->addFieldMapping('field_tags', 'field_tags'); $this->addFieldMapping('field_tags:source_type')->defaultValue('tid'); $this->addFieldMapping('field_tags:create_term')->defaultValue(TRUE); $this->addFieldMapping('field_tags:ignore_case')->defaultValue(TRUE);

// Field field_image. $this->addFieldMapping('field_image', 'field_image'); $this->addFieldMapping('field_image:file_class')->defaultValue(‘SomeArticleImages’); $this->addFieldMapping('field_image:source_dir')->defaultValue($files_path . '/field/image/'); $this->addFieldMapping('field_image:destination_dir')->defaultValue('public://field/image/'); $this->addFieldMapping('field_image:file_replace')->defaultValue(FILE_EXISTS_REPLACE); $this->addFieldMapping('field_image:preserve_files')->defaultValue(FALSE); $this->addFieldMapping('field_image:alt', 'field_image:alt');

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 11: Migrate - new way site upgrade

Example: Content type migration 3

// Field field_article_comment_header - simple text field. $this->addFieldMapping('field_article_comment_header', 'field_article_comment_header');

// Field field_embed_map - boolean field. $this->addFieldMapping('field_embed_map', 'field_embed_map');

// Field field_map_location - geofield. $this->addFieldMapping('field_map_location', 'field_map_location'); $this->addFieldMapping('field_map_location:lng', 'field_map_location:lng')

->callbacks('coconuts_migrate_map_location_lng');; }

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 12: Migrate - new way site upgrade

Example: Content type migration 4

/** * Limit selecting nodes only to those assigned to specified source domain. * @return QueryConditionInterface * Modified $query object. */ protected function query() { $query = parent::query(); $source_domain_id = (int) $this->arguments['source_domain_id']; $query->join('domain_access', 'da', 'da.nid = n.nid'); // Limit nodes to source domain and to those for ALL domains(gid == 0). $query->condition('da.gid', array(0, $source_domain_id)); return $query; } protected function preImport() { $some_dummy_code_here = TRUE; }}

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 13: Migrate - new way site upgrade

Example: Helper class to migrate images

<?phpclass SomeArticleImages extends MigrateFileUri { public function __construct($arguments = array(), $default_file = NULL) { parent::__construct($arguments, $default_file); } public function processFile($value, $owner) { $filename = Database::getConnection('default', SOME_MIGRATE_CONNECTION_KEY) ->select('file_managed', 'f') ->fields('f', array('filename')) ->condition('fid', $value) ->execute() ->fetchField();

return parent::processFile($filename, $owner); }}

25 -27 April, 2014 http://camp2014.drupal.dn.ua/

Page 14: Migrate - new way site upgrade

THANK YOU!

Questions?

Kirill Roskoliy

Email: [email protected]: https://drupal.org/user/325151

Trellon, LLC