updated contrib modules

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-13 14:16:18 +01:00
parent e668535a4e
commit 272fa07ccf
202 changed files with 5165 additions and 1725 deletions
@@ -65,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
@@ -10,8 +10,8 @@ dependencies:
- drupal:menu_ui
- drupal:path
# Information added by Drupal.org packaging script on 2017-12-12
version: '8.x-4.0-beta2'
# Information added by Drupal.org packaging script on 2018-02-23
version: '8.x-4.0-beta3'
core: '8.x'
project: 'migrate_plus'
datestamp: 1513088305
datestamp: 1519400598
@@ -11,8 +11,8 @@ dependencies:
- drupal:options
- drupal:taxonomy
# Information added by Drupal.org packaging script on 2017-12-12
version: '8.x-4.0-beta2'
# Information added by Drupal.org packaging script on 2018-02-23
version: '8.x-4.0-beta3'
core: '8.x'
project: 'migrate_plus'
datestamp: 1513088305
datestamp: 1519400598
@@ -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,6 +34,12 @@ 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 [
'description' => 'Beers of the world.',
@@ -92,6 +106,12 @@ function migrate_example_beer_schema_node() {
];
}
/**
* The hook_schema definition for topic.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_topic() {
return [
'description' => 'Categories',
@@ -129,6 +149,12 @@ function migrate_example_beer_schema_topic() {
];
}
/**
* The hook_schema definition for topic node.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_topic_node() {
return [
'description' => 'Beers topic pairs.',
@@ -149,6 +175,12 @@ function migrate_example_beer_schema_topic_node() {
];
}
/**
* The hook_schema definition for comment.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_comment() {
return [
'description' => 'Beers comments.',
@@ -202,6 +234,12 @@ function migrate_example_beer_schema_comment() {
];
}
/**
* The hook_schema definition for account.
*
* @return array
* The schema definition.
*/
function migrate_example_beer_schema_account() {
return [
'description' => 'Beers accounts.',
@@ -262,16 +300,63 @@ function migrate_example_beer_schema_account() {
];
}
/**
* Populate node table.
*/
function migrate_example_beer_data_node() {
$fields = ['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);
// Use high bid numbers to avoid overwriting an existing node id.
$data = [
[99999999, 'Heineken', 'Blab Blah Blah Green', 'Green', 'Netherlands|Belgium', 0, 'heineken.jpg', 'Heinekin alt', 'Heinekin title', 'Heinekin description'], // comes with migrate_example project.
[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],
// 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));
@@ -280,18 +365,65 @@ function migrate_example_beer_data_node() {
}
/**
* Populate account table.
*
* Note that alice has duplicate username. Exercises dedupe_entity plugin.
*@TODO duplicate email also.
* TODO duplicate email also.
*/
function migrate_example_beer_data_account() {
$fields = ['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 = [
[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'],
[
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));
@@ -299,6 +431,9 @@ function migrate_example_beer_data_account() {
$query->execute();
}
/**
* Populate comment table.
*/
function migrate_example_beer_data_comment() {
$fields = ['bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid'];
$query = db_insert('migrate_example_beer_comment')
@@ -308,7 +443,15 @@ function migrate_example_beer_data_comment() {
[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],
[
99999999,
4,
'im grandchild',
'bitter body',
'charlie@example.com',
NULL,
1,
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
@@ -316,6 +459,9 @@ function migrate_example_beer_data_comment() {
$query->execute();
}
/**
* Populate topic table.
*/
function migrate_example_beer_data_topic() {
$fields = ['style', 'details', 'style_parent', 'region', 'hoppiness'];
$query = db_insert('migrate_example_beer_topic')
@@ -323,7 +469,13 @@ function migrate_example_beer_data_topic() {
$data = [
['ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'],
['red ale', 'colorful', 'ale', NULL, NULL],
['pilsner', 'refreshing', NULL, 'Pilsen, Bohemia (now Czech Republic)', 'Low'],
[
'pilsner',
'refreshing',
NULL,
'Pilsen, Bohemia (now Czech Republic)',
'Low',
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
@@ -331,6 +483,9 @@ function migrate_example_beer_data_topic() {
$query->execute();
}
/**
* Populate topic node table.
*/
function migrate_example_beer_data_topic_node() {
$fields = ['bid', 'style'];
$query = db_insert('migrate_example_beer_topic_node')
@@ -17,9 +17,18 @@ 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'])
->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,11 +84,9 @@ class BeerNode extends SqlBase {
* {@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'])
->condition('bid', $row->getSourceProperty('bid'))
@@ -5,11 +5,12 @@ namespace Drupal\migrate_example\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
/**
* This is an example of a simple SQL-based source plugin. Source plugins are
* classes which deliver source data to the processing pipeline. For SQL
* sources, the SqlBase class provides most of the functionality needed - for
* a specific migration, you are required to implement the three simple public
* methods you see below.
* This is an example of a simple SQL-based source plugin.
*
* Source plugins are classes which deliver source data to the processing
* pipeline. For SQL sources, the SqlBase class provides most of the
* functionality needed - for a specific migration, you are required to
* implement the three simple public methods you see below.
*
* This annotation tells Drupal that the name of the MigrateSource plugin
* implemented by this class is "beer_term". This is the name that the migration
@@ -25,16 +26,15 @@ class BeerTerm extends SqlBase {
* {@inheritdoc}
*/
public function query() {
/**
* The most important part of a SQL source plugin is the SQL query to
* retrieve the data to be imported. Note that the query is not executed
* here - the migration process will control execution of the query. Also
* note that it is constructed from a $this->select() call - this ensures
* that the query is executed against the database configured for this
* source plugin.
*/
// The most important part of a SQL source plugin is the SQL query to
// retrieve the data to be imported. Note that the query is not executed
// here - the migration process will control execution of the query. Also
// note that it is constructed from a $this->select() call - this ensures
// that the query is executed against the database configured for this
// source plugin.
$fields = ['style', 'details', 'style_parent', 'region', 'hoppiness'];
return $this->select('migrate_example_beer_topic', 'met')
->fields('met', ['style', 'details', 'style_parent', 'region', 'hoppiness'])
->fields('met', $fields)
// We sort this way to ensure parent terms are imported first.
->orderBy('style_parent', 'ASC');
}
@@ -43,12 +43,10 @@ class BeerTerm extends SqlBase {
* {@inheritdoc}
*/
public function fields() {
/**
* This method simply documents the available source fields provided by
* the source plugin, for use by front-end tools. It returns an array keyed
* by field/column name, with the value being a translated string explaining
* to humans what the field represents. You should always
*/
// This method simply documents the available source fields provided by the
// source plugin, for use by front-end tools. It returns an array keyed by
// field/column name, with the value being a translated string explaining
// to humans what the field represents.
$fields = [
'style' => $this->t('Beer style'),
'details' => $this->t('Style details'),
@@ -66,14 +64,12 @@ class BeerTerm extends SqlBase {
* {@inheritdoc}
*/
public function getIds() {
/**
* This method indicates what field(s) from the source row uniquely identify
* that source row, and what their types are. This is critical information
* for managing the migration. The keys of the returned array are the field
* names from the query which comprise the unique identifier. The values are
* arrays indicating the type of the field, used for creating compatible
* columns in the map tables that track processed items.
*/
// This method indicates what field(s) from the source row uniquely identify
// that source row, and what their types are. This is critical information
// for managing the migration. The keys of the returned array are the field
// names from the query which comprise the unique identifier. The values are
// arrays indicating the type of the field, used for creating compatible
// columns in the map tables that track processed items.
return [
'style' => [
'type' => 'string',
@@ -18,9 +18,19 @@ class BeerUser extends SqlBase {
* {@inheritdoc}
*/
public function query() {
$fields = [
'aid',
'status',
'registered',
'username',
'nickname',
'password',
'email',
'sex',
'beers',
];
return $this->select('migrate_example_beer_account', 'mea')
->fields('mea', ['aid', 'status', 'registered', 'username', 'nickname',
'password', 'email', 'sex', 'beers']);
->fields('mea', $fields);
}
/**
@@ -58,27 +68,22 @@ class BeerUser extends SqlBase {
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
/**
* prepareRow() is the most common place to perform custom run-time
* processing that isn't handled by an existing process plugin. It is called
* when the raw data has been pulled from the source, and provides the
* opportunity to modify or add to that data, creating the canonical set of
* source data that will be fed into the processing pipeline.
*
* In our particular case, the list of a user's favorite beers is a pipe-
* separated list of beer IDs. The processing pipeline deals with arrays
* representing multi-value fields naturally, so we want to explode that
* string to an array of individual beer IDs.
*/
// A prepareRow() is the most common place to perform custom run-time
// processing that isn't handled by an existing process plugin. It is called
// when the raw data has been pulled from the source, and provides the
// opportunity to modify or add to that data, creating the canonical set of
// source data that will be fed into the processing pipeline.
// In our particular case, the list of a user's favorite beers is a pipe-
// separated list of beer IDs. The processing pipeline deals with arrays
// representing multi-value fields naturally, so we want to explode that
// string to an array of individual beer IDs.
if ($value = $row->getSourceProperty('beers')) {
$row->setSourceProperty('beers', explode('|', $value));
}
/**
* Always call your parent! Essential processing is performed in the base
* class. Be mindful that prepareRow() returns a boolean status - if FALSE
* that indicates that the item being processed should be skipped. Unless
* we're deciding to skip an item ourselves, let the parent class decide.
*/
// Always call your parent! Essential processing is performed in the base
// class. Be mindful that prepareRow() returns a boolean status - if FALSE
// that indicates that the item being processed should be skipped. Unless
// we're deciding to skip an item ourselves, let the parent class decide.
return parent::prepareRow($row);
}
@@ -8,8 +8,8 @@ dependencies:
- migrate_plus:migrate_example_advanced_setup
- migrate_plus:migrate_plus
# Information added by Drupal.org packaging script on 2017-12-12
version: '8.x-4.0-beta2'
# Information added by Drupal.org packaging script on 2018-02-23
version: '8.x-4.0-beta3'
core: '8.x'
project: 'migrate_plus'
datestamp: 1513088305
datestamp: 1519400598
@@ -2,20 +2,20 @@
/**
* @file
* Install, update and uninstall functions for the migrate_example_advanced module.
* Install, update and uninstall functions for migrate_example_advanced module.
*/
use Drupal\migrate_plus\Entity\Migration;
/**
* Implements hook_install().
*
* We need the urls to be absolute for the XML source plugin to read them, but
* the static configuration files on disk can't know the server and port to
* use. So, in the .yml files we provide the REST resources relative to the
* site root and here rewrite them to fully-qualified paths.
*/
function migrate_example_advanced_install() {
// We need the urls to be absolute for the XML source plugin to read them, but
// the static configuration files on disk can't know the server and port to
// use. So, in the .yml files we provide the REST resources relative to the
// site root and here rewrite them to fully-qualified paths.
/** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_xml_migration */
$wine_role_xml_migration = Migration::load('wine_role_xml');
if ($wine_role_xml_migration) {
@@ -11,8 +11,8 @@ dependencies:
- drupal:taxonomy
- drupal:rest
# Information added by Drupal.org packaging script on 2017-12-12
version: '8.x-4.0-beta2'
# Information added by Drupal.org packaging script on 2018-02-23
version: '8.x-4.0-beta3'
core: '8.x'
project: 'migrate_plus'
datestamp: 1513088305
datestamp: 1519400598
@@ -55,6 +55,12 @@ function migrate_example_advanced_setup_install() {
migrate_example_advanced_data_table_source();
}
/**
* The hook_schema definition for wine.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_wine() {
return [
'description' => 'Wines of the world',
@@ -123,6 +129,12 @@ function migrate_example_advanced_schema_wine() {
];
}
/**
* The hook_schema definition for updates.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_updates() {
return [
'description' => 'Updated wine ratings',
@@ -144,6 +156,12 @@ function migrate_example_advanced_schema_updates() {
];
}
/**
* The hook_schema definition for producer.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_producer() {
return [
'description' => 'Wine producers of the world',
@@ -182,6 +200,12 @@ function migrate_example_advanced_schema_producer() {
];
}
/**
* The hook_schema definition for categories.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_categories() {
return [
'description' => 'Categories',
@@ -225,6 +249,12 @@ function migrate_example_advanced_schema_categories() {
];
}
/**
* The hook_schema definition for vintages.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_vintages() {
return [
'description' => 'Wine vintages',
@@ -245,6 +275,12 @@ function migrate_example_advanced_schema_vintages() {
];
}
/**
* The hook_schema definition for variety updates.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_variety_updates() {
return [
'description' => 'Variety updates',
@@ -265,6 +301,12 @@ function migrate_example_advanced_schema_variety_updates() {
];
}
/**
* The hook_schema definition for category wine.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_category_wine() {
return [
'description' => 'Wine category assignments',
@@ -285,6 +327,12 @@ function migrate_example_advanced_schema_category_wine() {
];
}
/**
* The hook_schema definition for category producer.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_category_producer() {
return [
'description' => 'Producer category assignments',
@@ -305,6 +353,12 @@ function migrate_example_advanced_schema_category_producer() {
];
}
/**
* The hook_schema definition for comment.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_comment() {
return [
'description' => 'Wine comments',
@@ -386,6 +440,12 @@ function migrate_example_advanced_schema_comment() {
];
}
/**
* The hook_schema definition for comment updates.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_comment_updates() {
return [
'description' => 'Wine comment updates',
@@ -407,6 +467,12 @@ function migrate_example_advanced_schema_comment_updates() {
];
}
/**
* The hook_schema definition for account.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_account() {
return [
'description' => 'Wine accounts.',
@@ -492,6 +558,12 @@ function migrate_example_advanced_schema_account() {
];
}
/**
* The hook_schema definition for account updates.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_account_updates() {
return [
'description' => 'Wine account updates',
@@ -512,6 +584,12 @@ function migrate_example_advanced_schema_account_updates() {
];
}
/**
* The hook_schema definition for blobs.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_blobs() {
return [
'description' => 'Wine blobs to be migrated to file entities',
@@ -532,6 +610,12 @@ function migrate_example_advanced_schema_blobs() {
];
}
/**
* The hook_schema definition for files.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_files() {
return [
'description' => 'Wine and account files',
@@ -571,6 +655,12 @@ function migrate_example_advanced_schema_files() {
];
}
/**
* The hook_schema definition for table source.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_table_source() {
return [
'description' => 'Source data to go into a custom Drupal table',
@@ -598,6 +688,12 @@ function migrate_example_advanced_schema_table_source() {
];
}
/**
* The hook_schema definition for table destination.
*
* @return array
* The schema definition.
*/
function migrate_example_advanced_schema_table_dest() {
return [
'description' => 'Custom Drupal table to receive source data directly',
@@ -625,16 +721,49 @@ function migrate_example_advanced_schema_table_dest() {
];
}
/**
* Populate wine table.
*/
function migrate_example_advanced_data_wine() {
$fields = ['wineid', 'name', 'body', 'excerpt', 'accountid',
'posted', 'last_changed', 'variety', 'region', 'rating'];
$fields = [
'wineid',
'name',
'body',
'excerpt',
'accountid',
'posted',
'last_changed',
'variety',
'region',
'rating',
];
$query = db_insert('migrate_example_wine')
->fields($fields);
$data = [
[1, 'Montes Classic Cabernet Sauvignon', 'Intense ruby-red color', 'Great!', 9,
strtotime('2010-01-02 03:04:05'), strtotime('2010-03-04 05:06:07'), 25, 17, 95],
[2, 'Archeo Ruggero di Tasso Nero d\'Avola', 'Lots of berry character', 'Pair with red sauced dishes', 3,
strtotime('2010-09-03 18:23:58'), strtotime('2010-09-03 18:23:58'), 26, 2, 85],
[
1,
'Montes Classic Cabernet Sauvignon',
'Intense ruby-red color',
'Great!',
9,
strtotime('2010-01-02 03:04:05'),
strtotime('2010-03-04 05:06:07'),
25,
17,
95,
],
[
2,
'Archeo Ruggero di Tasso Nero d\'Avola',
'Lots of berry character',
'Pair with red sauced dishes',
3,
strtotime('2010-09-03 18:23:58'),
strtotime('2010-09-03 18:23:58'),
26,
2,
85,
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
@@ -642,6 +771,9 @@ function migrate_example_advanced_data_wine() {
$query->execute();
}
/**
* Populate updates table.
*/
function migrate_example_advanced_data_updates() {
$fields = ['wineid', 'rating'];
$query = db_insert('migrate_example_advanced_updates')
@@ -656,6 +788,9 @@ function migrate_example_advanced_data_updates() {
$query->execute();
}
/**
* Populate producer table.
*/
function migrate_example_advanced_data_producer() {
$fields = ['producerid', 'name', 'body', 'excerpt', 'accountid'];
$query = db_insert('migrate_example_advanced_producer')
@@ -670,21 +805,73 @@ function migrate_example_advanced_data_producer() {
$query->execute();
}
/**
* Populate account table.
*/
function migrate_example_advanced_data_account() {
$fields = ['accountid', 'status', 'posted', 'last_access', 'last_login',
'name', 'sex', 'password', 'mail', 'original_mail', 'sig', 'imageid', 'positions'];
$fields = [
'accountid',
'status',
'posted',
'last_access',
'last_login',
'name',
'sex',
'password',
'mail',
'original_mail',
'sig',
'imageid',
'positions',
];
$query = db_insert('migrate_example_advanced_account')
->fields($fields);
$data = [
[1, 1, '2010-03-30 10:31:05', '2010-04-30 18:25:24', '2010-04-30 14:01:02',
'darren', 'M', 'dpass', 'ddarren@example.com', 'darren@example.com',
'All about the Australians', NULL, '5'],
[3, 0, '2007-03-15 10:31:05', '2007-06-10 04:11:38', '2007-06-10 04:11:38',
'emily', 'F', 'insecure', 'emily@example.com', 'emily@example.com',
'Sommelier to the stars', NULL, '18'],
[9, 1, '2004-02-29 10:31:05', '2004-02-29 10:31:05', '2004-02-29 10:31:05',
'fonzie', NULL, 'bike', 'thefonz@example.com', 'arthur@example.com',
'Aaay!', 1, '5,18'],
[
1,
1,
'2010-03-30 10:31:05',
'2010-04-30 18:25:24',
'2010-04-30 14:01:02',
'darren',
'M',
'dpass',
'ddarren@example.com',
'darren@example.com',
'All about the Australians',
NULL,
'5',
],
[
3,
0,
'2007-03-15 10:31:05',
'2007-06-10 04:11:38',
'2007-06-10 04:11:38',
'emily',
'F',
'insecure',
'emily@example.com',
'emily@example.com',
'Sommelier to the stars',
NULL,
'18',
],
[
9,
1,
'2004-02-29 10:31:05',
'2004-02-29 10:31:05',
'2004-02-29 10:31:05',
'fonzie',
NULL,
'bike',
'thefonz@example.com',
'arthur@example.com',
'Aaay!',
1,
'5,18',
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
@@ -692,6 +879,9 @@ function migrate_example_advanced_data_account() {
$query->execute();
}
/**
* Populate account updates table.
*/
function migrate_example_advanced_data_account_updates() {
$fields = ['accountid', 'sex'];
$query = db_insert('migrate_example_advanced_account_updates')
@@ -707,27 +897,97 @@ function migrate_example_advanced_data_account_updates() {
$query->execute();
}
/**
* Populate comment table.
*/
function migrate_example_advanced_data_comment() {
$fields = ['commentid', 'wineid', 'comment_parent', 'subject', 'body',
'name', 'mail', 'accountid', 'commenthost', 'userpage', 'posted', 'lastchanged'];
$fields = [
'commentid',
'wineid',
'comment_parent',
'subject',
'body',
'name',
'mail',
'accountid',
'commenthost',
'userpage',
'posted',
'lastchanged',
];
$query = db_insert('migrate_example_advanced_comment')
->fields($fields);
$data = [
[1, 1, NULL, 'im first', 'Tasty', 'grace', 'grace@example.com', 0,
'123.456.78.9', 'http:://grace.example.com/',
strtotime('2010-01-02 03:04:05'), strtotime('2010-04-05 06:07:08')],
[2, 1, NULL, 'im second', 'Delicious', 'horace', 'horace@example.com', 0,
'example.com', NULL,
strtotime('2010-02-02 03:04:05'), strtotime('2010-05-05 06:07:08')],
[3, 1, NULL, 'im parent', 'Don\'t care for it', 'irene', 'irene@example.com', 0,
'254.0.2.5', 'http:://www.example.com/irene',
strtotime('2010-03-02 03:04:05'), strtotime('2010-03-02 03:04:05')],
[4, 1, 3, 'im child', 'But it\'s so good!', 'emily', NULL, 3,
'58.29.126.1', 'http:://www.wine.com/',
strtotime('2010-01-02 03:04:05'), strtotime('2010-01-02 03:04:05')],
[5, 1, 4, 'im grandchild', 'Right on, Emily!', 'thefonz@example.com', NULL, 9,
'123.456.78.9', NULL,
strtotime('2010-06-02 03:04:05'), strtotime('2010-06-02 03:04:05')],
[
1,
1,
NULL,
'im first',
'Tasty',
'grace',
'grace@example.com',
0,
'123.456.78.9',
'http:://grace.example.com/',
strtotime('2010-01-02 03:04:05'),
strtotime('2010-04-05 06:07:08'),
],
[
2,
1,
NULL,
'im second',
'Delicious',
'horace',
'horace@example.com',
0,
'example.com',
NULL,
strtotime('2010-02-02 03:04:05'),
strtotime('2010-05-05 06:07:08'),
],
[
3,
1,
NULL,
'im parent',
'Don\'t care for it',
'irene',
'irene@example.com',
0,
'254.0.2.5',
'http:://www.example.com/irene',
strtotime('2010-03-02 03:04:05'),
strtotime('2010-03-02 03:04:05'),
],
[
4,
1,
3,
'im child',
'But it\'s so good!',
'emily',
NULL,
3,
'58.29.126.1',
'http:://www.wine.com/',
strtotime('2010-01-02 03:04:05'),
strtotime('2010-01-02 03:04:05'),
],
[
5,
1,
4,
'im grandchild',
'Right on, Emily!',
'thefonz@example.com',
NULL,
9,
'123.456.78.9',
NULL,
strtotime('2010-06-02 03:04:05'),
strtotime('2010-06-02 03:04:05'),
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
@@ -735,6 +995,9 @@ function migrate_example_advanced_data_comment() {
$query->execute();
}
/**
* Populate comment updates table.
*/
function migrate_example_advanced_data_comment_updates() {
$fields = ['commentid', 'subject'];
$query = db_insert('migrate_example_advanced_comment_updates')
@@ -752,13 +1015,37 @@ function migrate_example_advanced_data_comment_updates() {
$query->execute();
}
/**
* Populate categories table.
*/
function migrate_example_advanced_data_categories() {
$fields = ['categoryid', 'type', 'name', 'category_parent', 'details', 'ordering'];
$fields = [
'categoryid',
'type',
'name',
'category_parent',
'details',
'ordering',
];
$query = db_insert('migrate_example_advanced_categories')
->fields($fields);
$data = [
[1, 'variety', 'White wine', NULL, 'White wines are generally simpler and sweeter than red', 3],
[3, 'variety', 'Red wine', NULL, 'Red wines are generally more complex and "dry" than white', 1],
[
1,
'variety',
'White wine',
NULL,
'White wines are generally simpler and sweeter than red',
3,
],
[
3,
'variety',
'Red wine',
NULL,
'Red wines are generally more complex and "dry" than white',
1,
],
[8, 'variety', 'Riesling', 1, 'Associated with Germany', 2],
[9, 'variety', 'Chardonnay', 1, 'One of the most popular whites', 1],
[13, 'variety', 'Merlot', 3, 'Very drinkable', 4],
@@ -787,6 +1074,9 @@ function migrate_example_advanced_data_categories() {
$query->execute();
}
/**
* Populate vintages table.
*/
function migrate_example_advanced_data_vintages() {
$fields = ['wineid', 'vintage'];
$query = db_insert('migrate_example_advanced_vintages')
@@ -802,6 +1092,9 @@ function migrate_example_advanced_data_vintages() {
$query->execute();
}
/**
* Populate variety updates table.
*/
function migrate_example_advanced_data_variety_updates() {
$fields = ['categoryid', 'details'];
$query = db_insert('migrate_example_advanced_variety_updates')
@@ -822,6 +1115,9 @@ function migrate_example_advanced_data_variety_updates() {
$query->execute();
}
/**
* Populate category wine table.
*/
function migrate_example_advanced_data_category_wine() {
$fields = ['wineid', 'categoryid'];
$query = db_insert('migrate_example_advanced_category_wine')
@@ -837,6 +1133,9 @@ function migrate_example_advanced_data_category_wine() {
$query->execute();
}
/**
* Populate category producer table.
*/
function migrate_example_advanced_data_category_producer() {
$fields = ['producerid', 'categoryid'];
$query = db_insert('migrate_example_advanced_category_producer')
@@ -850,15 +1149,36 @@ function migrate_example_advanced_data_category_producer() {
$query->execute();
}
/**
* Populate files table.
*/
function migrate_example_advanced_data_files() {
$fields = ['imageid', 'url', 'image_alt', 'image_title', 'wineid'];
$query = db_insert('migrate_example_advanced_files')
->fields($fields);
$data = [
[1, 'http://placekitten.com/200/200', NULL, NULL, NULL],
[2, 'http://cyrve.com/files/penguin.jpeg', 'Penguin alt', 'Penguin title', 1],
[
1,
'http://placekitten.com/200/200',
NULL,
NULL,
NULL,
],
[
2,
'http://cyrve.com/files/penguin.jpeg',
'Penguin alt',
'Penguin title',
1,
],
[3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2],
[4, 'http://cyrve.com/files/boutisse_0.jpeg', 'Boutisse alt', 'Boutisse title', 2],
[
4,
'http://cyrve.com/files/boutisse_0.jpeg',
'Boutisse alt',
'Boutisse title',
2,
],
];
foreach ($data as $row) {
$query->values(array_combine($fields, $row));
@@ -866,6 +1186,9 @@ function migrate_example_advanced_data_files() {
$query->execute();
}
/**
* Populate blobs table.
*/
function migrate_example_advanced_data_blobs() {
$blob = file_get_contents('core/misc/druplicon.png');
$fields = ['imageid', 'imageblob'];
@@ -880,6 +1203,9 @@ function migrate_example_advanced_data_blobs() {
$query->execute();
}
/**
* Populate table source table.
*/
function migrate_example_advanced_data_table_source() {
$fields = ['fooid', 'field1', 'field2'];
$query = db_insert('migrate_example_advanced_table_source')
@@ -31,22 +31,26 @@ class VarietyItems extends ResourceBase {
$varieties = [
'retsina' => [
'name' => 'Retsina',
'parent' => 1, // categoryid for 'white'.
// The categoryid for 'white'.
'parent' => 1,
'details' => 'Greek',
],
'trebbiano' => [
'name' => 'Trebbiano',
'parent' => 1, // categoryid for 'white'.
// The categoryid for 'white'.
'parent' => 1,
'details' => 'Italian',
],
'valpolicella' => [
'name' => 'Valpolicella',
'parent' => 3, // categoryid for 'red'.
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Venoto region',
],
'bardolino' => [
'name' => 'Bardolino',
'parent' => 3, // categoryid for 'red'.
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Venoto region',
],
];
@@ -32,7 +32,8 @@ class VarietyMultiFiles extends ResourceBase {
if (strtolower($type) != 'white') {
$data['variety'][] = [
'name' => 'Amarone',
'parent' => 3, // categoryid for 'red'.
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Venoto region',
'attributes' => [
'rich',
@@ -41,7 +42,8 @@ class VarietyMultiFiles extends ResourceBase {
];
$data['variety'][] = [
'name' => 'Barbaresco',
'parent' => 3, // categoryid for 'red'.
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Piedmont region',
'attributes' => [
'smoky',
@@ -52,13 +54,15 @@ class VarietyMultiFiles extends ResourceBase {
if (strtolower($type) != 'red') {
$data['variety'][] = [
'name' => 'Kir',
'parent' => 1, // categoryid for 'white'.
// The categoryid for 'white'.
'parent' => 1,
'details' => 'French Burgundy region',
'attributes' => [],
];
$data['variety'][] = [
'name' => 'Pinot Grigio',
'parent' => 1, // categoryid for 'white'.
// The categoryid for 'white'.
'parent' => 1,
'details' => 'From the northeast of Italy',
'attributes' => [
'fruity',
@@ -5,8 +5,7 @@ namespace Drupal\migrate_example_advanced\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
/**
* A straight-forward SQL-based source plugin, to retrieve category data from
* the source database.
* A SQL-based source plugin, to retrieve category data from a source database.
*
* @MigrateSource(
* id = "wine_term"
@@ -18,8 +17,16 @@ class WineTerm extends SqlBase {
* {@inheritdoc}
*/
public function query() {
$fields = [
'categoryid',
'type',
'name',
'details',
'category_parent',
'ordering',
];
return $this->select('migrate_example_advanced_categories', 'wc')
->fields('wc', ['categoryid', 'type', 'name', 'details', 'category_parent', 'ordering'])
->fields('wc', $fields)
// This sort assures that parents are saved before children.
->orderBy('category_parent', 'ASC');
}
@@ -6,8 +6,8 @@ package: Migration
dependencies:
- drupal:migrate (>=8.3)
# Information added by Drupal.org packaging script on 2017-12-12
version: '8.x-4.0-beta2'
# Information added by Drupal.org packaging script on 2018-02-23
version: '8.x-4.0-beta3'
core: '8.x'
project: 'migrate_plus'
datestamp: 1513088305
datestamp: 1519400598
@@ -1,126 +1,207 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="drupal_core">
<description>PHP CodeSniffer configuration</description>
<?xml version="1.0"?>
<ruleset name="Drupal coding standards">
<description>Drupal 8 coding standards</description>
<file>.</file>
<arg name="extensions" value="install,module,php"/>
<arg name="extensions" value="inc,install,module,php,profile,test,theme"/>
<!--Exclude third party code.-->
<exclude-pattern>./vendor/*</exclude-pattern>
<!-- Only include specific sniffs that pass. This ensures that, if new sniffs are added, HEAD does not fail.-->
<!-- Drupal sniffs -->
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php">
<!-- Sniff for these errors: SpacingAfterTagGroup, WrongEnd, SpacingBetween,
ContentAfterOpen, SpacingBeforeShort, TagValueIndent, ShortStartSpace,
SpacingAfter -->
<exclude name="Drupal.Commenting.DocComment.LongNotCapital"/>
<!-- ParamNotFirst still not decided for PHPUnit-based tests.
@see https://www.drupal.org/node/2253915 -->
<exclude name="Drupal.Commenting.DocComment.ParamNotFirst"/>
<exclude name="Drupal.Commenting.DocComment.SpacingBeforeTags"/>
<exclude name="Drupal.Commenting.DocComment.LongFullStop"/>
<exclude name="Drupal.Commenting.DocComment.ShortNotCapital"/>
<exclude name="Drupal.Commenting.DocComment.ShortFullStop"/>
<!--Run Drupal standards.-->
<rule ref="Drupal.Array"/>
<rule ref="Drupal.Classes"/>
<rule ref="Drupal.Commenting">
<!-- TagsNotGrouped and ParamGroup have false-positives.
@see https://www.drupal.org/node/2060925 -->
<exclude name="Drupal.Commenting.DocComment.TagsNotGrouped"/>
<exclude name="Drupal.Commenting.DocComment.ParamGroup"/>
<exclude name="Drupal.Commenting.DocComment.ShortSingleLine"/>
<exclude name="Drupal.Commenting.DocComment.TagGroupSpacing"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php">
<exclude name="Drupal.Commenting.FunctionComment.IncorrectTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidNoReturn"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidReturnNotVoid"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingFile"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnType"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentFullStop"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentIndentation"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamMissingDefinition"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamNameNoMatch"/>
<exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php">
<!-- Sniff for: LowerStart -->
<exclude name="Drupal.NamingConventions.ValidVariableName.LowerCamelName"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php">
<exclude name="Drupal.Semantics.FunctionT.BackslashSingleQuote"/>
<exclude name="Drupal.Semantics.FunctionT.NotLiteralString"/>
<exclude name="Drupal.Semantics.FunctionT.ConcatString"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/TInHookMenuSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php"/>
<rule ref="Drupal.ControlStructures"/>
<rule ref="Drupal.CSS"/>
<rule ref="Drupal.Files"/>
<rule ref="Drupal.Formatting"/>
<rule ref="Drupal.Functions"/>
<rule ref="Drupal.InfoFiles"/>
<rule ref="Drupal.Methods"/>
<rule ref="Drupal.NamingConventions"/>
<rule ref="Drupal.Scope"/>
<rule ref="Drupal.Semantics"/>
<rule ref="Drupal.Strings"/>
<rule ref="Drupal.WhiteSpace"/>
<!-- Drupal Practice sniffs -->
<rule ref="vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php"/>
<rule ref="DrupalPractice.Commenting"/>
<!-- Generic sniffs -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.NamingConventions.ConstructorName" />
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
<properties>
<property name="checkClosures" value="true"/>
</properties>
</rule>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.PHP.UpperCaseConstant"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
<!-- MySource sniffs -->
<rule ref="MySource.Debug.DebugCode"/>
<!-- PEAR sniffs -->
<rule ref="PEAR.Files.IncludingFile"/>
<!-- Disable some error messages that we do not want. -->
<rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseInclude">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequire">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<!-- PEAR sniffs -->
<rule ref="PEAR.Functions.FunctionCallSignature"/>
<!-- The sniffs inside PEAR.Functions.FunctionCallSignature silenced below are
also silenced in Drupal CS' ruleset.xml. The code below is a 1-on-1 copy
from that file. -->
<!-- Disable some error messages that we already cover. -->
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
<severity>0</severity>
</rule>
<!-- Disable some error messages that we do not want. -->
<rule ref="PEAR.Functions.FunctionCallSignature.Indent">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
<severity>0</severity>
</rule>
<!-- PSR-2 sniffs -->
<rule ref="PSR2.Classes.PropertyDeclaration">
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
</rule>
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
<rule ref="PSR2.Namespaces.UseDeclaration">
<exclude name="PSR2.Namespaces.UseDeclaration.UseAfterNamespace"/>
</rule>
<!-- Squiz sniffs -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration">
<exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
</rule>
<!-- Disable some error messages that we do not want. -->
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.FirstValueNoNewline">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NoComma">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NotLowerCase">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
<!-- Disable some error messages that we already cover. -->
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
<!-- Disable some error messages that we already cover. -->
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
<severity>0</severity>
</rule>
<!-- Standard yet to be finalized on this (https://www.drupal.org/node/1539712). -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg">
<severity>0</severity>
</rule>
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
</rule>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<!-- Zend sniffs -->
<rule ref="Zend.Files.ClosingTag"/>
</ruleset>
@@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Plugin;
/**
* Defines an authentication annotation object.
*
* Plugin Namespace: Plugin\migrate_plus\authentication
* Plugin namespace: Plugin\migrate_plus\authentication.
*
* @see \Drupal\migrate_plus\AuthenticationPluginBase
* @see \Drupal\migrate_plus\AuthenticationPluginInterface
@@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Plugin;
/**
* Defines a data fetcher annotation object.
*
* Plugin Namespace: Plugin\migrate_plus\data_fetcher
* Plugin namespace: Plugin\migrate_plus\data_fetcher.
*
* @see \Drupal\migrate_plus\DataFetcherPluginBase
* @see \Drupal\migrate_plus\DataFetcherPluginInterface
@@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Plugin;
/**
* Defines a data parser annotation object.
*
* Plugin Namespace: Plugin\migrate_plus\data_parser
* Plugin namespace: Plugin\migrate_plus\data_parser.
*
* @see \Drupal\migrate_plus\DataParserPluginBase
* @see \Drupal\migrate_plus\DataParserPluginInterface
@@ -21,7 +21,7 @@ class AuthenticationPluginManager extends DefaultPluginManager {
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
@@ -15,7 +15,7 @@ interface DataFetcherPluginInterface {
/**
* Set the client headers.
*
* @param $headers
* @param array $headers
* An array of the headers to set on the HTTP request.
*/
public function setRequestHeaders(array $headers);
@@ -28,7 +28,7 @@ interface DataFetcherPluginInterface {
/**
* Return content.
*
* @param $url
* @param string $url
* URL to retrieve from.
*
* @return string
@@ -39,10 +39,11 @@ interface DataFetcherPluginInterface {
/**
* Return Http Response object for a given url.
*
* @param $url
* @param string $url
* URL to retrieve from.
*
* @return \Psr\Http\Message\ResponseInterface
* The HTTP response message.
*/
public function getResponse($url);
@@ -21,7 +21,7 @@ class DataFetcherPluginManager extends DefaultPluginManager {
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
@@ -127,7 +127,7 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug
/**
* Opens the specified URL.
*
* @param $url
* @param string $url
* URL to open.
*
* @return bool
@@ -136,8 +136,9 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug
abstract protected function openSourceUrl($url);
/**
* Retrieves the next row of data from the open source URL, populating
* currentItem.
* Retrieves the next row of data. populating currentItem.
*
* Retrieves from the open source URL.
*/
abstract protected function fetchNextRow();
@@ -21,7 +21,7 @@ class DataParserPluginManager extends DefaultPluginManager {
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
@@ -16,7 +16,8 @@ final class MigrateEvents {
* has read the inital source data into a Row object. Typically, this would be
* used to add data to the row, manipulate the data into a canonical form, or
* signal by exception that the row should be skipped. The event listener
* method receives a \Drupal\migrate_plus\Event\MigratePrepareRowEvent instance.
* method receives a \Drupal\migrate_plus\Event\MigratePrepareRowEvent
* instance.
*
* @Event
*
@@ -51,6 +51,20 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface {
*/
protected $dbConnection;
/**
* Constructs a new Table.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Connection $connection) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->dbConnection = $connection;
@@ -0,0 +1,44 @@
<?php
namespace Drupal\migrate_plus\Plugin\migrate\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Performs an array_pop() on a source array.
*
* @MigrateProcessPlugin(
* id = "array_pop",
* handle_multiples = TRUE
* )
*
* The "extract" plugin in core can extract array values when indexes are
* already known. This plugin helps extract the last value in an array by
* performing a "pop" operation.
*
* Example: Say, the migration source has an associative array of names in
* a property called "authors" and the keys in the array can vary, you
* can extract the last value like this:
*
* @code
* last_author:
* plugin: array_pop
* source: authors
* @endcode
*/
class ArrayPop extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($value)) {
throw new MigrateException('Input should be an array.');
}
return array_pop($value);
}
}
@@ -0,0 +1,44 @@
<?php
namespace Drupal\migrate_plus\Plugin\migrate\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Performs an array_shift() on a source array.
*
* @MigrateProcessPlugin(
* id = "array_shift",
* handle_multiples = TRUE
* )
*
* The "extract" plugin in core can extract array values when indexes are
* already known. This plugin helps extract the first value in an array by
* performing a "shift" operation.
*
* Example: Say, the migration source has an associative array of names in
* a property called "authors" and the keys in the array can vary, you
* can extract the first value like this:
*
* @code
* first_author:
* plugin: array_shift
* source: authors
* @endcode
*/
class ArrayShift extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($value)) {
throw new MigrateException('Input should be an array.');
}
return array_shift($value);
}
}
@@ -75,7 +75,7 @@ class EntityGenerate extends EntityLookup {
* This is intended to be extended by implementing classes to provide for more
* dynamic default values, rather than just static ones.
*
* @param $value
* @param mixed $value
* Primary value to use in creation of the entity.
*
* @return array
@@ -185,7 +185,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
}
if (empty($this->lookupValueKey) || empty($this->lookupBundleKey) || empty($this->lookupBundle) || empty($this->lookupEntityType)) {
// See if we can introspect the lookup properties from the destination field.
// See if we can introspect the lookup properties from destination field.
if (!empty($this->migration->getProcess()[$this->destinationBundleKey][0]['default_value'])) {
$destinationEntityBundle = $this->migration->getProcess()[$this->destinationBundleKey][0]['default_value'];
$fieldConfig = $this->entityManager->getFieldDefinitions($this->destinationEntityType, $destinationEntityBundle)[$destinationProperty]->getConfig($destinationEntityBundle);
@@ -203,8 +203,8 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
}
}
// Make an assumption that if the selection handler can target more than
// one type of entity that we will use the first entity type.
// Make an assumption that if the selection handler can target more
// than one type of entity that we will use the first entity type.
$this->lookupEntityType = $this->lookupEntityType ?: reset($this->selectionPluginManager->createInstance($fieldConfig->getSetting('handler'))->getPluginDefinition()['entity_types']);
$this->lookupValueKey = $this->lookupValueKey ?: $this->entityManager->getDefinition($this->lookupEntityType)->getKey('label');
$this->lookupBundleKey = $this->lookupBundleKey ?: $this->entityManager->getDefinition($this->lookupEntityType)->getKey('bundle');
@@ -238,8 +238,8 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
/**
* Checks for the existence of some value.
*
* @param $value
* The value to query.
* @param mixed $value
* The value to query.
*
* @return mixed|null
* Entity id if the queried entity exists. Otherwise NULL.
@@ -38,7 +38,7 @@ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterf
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, FileSystemInterface $file_system) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, FileSystemInterface $file_system) {
$configuration += [
'reuse' => FALSE,
];
@@ -65,11 +65,11 @@ class SkipOnValue extends ProcessPluginBase {
/**
* Compare values to see if they are equal.
*
* @param $value
* Actual value
* @param $skipValue
* @param mixed $value
* Actual value.
* @param mixed $skipValue
* Value to compare against.
* @param $equal
* @param bool $equal
* Compare as equal or not equal.
*
* @return bool
@@ -17,44 +17,44 @@ use Drupal\migrate\Row;
* To do a simple hardcoded string replace use the following:
*
* @code
* field_text:
* plugin: str_replace
* source: text
* search: foo
* replace: bar
* field_text:
* plugin: str_replace
* source: text
* search: foo
* replace: bar
* @endcode
*
* If the value of text is "vero eos et accusam et justo vero"
* in source, foo is "et" in search and bar is "that" in replace,
* field_text will be "vero eos that accusam that justo vero".
* If the value of text is "vero eos et accusam et justo vero" in source, foo is
* "et" in search and bar is "that" in replace, field_text will be "vero eos
* that accusam that justo vero".
*
* Case insensitive searches can be achieved using the following:
* @code
* field_text:
* plugin: str_replace
* case_insensitive: true
* source: text
* search: foo
* replace: bar
* field_text:
* plugin: str_replace
* case_insensitive: true
* source: text
* search: foo
* replace: bar
* @endcode
*
* If the value of text is "VERO eos et accusam et justo vero"
* in source, foo is "vero" in search and bar is "that" in replace,
* field_text will be "that eos et accusam et justo that".
* If the value of text is "VERO eos et accusam et justo vero" in source, foo is
* "vero" in search and bar is "that" in replace, field_text will be "that eos
* et accusam et justo that".
*
* Also regular expressions can be matched using:
* @code
* field_text:
* plugin: str_replace
* regex: true
* source: text
* search: foo
* replace: bar
* field_text:
* plugin: str_replace
* regex: true
* source: text
* search: foo
* replace: bar
* @endcode
*
* If the value of text is "vero eos et 123 accusam et justo 123 duo"
* in source, foo is "/[0-9]{3}/" in search and bar is "the" in replace,
* field_text will be "vero eos et the accusam et justo the duo".
* If the value of text is "vero eos et 123 accusam et justo 123 duo" in source,
* foo is "/[0-9]{3}/" in search and bar is "the" in replace, field_text will be
* "vero eos et the accusam et justo the duo".
*
* All the rules for
* @link http://php.net/manual/function.str-replace.php str_replace @endlink
@@ -11,7 +11,7 @@ use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Transliterates text from Unicode to US-ASCII
* Transliterates text from Unicode to US-ASCII.
*
* The transliteration process plugin takes the source value and runs it through
* the transliteration service. Letters will have language decorations and
@@ -26,8 +26,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* source: foo
* @endcode
*
* If the value of foo in the source is 'áéí!' then the destination value of bar
* will be 'aei!'.
* If the value of foo in the source is 'áéí!' then the destination value of
* bar will be 'aei!'.
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
*
@@ -81,4 +81,3 @@ class Transliteration extends ProcessPluginBase implements ContainerFactoryPlugi
}
}
@@ -16,7 +16,7 @@ use Sainsburys\Guzzle\Oauth2\Middleware\OAuthMiddleware;
/**
* Provides OAuth2 authentication for the HTTP resource.
*
*
* @link https://packagist.org/packages/sainsburys/guzzle-oauth2-plugin
*
* @Authentication(
@@ -10,7 +10,7 @@ use GuzzleHttp\Exception\RequestException;
/**
* Retrieve data over an HTTP connection for migration.
*
* * Example:
* Example:
*
* @code
* source:
@@ -31,7 +31,7 @@ use GuzzleHttp\Exception\RequestException;
class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterface {
/**
* The HTTP Client
* The HTTP client.
*
* @var \GuzzleHttp\Client
*/
@@ -58,6 +58,8 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->httpClient = \Drupal::httpClient();
// Ensure there is a 'headers' key in the configuration.
$configuration += ['headers' => []];
$this->setRequestHeaders($configuration['headers']);
}
@@ -16,12 +16,17 @@ class MigrateTableTest extends MigrateTestBase {
const TABLE_NAME = 'migrate_test_destination_table';
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
public static $modules = ['migrate_plus'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
@@ -50,22 +55,42 @@ class MigrateTableTest extends MigrateTestBase {
]);
}
/**
* {@inheritdoc}
*/
protected function tearDown() {
$this->connection->schema()->dropTable(static::TABLE_NAME);
parent::tearDown();
}
/**
* Create a minimally valid migration with some source data.
*
* @return array
* The migration definition.
*/
protected function getTableDestinationMigration() {
// Create a minimally valid migration with some source data.
$definition = [
'id' => 'migration_table_test',
'migration_tags' => ['Testing'],
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [
['data' => 'dummy value', 'data2' => 'dummy2 value', 'data3' => 'dummy3 value'],
['data' => 'dummy value2', 'data2' => 'dummy2 value2', 'data3' => 'dummy3 value2'],
['data' => 'dummy value3', 'data2' => 'dummy2 value3', 'data3' => 'dummy3 value3'],
[
'data' => 'dummy value',
'data2' => 'dummy2 value',
'data3' => 'dummy3 value',
],
[
'data' => 'dummy value2',
'data2' => 'dummy2 value2',
'data3' => 'dummy3 value2',
],
[
'data' => 'dummy value3',
'data2' => 'dummy2 value3',
'data3' => 'dummy3 value3',
],
],
'ids' => [
'data' => ['type' => 'string'],
@@ -106,6 +131,9 @@ class MigrateTableTest extends MigrateTestBase {
$this->assertEquals(3, count($values));
}
/**
* Tests table rollback.
*/
public function testTableRollback() {
$this->testTableDestination();
@@ -15,15 +15,23 @@ class MigrationConfigEntityTest extends KernelTestBase {
public static $modules = ['migrate', 'migrate_plus'];
/**
* The plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected $pluginManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->pluginManager = \Drupal::service('plugin.manager.migration');
}
/**
* Tests cache invalidation.
*/
public function testCacheInvalidation() {
$config = Migration::create([
'id' => 'test',
@@ -25,14 +25,18 @@ class MigrationGroupTest extends KernelTestBase {
$group_configuration = [
'id' => $group_id,
'shared_configuration' => [
'migration_tags' => ['Drupal 6'], // In migration, so will be overridden.
// In migration, so will be overridden.
'migration_tags' => ['Drupal 6'],
'source' => [
'constants' => [
'type' => 'image', // Not in migration, so will be added.
'cardinality' => '1', // In migration, so will be overridden.
// Not in migration, so will be added.
'type' => 'image',
// In migration, so will be overridden.
'cardinality' => '1',
],
],
'destination' => ['plugin' => 'field_storage_config'], // Not in migration, so will be added.
// Not in migration, so will be added.
'destination' => ['plugin' => 'field_storage_config'],
],
];
$this->container->get('entity_type.manager')->getStorage('migration_group')
@@ -41,21 +45,25 @@ class MigrationGroupTest extends KernelTestBase {
/** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */
$migration = $this->container->get('entity_type.manager')
->getStorage('migration')->create([
'id' => 'specific_migration',
'load' => [],
'migration_group' => $group_id,
'label' => 'Unaffected by the group',
'migration_tags' => ['Drupal 7'], // Overrides group.
'destination' => [],
'source' => [],
'process' => [],
'migration_dependencies' => [],
]);
'id' => 'specific_migration',
'load' => [],
'migration_group' => $group_id,
'label' => 'Unaffected by the group',
// Overrides group.
'migration_tags' => ['Drupal 7'],
'destination' => [],
'source' => [],
'process' => [],
'migration_dependencies' => [],
]);
$migration->set('source', [
'plugin' => 'empty', // Not in group, persists.
// Not in group, persists.
'plugin' => 'empty',
'constants' => [
'entity_type' => 'user', // Not in group, persists.
'cardinality' => '3', // Overrides group.
// Not in group, persists.
'entity_type' => 'user',
// Overrides group.
'cardinality' => '3',
],
]);
$migration->save();
@@ -98,14 +106,14 @@ class MigrationGroupTest extends KernelTestBase {
/** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */
$migration = $this->container->get('entity_type.manager')
->getStorage('migration')->create([
'id' => 'specific_migration',
'migration_group' => 'test_group',
'migration_tags' => [],
'load' => [],
'destination' => [],
'source' => [],
'migration_dependencies' => [],
]);
'id' => 'specific_migration',
'migration_group' => 'test_group',
'migration_tags' => [],
'load' => [],
'destination' => [],
'source' => [],
'migration_dependencies' => [],
]);
$migration->save();
/** @var \Drupal\migrate_plus\Entity\MigrationGroupInterface $loaded_migration_group */
@@ -58,9 +58,9 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
protected $vocabulary = 'fruit';
/**
* @var \Drupal\migrate\Plugin\MigrationPluginManager $migrationManager
*
* The migration plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected $migrationPluginManager;
@@ -2,14 +2,11 @@
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_fetcher;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher\Http;
use Drupal\Tests\Core\Test\KernelTestBaseTest;
use Drupal\Tests\UnitTestCase;
/**
* Class HttpTest
* Class HttpTest.
*
* @group migrate_plus
* @package Drupal\Tests\migrate_plus\Unit\migrate_plus\data_fetcher
@@ -18,26 +15,45 @@ class HttpTest extends KernelTestBase {
/**
* Test http headers option.
*
* @dataProvider headerDataProvider
*/
function testHttpHeaders() {
$expected = [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz'
];
$configuration = [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz'
]
];
$http = new Http($configuration, 'http', []);
public function testHttpHeaders(array $definition, array $expected, array $preSeed = []) {
$http = new Http($definition, 'http', []);
$this->assertEquals($expected, $http->getRequestHeaders());
}
/**
* Provides multiple test cases for the testHttpHeaders method.
*
* @return array
* The test cases
*/
public function headerDataProvider() {
return [
'dummy headers specified' => [
'definition' => [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz',
],
],
'expected' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz',
],
],
'no headers specified' => [
'definition' => [
'no_headers_here' => 'foo',
],
'expected' => [],
],
];
}
}
@@ -0,0 +1,71 @@
<?php
namespace Drupal\Tests\migrate_plus\Unit\process;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
use Drupal\migrate_plus\Plugin\migrate\process\ArrayPop;
use Drupal\migrate\MigrateException;
/**
* Tests the array pop process plugin.
*
* @group migrate
* @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\ArrayPop
*/
class ArrayPopTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new ArrayPop([], 'array_pop', []);
parent::setUp();
}
/**
* Data provider for testArrayPop().
*
* @return array
* An array containing input values and expected output values.
*/
public function arrayPopDataProvider() {
return [
'indexed array' => [
'input' => ['v1', 'v2', 'v3'],
'expected_output' => 'v3',
],
'associative array' => [
'input' => ['i1' => 'v1', 'i2' => 'v2', 'i3' => 'v3'],
'expected_output' => 'v3',
],
'empty array' => [
'input' => [],
'expected_output' => NULL,
],
];
}
/**
* Test array pop plugin.
*
* @param array $input
* The input values.
* @param mixed $expected_output
* The expected output.
*
* @dataProvider arrayPopDataProvider
*/
public function testArrayPop(array $input, $expected_output) {
$output = $this->plugin->transform($input, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame($output, $expected_output);
}
/**
* Test invalid input.
*/
public function testArrayPopFromString() {
$this->setExpectedException(MigrateException::class, 'Input should be an array.');
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
}
}
@@ -0,0 +1,71 @@
<?php
namespace Drupal\Tests\migrate_plus\Unit\process;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
use Drupal\migrate_plus\Plugin\migrate\process\ArrayShift;
use Drupal\migrate\MigrateException;
/**
* Tests the array shift process plugin.
*
* @group migrate
* @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\ArrayShift
*/
class ArrayShiftTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new ArrayShift([], 'array_shift', []);
parent::setUp();
}
/**
* Data provider for testArrayShift().
*
* @return array
* An array containing input values and expected output values.
*/
public function arrayShiftDataProvider() {
return [
'indexed array' => [
'input' => ['v1', 'v2', 'v3'],
'expected_output' => 'v1',
],
'associative array' => [
'input' => ['i1' => 'v1', 'i2' => 'v2', 'i3' => 'v3'],
'expected_output' => 'v1',
],
'empty array' => [
'input' => [],
'expected_output' => NULL,
],
];
}
/**
* Test array shift plugin.
*
* @param array $input
* The input values.
* @param mixed $expected_output
* The expected output.
*
* @dataProvider arrayShiftDataProvider
*/
public function testArrayShift(array $input, $expected_output) {
$output = $this->plugin->transform($input, $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame($output, $expected_output);
}
/**
* Test invalid input.
*/
public function testArrayShiftFromString() {
$this->setExpectedException(MigrateException::class, 'Input should be an array.');
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
}
}
@@ -5,7 +5,6 @@ namespace Drupal\Tests\migrate_plus\Unit\process;
use Drupal\migrate_plus\Plugin\migrate\process\StrReplace;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests the str replace process plugin.
*
@@ -56,7 +55,6 @@ class StrReplaceTest extends MigrateProcessTestCase {
/**
* Test for MigrateException for "search" configuration.
*
*/
public function testSearchMigrateException() {
$value = 'vero eos et accusam et justo vero';
@@ -80,11 +78,11 @@ class StrReplaceTest extends MigrateProcessTestCase {
/**
* Test for multiple.
*/
public function testIsMultiple() {
public function testIsMultiple() {
$value = [
'vero eos et accusam et justo vero',
'et eos vero accusam vero justo et',
];
];
$expected = [
'vero eos that accusam that justo vero',