D6-D8 migration: How did we migrate Drupal 6 Nodewords: D6 Meta Tags (nodewords module) to Drupal 8 Metatag
In Drupal 6, we use Nodewords: D6 Meta Tags module to have meta tags attached to Content. Currently Drupal 8 Metatag module doesn't support migration of meta tags from Drupal 6 content to Drupal 8 content.
We used following steps to migrate the meta tags from D6 to D8 site:
1) Firstly we setup the D6 site by enabling contributed Nodewords module along with it's sub module Nodewords basic meta tags. These two modules provided support for adding meta tags information in all the available content types. Our D6 site looks like below after we added content in Page content type along with meta tags information,
2) Next we setup D8 site and enabled Metatag module.
3) Next we enabled Drupal Upgrade and Migrate Tools contrib modules for the migration,
8) We copied config/migrate.migration.d6_node__page.yml, it was created by 'drush config-export' command above, to config/install/ folder,
9) Next we added hook_migrate_prepare_row() in our migrate_d6_metatag_custom.module file. The code looks like below,
This will fetch the meta tags information from D6 database based on the current record (node id) being processed. After getting the data, it's being unserialized and finally being assigned to 'field_metatag'. This field or variable 'field_metatag' will be used by process plugin to convert the D6 nodewords data into D8 meta tags format.
10) The code in process plugin, Nodewords.php, looks like below,
As per field mapping in step 8 and then assigning the meta tags data to 'field_metatag' in step 9, process plugin will get D6 meta tags information (stored in 'field_metatag') in '$value' variable. This code converts the D6 meta tags data into D8 meta tags format.
11) Finally we enabled our custom module and executed the migration,
Page migration depends upon 'd6_filter_format', 'd6_node_type', 'd6_user_role' and 'd6_user' migrations so we executed them first.
You can also run complete migration by passing '--all' option to migrate-import drush command,
After the migration, D8 site contains meta tags information for the given content and looks like below,
The custom module is hosted on Github - https://github.com/amitgoyal/migrate_d6_metatag_custom
You can find more information on how to execute Drupal upgrade using Drush command here - https://www.drupal.org/node/2350651
We used following steps to migrate the meta tags from D6 to D8 site:
1) Firstly we setup the D6 site by enabling contributed Nodewords module along with it's sub module Nodewords basic meta tags. These two modules provided support for adding meta tags information in all the available content types. Our D6 site looks like below after we added content in Page content type along with meta tags information,
2) Next we setup D8 site and enabled Metatag module.
drush en metatag -yWe added Metatag field (field_metatag) of field type 'Meta tags' in Page content type so that we can migrate D6 metatag information in Page content type to this field. You have to add 'Meta tags' type field in the content types if you want to associate meta tags information with the content.
3) Next we enabled Drupal Upgrade and Migrate Tools contrib modules for the migration,
drush en migrate_upgrade migrate_tools -y4) This was optional step. We specified $config_directories variable in settings.php,
$config_directories['sync'] = 'config';5) To generate the migrations for our site, we passed --configure-only option to migrate-upgrade drush command. As it indicates, our D6 site is hosted at http://d6.local:8083 and database name is d6.
drush migrate-upgrade --configure-only --legacy-db-url=mysql://drupaluser:@127.0.0.1:33067/d6 --legacy-root=http://d6.local:80836) To export the generated migrations in above step to 'config' folder on file system,
drush config-export sync7) We created one custom module, migrate_d6_metatag_custom, with the following files/folders,
8) We copied config/migrate.migration.d6_node__page.yml, it was created by 'drush config-export' command above, to config/install/ folder,
cp config/migrate.migration.d6_node__page.yml modules/custom/migrate_d6_metatag_custom/config/install/migrate.migration.d6_node__page_custom.ymlWe changed the 'id' to 'd6_node__page_custom' and added Metatag field mapping like below,
field_metatag:d6_nodewords is a process plugin which will convert the D6 nodewords data into D8 meta tags format.
plugin: d6_nodewords
source: field_metatag
9) Next we added hook_migrate_prepare_row() in our migrate_d6_metatag_custom.module file. The code looks like below,
This will fetch the meta tags information from D6 database based on the current record (node id) being processed. After getting the data, it's being unserialized and finally being assigned to 'field_metatag'. This field or variable 'field_metatag' will be used by process plugin to convert the D6 nodewords data into D8 meta tags format.
10) The code in process plugin, Nodewords.php, looks like below,
As per field mapping in step 8 and then assigning the meta tags data to 'field_metatag' in step 9, process plugin will get D6 meta tags information (stored in 'field_metatag') in '$value' variable. This code converts the D6 meta tags data into D8 meta tags format.
11) Finally we enabled our custom module and executed the migration,
drush en migrate_d6_metatag_custom -y
drush migrate-import d6_filter_format
drush migrate-import d6_node_type
drush migrate-import d6_user_role
drush migrate-import d6_user
drush migrate-import d6_node__page_custom
Page migration depends upon 'd6_filter_format', 'd6_node_type', 'd6_user_role' and 'd6_user' migrations so we executed them first.
You can also run complete migration by passing '--all' option to migrate-import drush command,
drush migrate-import --all
After the migration, D8 site contains meta tags information for the given content and looks like below,
The custom module is hosted on Github - https://github.com/amitgoyal/migrate_d6_metatag_custom
You can find more information on how to execute Drupal upgrade using Drush command here - https://www.drupal.org/node/2350651





Comments