Commit 7a526044 authored by heddn's avatar heddn Committed by heddn

Issue #2944544 by heddn: Fix failing phpcs testing

parent 81482505
......@@ -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);
}
......
......@@ -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) {
......
......@@ -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