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) {
......
......@@ -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');
}
......
This diff is collapsed.
......@@ -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