Skip to content
Snippets Groups Projects
Commit 91ec35d5 authored by bcweaver's avatar bcweaver
Browse files

Adding 'migrate_tools' module (and upgrade 'migrate_plus')

parent c472ed27
No related branches found
No related tags found
No related merge requests found
Showing
with 653 additions and 239 deletions
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "549076b42f1930243fcc38aef6b64e85",
"content-hash": "1765d49ab9251383f8e8c2d4b540106a",
"packages": [
{
"name": "alchemy/zippy",
......@@ -4971,36 +4971,40 @@
},
{
"name": "drupal/migrate_plus",
"version": "2.0.0-beta2",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/migrate_plus",
"reference": "8.x-2.0-beta2"
"reference": "8.x-4.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/migrate_plus-8.x-2.0-beta2.zip",
"reference": "8.x-2.0-beta2",
"shasum": "0b29113a3c00c7ab3ba73e811da3450edca4c0bb"
"url": "https://ftp.drupal.org/files/projects/migrate_plus-8.x-4.0.zip",
"reference": "8.x-4.0",
"shasum": "63dad289defe8298aa5ca5e30062fe9761d19eca"
},
"require": {
"drupal/core": "^8.1"
"drupal/core": "^8.3"
},
"require-dev": {
"drupal/migrate_example_advanced_setup": "*",
"drupal/migrate_example_setup": "*"
},
"suggest": {
"ext-soap": "*",
"sainsburys/guzzle-oauth2-plugin": "3.0 required for the OAuth2 authentication plugin"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
"dev-4.x": "4.x-dev"
},
"drupal": {
"version": "8.x-2.0-beta2",
"datestamp": "1476307439",
"version": "8.x-4.0",
"datestamp": "1536264180",
"security-coverage": {
"status": "not-covered",
"message": "Beta releases are not covered by Drupal security advisories."
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
......@@ -5027,6 +5031,73 @@
"irc": "irc://irc.freenode.org/drupal-migrate"
}
},
{
"name": "drupal/migrate_tools",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/migrate_tools",
"reference": "8.x-4.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/migrate_tools-8.x-4.0.zip",
"reference": "8.x-4.0",
"shasum": "016dfb010df76723c5a6a447921fdccd3c885237"
},
"require": {
"drupal/core": "^8.3",
"drupal/migrate_plus": "^4"
},
"require-dev": {
"drupal/coder": "^8",
"drupal/migrate_source_csv": "^2.2"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-4.x": "4.x-dev"
},
"drupal": {
"version": "8.x-4.0",
"datestamp": "1535380084",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"drush": {
"services": {
"drush.services.yml": "^9"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "heddn",
"homepage": "https://www.drupal.org/user/1463982"
},
{
"name": "mikeryan",
"homepage": "https://www.drupal.org/user/4420"
},
{
"name": "moshe weitzman",
"homepage": "https://www.drupal.org/user/23"
}
],
"description": "Tools to assist in developing and running migrations.",
"homepage": "http://drupal.org/project/migrate_tools",
"support": {
"source": "http://cgit.drupalcode.org/migrate_tools",
"issues": "http://drupal.org/project/migrate_tools",
"irc": "irc://irc.freenode.org/drupal-migrate"
}
},
{
"name": "drupal/nice_menus",
"version": "1.0.0-beta2",
......
......@@ -5125,37 +5125,41 @@
},
{
"name": "drupal/migrate_plus",
"version": "2.0.0-beta2",
"version_normalized": "2.0.0.0-beta2",
"version": "4.0.0",
"version_normalized": "4.0.0.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/migrate_plus",
"reference": "8.x-2.0-beta2"
"reference": "8.x-4.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/migrate_plus-8.x-2.0-beta2.zip",
"reference": "8.x-2.0-beta2",
"shasum": "0b29113a3c00c7ab3ba73e811da3450edca4c0bb"
"url": "https://ftp.drupal.org/files/projects/migrate_plus-8.x-4.0.zip",
"reference": "8.x-4.0",
"shasum": "63dad289defe8298aa5ca5e30062fe9761d19eca"
},
"require": {
"drupal/core": "^8.1"
"drupal/core": "^8.3"
},
"require-dev": {
"drupal/migrate_example_advanced_setup": "*",
"drupal/migrate_example_setup": "*"
},
"suggest": {
"ext-soap": "*",
"sainsburys/guzzle-oauth2-plugin": "3.0 required for the OAuth2 authentication plugin"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
"dev-4.x": "4.x-dev"
},
"drupal": {
"version": "8.x-2.0-beta2",
"datestamp": "1476307439",
"version": "8.x-4.0",
"datestamp": "1536264180",
"security-coverage": {
"status": "not-covered",
"message": "Beta releases are not covered by Drupal security advisories."
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
......@@ -5183,6 +5187,75 @@
"irc": "irc://irc.freenode.org/drupal-migrate"
}
},
{
"name": "drupal/migrate_tools",
"version": "4.0.0",
"version_normalized": "4.0.0.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/migrate_tools",
"reference": "8.x-4.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/migrate_tools-8.x-4.0.zip",
"reference": "8.x-4.0",
"shasum": "016dfb010df76723c5a6a447921fdccd3c885237"
},
"require": {
"drupal/core": "^8.3",
"drupal/migrate_plus": "^4"
},
"require-dev": {
"drupal/coder": "^8",
"drupal/migrate_source_csv": "^2.2"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-4.x": "4.x-dev"
},
"drupal": {
"version": "8.x-4.0",
"datestamp": "1535380084",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"drush": {
"services": {
"drush.services.yml": "^9"
}
}
},
"installation-source": "dist",
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "heddn",
"homepage": "https://www.drupal.org/user/1463982"
},
{
"name": "mikeryan",
"homepage": "https://www.drupal.org/user/4420"
},
{
"name": "moshe weitzman",
"homepage": "https://www.drupal.org/user/23"
}
],
"description": "Tools to assist in developing and running migrations.",
"homepage": "http://drupal.org/project/migrate_tools",
"support": {
"source": "http://cgit.drupalcode.org/migrate_tools",
"issues": "http://drupal.org/project/migrate_tools",
"irc": "irc://irc.freenode.org/drupal-migrate"
}
},
{
"name": "drupal/nice_menus",
"version": "1.0.0-beta2",
......
......@@ -4,26 +4,69 @@ and additional functionality, as well as providing practical examples.
Extensions to base API
======================
* A Migration configuration entity is provided, enabling persistance of dynamic
migration configuration.
* A ConfigEntityDiscovery class is implemented which enables plugin configuration
to be based on configuration entities. This is fully general - it can be used
for any configuration entity type, not just migrations.
* A MigrationConfigEntityPluginManager class and corresponding
plugin.manager.config_entity_migration service is provided, to enable discovery
and instantiation of migration plugins based on the Migration configuration
entity.
migration configuration.
* A MigrationGroup configuration entity is provided, which enables migrations to
be organized in groups, and to maintain shared configuration in one place.
be organized in groups, and to maintain shared configuration in one place.
* A MigrateEvents::PREPARE_ROW event is provided to dispatch hook_prepare_row()
invocations as events.
invocations as events.
* A SourcePluginExtension class is provided, enabling one to define fields and
IDs for a source plugin via configuration rather than requiring PHP code.
IDs for a source plugin via configuration rather than requiring PHP code.
Plugin types
============
migrate_plus provides the following plugin types, for use with the url source
plugin.
* A data_parser type, for parsing different formats on behalf of the url source
plugin.
* A data_fetcher type, for fetching data to feed into a data_parser plugin.
* An authentication type, for adding authentication headers with the http
data_fetcher plugin.
Plugins
=======
* A Url source plugin is provided, implementing a common structure for
file-based data providers.
* XML and JSON fetchers and parsers for the Url source plugin are provided.
Process
-------
* The entity_lookup process plugin allows you to populate references to entities
which already exist in Drupal, whether they were migrated or not.
* The entity_generate process plugin extends entity_lookup to also create the
desired entity when it doesn't already exist.
* The file_blob process plugin supports creating file entities from blob data.
* The merge process plugin allows the merging of multiple arrays into a single
field.
* The skip_on_value process plugin allows you to skip a row, or a given field,
for specific source values.
Source
------
* A url source plugin is provided, implementing a common structure for
file-based data providers.
Data parsers
------------
* The xml parser plugin uses PHP's XMLReader interface to incrementally parse
XML files. This should be used for XML sources which are potentially very
large.
* The simple_xml parser plugin uses PHP's SimpleXML interface to fully parse
XML files. This should be used for XML sources where you need to be able to
use complex xpaths for your item selectors, or have to access elements outside
of the current item element via xpaths.
* The json parser plugin supports JSON sources.
* The soap parser plugin supports SOAP sources.
Data fetchers
-------------
* The file fetcher plugin works for most URLs regardless of protocol, as well as
local filesystems.
* The http fetcher plugin provides the ability to add headers to an HTTP
request (particularly through authentication plugins).
Authentication
--------------
* The basic authentication plugin provides HTTP Basic authentication.
* The digest authentication plugin provides HTTP Digest authentication.
* The oauth2 authentication plugin provides OAuth2 authentication over HTTP.
Examples
========
......
......@@ -17,5 +17,8 @@
"source": "https://cgit.drupalcode.org/migrate_plus"
},
"minimum-stability": "dev",
"require": {}
"suggest": {
"sainsburys/guzzle-oauth2-plugin": "3.0 required for the OAuth2 authentication plugin",
"ext-soap": "*"
}
}
......@@ -6,7 +6,6 @@ migrate_plugin:
plugin:
type: string
label: 'Plugin'
migrate_destination:
type: migrate_plugin
label: 'Destination'
......@@ -25,6 +24,35 @@ migrate_source:
constants:
type: ignore
label: 'Constants'
ids:
type: ignore
label: 'Source IDs schema definition for migrate mapping table'
urls:
type: sequence
label: 'URLs from which to fetch'
sequence:
type: string
data_fetcher_plugin:
type: string
label: 'Fetcher plugin'
data_parser_plugin:
type: string
label: 'Parser plugin'
fields:
type: ignore
label: Mapping of field names to selectors
function:
type: string
label: 'Function to call on the service'
parameters:
type: ignore
label: 'Parameters to pass to function on the service'
response_type:
type: string
label: 'Type of response; XML string, object or array'
item_selector:
type: string
label: 'XPath selector'
migrate_process:
type: migrate_plugin
......
......@@ -71,9 +71,9 @@ migrate_plus.process.get:
type: string
label: 'Source key'
migrate_plus.process.iterator:
migrate_plus.process.sub_process:
type: migrate_process
label: 'Iterator process'
label: 'Sub process'
mapping:
process:
type: ignore
......
......@@ -7,6 +7,15 @@ migrate_plus.migration.*:
id:
type: string
label: 'ID'
class:
type: string
label: 'Class'
field_plugin_method:
type: string
label: 'Field Plugin Method'
cck_plugin_method:
type: string
label: 'BC layer for Field Plugin Method'
migration_tags:
type: sequence
label: 'Migration Tags'
......
......@@ -22,12 +22,30 @@ STRUCTURE
---------
There are two primary components to this example:
1. Migration configuration, in the config/install directory. These YAML files
describe the migration process and provide the mappings from the source data
to Drupal's destination entities. The YAML file names are prefixed with
'migrate_plus.migration.' (because, reading from right to left, they define
"migration" configuration entities, and the configuration entity type is
defined by the "migrate_plus" module).
1. Migration configuration, in the migrations and config/install directories.
These YAML files describe the migration process and provide the mappings from
the source data to Drupal's destination entities. The difference between the
two possible directories:
a. Files in the migrations directory provide configuration directly for the
migration plugins. The filenames are of the form <migration ID>.yml. This
approach is recommended when your migration configuration is fully hardcoded
and does not need to be overridden (e.g., you don't need to change the URL to
a source web service through an admin UI). While developing migrations,
changes to these files require at most a 'drush cr' to load your changes.
b. Files in the config/install directory provide migration configuration as
configuration entities, and have names of the form
migrate_plus.migration.<migration ID>.yml ("migration" because they define
entities of the "migration" type, and "migrate_plus" because that is the
module which implements the "migration" type). Migrations defined in this way
may have their configuration modified (in particular, through a web UI) by
loading the configuration entity, modifying its configuration, and saving the
entity. When developing, to get edits to the .yml files in config/install to
take effect in active configuration, use the config_devel module.
Configuration in either type of file is identical - the only differences are
the directories and filenames.
2. Source plugins, in src/Plugin/migrate/source. These are referenced from the
configuration files, and provide the source data to the migration processing
......@@ -47,7 +65,7 @@ read the files in the following order:
5. BeerUser.php
6. migrate_plus.migration.beer_node.yml
7. BeerNode.php
8. migrate_plus.migration.beer_comment.yml
8. beer_comment.yml
9. BeerComment.php
RUNNING THE MIGRATIONS
......
......@@ -2,6 +2,8 @@
id: beer_node
label: Beers of the world
migration_group: beer
migration_tags:
- example
source:
plugin: beer_node
destination:
......@@ -14,7 +16,7 @@ process:
title: name
nid: bid
uid:
plugin: migration
plugin: migration_lookup
migration: beer_user
source: aid
sticky:
......@@ -22,7 +24,7 @@ process:
default_value: 0
field_migrate_example_country: countries
field_migrate_example_beer_style:
plugin: migration
plugin: migration_lookup
migration: beer_term
source: terms
# Some Drupal fields may have multiple components we may want to set
......
......@@ -12,6 +12,10 @@ label: Migrate style categories from the source database to taxonomy terms
# configuration to be merged with our own configuration here).
migration_group: beer
# The category or tag for the migration.
migration_tags:
- example
# Every migration must have a source plugin, which controls the delivery of our
# source data. In this case, our source plugin has the name "beer_term", which
# Drupal resolves to the PHP class defined in
......@@ -60,7 +64,7 @@ process:
# IDs in map tables, and the migration plugin is the means of performing a
# lookup in those map tables during processing.
parent:
plugin: migration
plugin: migration_lookup
# Here we reference the migration whose map table we're performing a lookup
# against. You'll note that in this case we're actually referencing this
# migration itself, since category parents are imported by the same
......
......@@ -4,6 +4,8 @@
id: beer_user
label: Beer Drinkers of the world
migration_group: beer
migration_tags:
- example
source:
plugin: beer_user
destination:
......@@ -90,7 +92,7 @@ process:
# when that migration runs it knows that each incoming beer should overwrite
# its stub instead of creating a new node.
field_migrate_example_favbeers:
plugin: migration
plugin: migration_lookup
source: beers
migration: beer_node
......
......@@ -4,12 +4,14 @@ description: 'Examples of how Drupal 8 migration compares to previous versions.'
package: Examples
# core: 8.x
dependencies:
- migrate
- migrate_example_setup
- migrate_plus
- drupal:migrate
- migrate_plus:migrate_example_setup
- migrate_plus:migrate_plus
- drupal:menu_ui
- drupal:path
# Information added by Drupal.org packaging script on 2016-08-05
version: '8.x-2.0-beta2'
# Information added by Drupal.org packaging script on 2018-09-06
version: '8.x-4.0'
core: '8.x'
project: 'migrate_plus'
datestamp: 1470428640
datestamp: 1536264189
......@@ -11,7 +11,6 @@ dependencies:
module:
- comment
- image
- path
- text
id: node.migrate_example_beer.default
targetEntityType: node
......@@ -58,11 +57,6 @@ content:
preview_image_style: thumbnail
third_party_settings: { }
type: image_image
path:
type: path
weight: 5
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
......
langcode: en
status: true
dependencies:
module:
- menu_ui
third_party_settings:
menu_ui:
available_menus:
- main
parent: 'main:'
name: Beer
type: migrate_example_beer
description: 'Beer is what we drink.'
......
......@@ -5,14 +5,14 @@ package: Migration
# core: 8.x
hidden: 1
dependencies:
- comment
- image
- text
- options
- taxonomy
- drupal:comment
- drupal:image
- drupal:text
- drupal:options
- drupal:taxonomy
# Information added by Drupal.org packaging script on 2016-08-05
version: '8.x-2.0-beta2'
# Information added by Drupal.org packaging script on 2018-09-06
version: '8.x-4.0'
core: '8.x'
project: 'migrate_plus'
datestamp: 1470428640
datestamp: 1536264189
......@@ -2,11 +2,16 @@
/**
* @file
* Install file for migrate example module.
*
* Set up source data and destination configuration for the migration example
* module. We do this in a separate module so migrate_example itself is a pure
* migration module.
*/
/**
* Implements hook_schema().
*/
function migrate_example_setup_schema() {
$schema['migrate_example_beer_account'] = migrate_example_beer_schema_account();
$schema['migrate_example_beer_node'] = migrate_example_beer_schema_node();
......@@ -17,6 +22,9 @@ function migrate_example_setup_schema() {
return $schema;
}
/**
* Implements hook_install().
*/
function migrate_example_setup_install() {
// Populate our tables.
migrate_example_beer_data_account();
......@@ -26,318 +34,467 @@ function migrate_example_setup_install() {
migrate_example_beer_data_topic_node();
}
/**
* The hook_schema definition for node.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_node() {
return array(
return [
'description' => 'Beers of the world.',
'fields' => array(
'bid' => array(
'fields' => [
'bid' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Beer ID.',
),
'name' => array(
],
'name' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'body' => array(
],
'body' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Full description of the beer.',
),
'excerpt' => array(
],
'excerpt' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Abstract for this beer.',
),
'countries' => array(
],
'countries' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Countries of origin. Multiple values, delimited by pipe',
),
'aid' => array(
],
'aid' => [
'type' => 'int',
'not null' => FALSE,
'description' => 'Account Id of the author.',
),
'image' => array(
],
'image' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Image path',
),
'image_alt' => array(
],
'image_alt' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Image ALT',
),
'image_title' => array(
],
'image_title' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Image title',
),
'image_description' => array(
],
'image_description' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Image description',
),
),
'primary key' => array('bid'),
);
],
],
'primary key' => ['bid'],
];
}
/**
* The hook_schema definition for topic.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_topic() {
return array(
return [
'description' => 'Categories',
'fields' => array(
'style' => array(
'fields' => [
'style' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
),
'details' => array(
],
'details' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'style_parent' => array(
],
'style_parent' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Parent topic, if any',
),
'region' => array(
],
'region' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Region first associated with this style',
),
'hoppiness' => array(
],
'hoppiness' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Relative hoppiness of the beer',
),
),
'primary key' => array('style'),
);
],
],
'primary key' => ['style'],
];
}
/**
* The hook_schema definition for topic node.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_topic_node() {
return array(
return [
'description' => 'Beers topic pairs.',
'fields' => array(
'bid' => array(
'fields' => [
'bid' => [
'type' => 'int',
'not null' => TRUE,
'description' => 'Beer ID.',
),
'style' => array(
],
'style' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'description' => 'Topic name',
),
),
'primary key' => array('style', 'bid'),
);
],
],
'primary key' => ['style', 'bid'],
];
}
/**
* The hook_schema definition for comment.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_comment() {
return array(
return [
'description' => 'Beers comments.',
'fields' => array(
'cid' => array(
'fields' => [
'cid' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Comment ID.',
),
'bid' => array(
],
'bid' => [
'type' => 'int',
'not null' => TRUE,
'description' => 'Beer ID that is being commented upon',
),
'cid_parent' => array(
],
'cid_parent' => [
'type' => 'int',
'not null' => FALSE,
'description' => 'Parent comment ID in case of comment replies.',
),
'subject' => array(
],
'subject' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Comment subject',
),
'body' => array(
],
'body' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Comment body',
),
'name' => array(
],
'name' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Comment name (if anon)',
),
'mail' => array(
],
'mail' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Comment email (if anon)',
),
'aid' => array(
],
'aid' => [
'type' => 'int',
'not null' => FALSE,
'description' => 'Account ID (if any).',
),
),
'primary key' => array('cid'),
);
],
],
'primary key' => ['cid'],
];
}
/**
* The hook_schema definition for account.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_account() {
return array(
return [
'description' => 'Beers accounts.',
'fields' => array(
'aid' => array(
'fields' => [
'aid' => [
'type' => 'serial',
//'not null' => TRUE,
'not null' => TRUE,
'description' => 'Account ID',
),
'status' => array(
],
'status' => [
'type' => 'int',
'not null' => TRUE,
'description' => 'Blocked_Allowed',
),
'registered' => array(
],
'registered' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Registration date',
),
'username' => array(
],
'username' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Account name (for login)',
),
'nickname' => array(
],
'nickname' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Account name (for display)',
),
'password' => array(
],
'password' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Account password (raw)',
),
'email' => array(
],
'email' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Account email',
),
'sex' => array(
],
'sex' => [
'type' => 'int',
'not null' => FALSE,
'description' => 'Gender (0 for male, 1 for female)',
),
'beers' => array(
],
'beers' => [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Favorite Beers',
),
),
'primary key' => array('aid'),
);
],
],
'primary key' => ['aid'],
];
}
/**
* Populate node table.
*/
function migrate_example_beer_data_node() {
$fields = array('bid', 'name', 'body', 'excerpt', 'countries', 'aid', 'image',
'image_alt', 'image_title', 'image_description');
$fields = [
'bid',
'name',
'body',
'excerpt',
'countries',
'aid',
'image',
'image_alt',
'image_title',
'image_description',
];
$query = db_insert('migrate_example_beer_node')
->fields($fields);
->fields($fields);
// Use high bid numbers to avoid overwriting an existing node id.
$data = array(
array(99999999, 'Heineken', 'Blab Blah Blah Green', 'Green', 'Netherlands|Belgium', 0, 'heineken.jpg', 'Heinekin alt', 'Heinekin title', 'Heinekin description'), // comes with migrate_example project.
array(99999998, 'Miller Lite', 'We love Miller Brewing', 'Tasteless', 'USA|Canada', 1, NULL, NULL, NULL, NULL),
array(99999997, 'Boddington', 'English occasionally get something right', 'A treat', 'United Kingdom', 1, NULL, NULL, NULL, NULL),
);
$data = [
// Comes with migrate_example project.
[
99999999,
'Heineken',
'Blab Blah Blah Green',
'Green',
'Netherlands|Belgium',
0,
'heineken.jpg',
'Heinekin alt',
'Heinekin title',
'Heinekin description',
],
[
99999998,
'Miller Lite',
'We love Miller Brewing',
'Tasteless',
'USA|Canada',
1,
NULL,
NULL,
NULL,
NULL,
],
[
99999997,
'Boddington',
'English occasionally get something right',
'A treat',
'United Kingdom',
1,
NULL,
NULL,
NULL,
NULL,
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
}
$query->execute();
}
// Note that alice has duplicate username. Exercises dedupe_entity plugin.
// @TODO duplicate email also.
/**
* Populate account table.
*
* Note that alice has duplicate username. Exercises dedupe_entity plugin.
* TODO duplicate email also.
*/
function migrate_example_beer_data_account() {
$fields = array('status', 'registered', 'username', 'nickname', 'password', 'email', 'sex', 'beers');
$fields = [
'status',
'registered',
'username',
'nickname',
'password',
'email',
'sex',
'beers',
];
$query = db_insert('migrate_example_beer_account')
->fields($fields);
$data = array(
array(1, '2010-03-30 10:31:05', 'alice', 'alice in beerland', 'alicepass', 'alice@example.com', '1', '99999999|99999998|99999997'),
array(1, '2010-04-04 10:31:05', 'alice', 'alice in aleland', 'alicepass', 'alice2@example.com', '1', '99999999|99999998|99999997'),
array(0, '2007-03-15 10:31:05', 'bob', 'rebob', 'bobpass', 'bob@example.com', '0', '99999999|99999997'),
array(1, '2004-02-29 10:31:05', 'charlie', 'charlie chocolate', 'mykids', 'charlie@example.com', '0', '99999999|99999998'),
);
$data = [
[
1,
'2010-03-30 10:31:05',
'alice',
'alice in beerland',
'alicepass',
'alice@example.com',
'1',
'99999999|99999998|99999997',
],
[
1,
'2010-04-04 10:31:05',
'alice',
'alice in aleland',
'alicepass',
'alice2@example.com',
'1',
'99999999|99999998|99999997',
],
[
0,
'2007-03-15 10:31:05',
'bob',
'rebob',
'bobpass',
'bob@example.com',
'0',
'99999999|99999997',
],
[
1,
'2004-02-29 10:31:05',
'charlie',
'charlie chocolate',
'mykids',
'charlie@example.com',
'0',
'99999999|99999998',
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
}
$query->execute();
}
/**
* Populate comment table.
*/
function migrate_example_beer_data_comment() {
$fields = array('bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid');
$fields = ['bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid'];
$query = db_insert('migrate_example_beer_comment')
->fields($fields);
$data = array(
array(99999998, NULL, 'im first', 'full body', 'alice', 'alice@example.com', 0),
array(99999998, NULL, 'im second', 'aromatic', 'alice', 'alice@example.com', 0),
array(99999999, NULL, 'im parent', 'malty', 'alice', 'alice@example.com', 0),
array(99999999, 1, 'im child', 'cold body', 'bob', NULL, 1),
array(99999999, 4, 'im grandchild', 'bitter body', 'charlie@example.com', NULL, 1),
);
$data = [
[99999998, NULL, 'im first', 'full body', 'alice', 'alice@example.com', 0],
[99999998, NULL, 'im second', 'aromatic', 'alice', 'alice@example.com', 0],
[99999999, NULL, 'im parent', 'malty', 'alice', 'alice@example.com', 0],
[99999999, 1, 'im child', 'cold body', 'bob', NULL, 1],
[
99999999,
4,
'im grandchild',
'bitter body',
'charlie@example.com',
NULL,
1,
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
}
$query->execute();
}
/**
* Populate topic table.
*/
function migrate_example_beer_data_topic() {
$fields = array('style', 'details', 'style_parent', 'region', 'hoppiness');
$fields = ['style', 'details', 'style_parent', 'region', 'hoppiness'];
$query = db_insert('migrate_example_beer_topic')
->fields($fields);
$data = array(
array('ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'),
array('red ale', 'colorful', 'ale', NULL, NULL),
array('pilsner', 'refreshing', NULL, 'Pilsen, Bohemia (now Czech Republic)', 'Low'),
);
$data = [
['ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'],
['red ale', 'colorful', 'ale', NULL, NULL],
[
'pilsner',
'refreshing',
NULL,
'Pilsen, Bohemia (now Czech Republic)',
'Low',
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
}
$query->execute();
}
/**
* Populate topic node table.
*/
function migrate_example_beer_data_topic_node() {
$fields = array('bid', 'style');
$fields = ['bid', 'style'];
$query = db_insert('migrate_example_beer_topic_node')
->fields($fields);
$data = array(
array(99999999, 'pilsner'),
array(99999999, 'red ale'),
array(99999998, 'red ale'),
);
$data = [
[99999999, 'pilsner'],
[99999999, 'red ale'],
[99999998, 'red ale'],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
}
......
......@@ -8,11 +8,11 @@ destination:
plugin: entity:comment
process:
pid:
plugin: migration
plugin: migration_lookup
migration: beer_comment
source: cid_parent
entity_id:
plugin: migration
plugin: migration_lookup
migration: beer_node
source: bid
entity_type:
......@@ -26,7 +26,7 @@ process:
default_value: node_comments
subject: subject
uid:
plugin: migration
plugin: migration_lookup
migration: beer_user
source: aid
name: name
......
......@@ -17,10 +17,19 @@ class BeerComment extends SqlBase {
* {@inheritdoc}
*/
public function query() {
$fields = [
'cid',
'cid_parent',
'name',
'mail',
'aid',
'body',
'bid',
'subject',
];
$query = $this->select('migrate_example_beer_comment', 'mec')
->fields('mec', ['cid', 'cid_parent', 'name', 'mail', 'aid',
'body', 'bid', 'subject'])
->orderBy('cid_parent', 'ASC');
->fields('mec', $fields)
->orderBy('cid_parent', 'ASC');
return $query;
}
......
......@@ -18,21 +18,29 @@ class BeerNode extends SqlBase {
* {@inheritdoc}
*/
public function query() {
/**
* An important point to note is that your query *must* return a single row
* for each item to be imported. Here we might be tempted to add a join to
* migrate_example_beer_topic_node in our query, to pull in the
* relationships to our categories. Doing this would cause the query to
* return multiple rows for a given node, once per related value, thus
* processing the same node multiple times, each time with only one of the
* multiple values that should be imported. To avoid that, we simply query
* the base node data here, and pull in the relationships in prepareRow()
* below.
*/
// An important point to note is that your query *must* return a single row
// for each item to be imported. Here we might be tempted to add a join to
// migrate_example_beer_topic_node in our query, to pull in the
// relationships to our categories. Doing this would cause the query to
// return multiple rows for a given node, once per related value, thus
// processing the same node multiple times, each time with only one of the
// multiple values that should be imported. To avoid that, we simply query
// the base node data here, and pull in the relationships in prepareRow()
// below.
$fields = [
'bid',
'name',
'body',
'excerpt',
'aid',
'countries',
'image',
'image_alt',
'image_title',
'image_description',
];
$query = $this->select('migrate_example_beer_node', 'b')
->fields('b', ['bid', 'name', 'body', 'excerpt', 'aid',
'countries', 'image', 'image_alt', 'image_title',
'image_description']);
->fields('b', $fields);
return $query;
}
......@@ -76,13 +84,11 @@ public function getIds() {
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
/**
* As explained above, we need to pull the style relationships into our
* source row here, as an array of 'style' values (the unique ID for
* the beer_term migration).
*/
// As explained above, we need to pull the style relationships into our
// source row here, as an array of 'style' values (the unique ID for
// the beer_term migration).
$terms = $this->select('migrate_example_beer_topic_node', 'bt')
->fields('bt', ['style'])
->fields('bt', ['style'])
->condition('bid', $row->getSourceProperty('bid'))
->execute()
->fetchCol();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment