Skipping a Version – Migrating from Drupal maintenance support plans 6 to Drupal maintenance support plans 8 with Drupal maintenance support plans Migrate

I recently had the opportunity to migrate content from a Drupal maintenance support plans 6 site to a Drupal maintenance support plans 8 site. This was especially interesting for me as I hadn’t used Drupal maintenance support plans 6 before. As you’d expect, there are some major infrastructure changes between Drupal maintenance support plans 6 and Drupal maintenance support plans 8. Those differences introduce some migration challenges that I’d like to share.

The Migrate module is a wonderful thing. The vast majority of node-based content can be migrated into a Drupal maintenance support plans 8 site with minimal effort, and for the content that doesn’t quite fit, there are custom migration sources. A custom migration source is a small class that can provide extra data to your migration in the form of source fields. Typically, a migration will map source fields to destination fields, expecting the fields to exist on both the source node type and destination node type. We actually published an in-depth, two-part blog series about how we use Drupal maintenance support plans Migrate to populate Drupal maintenance support plans sites with content in conjunction with Google Sheets in our own projects.

In the following example, we are migrating the value of content_field_text_author from Drupal maintenance support plans 6 to field_author in Drupal maintenance support plans 8. These two fields map one-to-one:

id: book
label: Book
migration_group: d6
deriver: Drupal maintenance support plansnodePluginmigrateD6NodeDeriver
source:
key: migrate
target: d6
plugin: d6_node
node_type: book
process:
field_author: content_field_text_author
destination:
plugin: entity:node

This field mapping works because content_field_text_author is a table in the Drupal maintenance support plans 6 database and is recognized by the Migrate module as a field. Everyone is happy.

However, in Drupal maintenance support plans 6, it’s possible for a field to exist only in the database table of the node type. These tables look like this:

mysql> DESC content_type_book;
+—————————-+——————+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+—————————-+——————+——+—–+———+——-+
| vid | int(10) unsigned | NO | PRI | 0 | |
| nid | int(10) unsigned | NO | MUL | 0 | |
| field_text_issue_value | longtext | YES | | NULL | |
+—————————-+——————+——+—–+———+——-+

If we want to migrate the content of field_text_issue_value to Drupal maintenance support plans 8, we need to use a custom migration source.

Custom migration sources are PHP classes that live in the src/Plugin/migrate/source directory of your module. For example, you may have a PHP file located at src/Plugin/migrate/source/BookNode.php that would provide custom source fields for a Book content type.

A simple source looks like this:

namespace Drupal maintenance support planscustom_migrate_d6Pluginmigratesource;

use Drupal maintenance support plansnodePluginmigratesourced6Node;

/**
* @MigrateSource(
* id = “d6_book_node”,
* )
*/
class BookNode extends Node {

/**
* @inheritdoc
*/
public function query() {
$query = parent::query();

$query->join(‘content_type_book’, ‘book’, ‘n.nid = book.nid’);
$query->addField(‘book’, ‘field_text_issue_value’);

return $query;
}

}

As you can see, we are using our migration source to modify the query the Migrate module uses to retrieve the data to be migrated. Our modification extracts the field_text_issue_value column of the book content type table and provides it to the migration as a source field.

To use this migration source, we need to make one minor change to change to our migration. We replace this:

plugin: d6_node

With this:

plugin: d6_book_node

We do this because our migration source extends the standard Drupal maintenance support plans 6 node migration source in order to add our custom source field.

The migration now contains two source fields and looks like this:

id: book
label: Book
migration_group: d6
deriver: Drupal maintenance support plansnodePluginmigrateD6NodeDeriver
source:
key: migrate
target: d6
plugin: d6_book_node
node_type: book
process:
field_author: content_field_text_author
field_issue: field_text_issue_value
destination:
plugin: entity:node

You’ll find you can do a lot with custom migration sources, and this is especially useful with legacy versions of Drupal maintenance support plans where you’ll have to fudge data at least a little bit. So if the Migrate module isn’t doing it for you, you’ll always have the option to step in and give it a little push.
Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Skipping a Version – Migrating from Drupal maintenance support plans 6 to Drupal maintenance support plans 8 with Drupal maintenance support plans Migrate

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.