updated contrib modules
This commit is contained in:
@@ -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
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+168
-13
@@ -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')
|
||||
|
||||
+11
-2
@@ -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;
|
||||
}
|
||||
|
||||
+25
-19
@@ -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'))
|
||||
|
||||
+24
-28
@@ -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',
|
||||
|
||||
+25
-20
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+6
-6
@@ -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) {
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+366
-40
@@ -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')
|
||||
|
||||
+8
-4
@@ -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',
|
||||
],
|
||||
];
|
||||
|
||||
+8
-4
@@ -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',
|
||||
|
||||
+10
-3
@@ -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
|
||||
*
|
||||
|
||||
+14
@@ -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;
|
||||
|
||||
+44
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
+5
-5
@@ -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.
|
||||
|
||||
+1
-1
@@ -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,
|
||||
];
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+26
-26
@@ -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
|
||||
|
||||
+3
-4
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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(
|
||||
|
||||
+4
-2
@@ -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']);
|
||||
}
|
||||
|
||||
|
||||
+32
-4
@@ -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();
|
||||
|
||||
|
||||
+8
@@ -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',
|
||||
|
||||
+33
-25
@@ -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 */
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
|
||||
+39
-23
@@ -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' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+71
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
+71
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
+2
-4
@@ -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',
|
||||
|
||||
@@ -2,10 +2,22 @@
|
||||
"name": "drupal/migrate_tools",
|
||||
"description": "Tools to assist in developing and running migrations.",
|
||||
"type": "drupal-module",
|
||||
"require-dev": {
|
||||
"drupal/coder": "^8"
|
||||
"homepage": "http://drupal.org/project/migrate_tools",
|
||||
"support": {
|
||||
"issues": "http://drupal.org/project/migrate_tools",
|
||||
"irc": "irc://irc.freenode.org/drupal-migrate",
|
||||
"source": "http://cgit.drupalcode.org/migrate_tools"
|
||||
},
|
||||
"license": "GPL-2.0+",
|
||||
"require": {},
|
||||
"minimum-stability": "dev"
|
||||
"require-dev": {
|
||||
"drupal/coder": "^8"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"drush": {
|
||||
"services": {
|
||||
"drush.services.yml": "^9"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Drupal\migrate_tools\MigrateExecutable;
|
||||
use Drupal\migrate_tools\DrushLogMigrateMessage;
|
||||
use Drupal\Core\Datetime\DateFormatter;
|
||||
use Drupal\migrate_plus\Entity\MigrationGroup;
|
||||
use Drupal\migrate_tools\DrushLogMigrateMessage;
|
||||
use Drupal\migrate_tools\MigrateExecutable;
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
@@ -68,27 +67,27 @@ function migrate_tools_drush_command() {
|
||||
'aliases' => ['mi', 'mim'],
|
||||
];
|
||||
|
||||
$items['migrate-rollback'] = array(
|
||||
$items['migrate-rollback'] = [
|
||||
'description' => 'Rollback one or more migrations.',
|
||||
'options' => array(
|
||||
'options' => [
|
||||
'all' => 'Process all migrations.',
|
||||
'group' => 'A comma-separated list of migration groups to rollback',
|
||||
'tag' => 'ID of the migration tag to rollback',
|
||||
'feedback' => 'Frequency of progress messages, in items processed',
|
||||
),
|
||||
'arguments' => array(
|
||||
],
|
||||
'arguments' => [
|
||||
'migration' => 'Name of migration(s) to rollback. Delimit multiple using commas.',
|
||||
),
|
||||
'examples' => array(
|
||||
],
|
||||
'examples' => [
|
||||
'migrate-rollback --all' => 'Perform all migrations',
|
||||
'migrate-rollback --group=beer' => 'Rollback all migrations in the beer group',
|
||||
'migrate-rollback --tag=user' => 'Rollback all migrations with the user tag',
|
||||
'migrate-rollback --group=beer --tag=user' => 'Rollback all migrations in the beer group and with the user tag',
|
||||
'migrate-rollback beer_term,beer_node' => 'Rollback imported terms and nodes',
|
||||
),
|
||||
'drupal dependencies' => array('migrate_tools'),
|
||||
'aliases' => array('mr'),
|
||||
);
|
||||
],
|
||||
'drupal dependencies' => ['migrate_tools'],
|
||||
'aliases' => ['mr'],
|
||||
];
|
||||
|
||||
$items['migrate-stop'] = [
|
||||
'description' => 'Stop an active migration operation.',
|
||||
@@ -114,7 +113,7 @@ function migrate_tools_drush_command() {
|
||||
'migration' => 'ID of the migration',
|
||||
],
|
||||
'options' => [
|
||||
'csv' => 'Export messages as a CSV'
|
||||
'csv' => 'Export messages as a CSV',
|
||||
],
|
||||
'examples' => [
|
||||
'migrate-messages MyNode' => 'Show all messages for the MyNode migration',
|
||||
@@ -139,7 +138,10 @@ function migrate_tools_drush_command() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display migration status.
|
||||
*
|
||||
* @param string $migration_names
|
||||
* The migration names.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_status($migration_names = '') {
|
||||
$names_only = drush_get_option('names-only');
|
||||
@@ -153,12 +155,12 @@ function drush_migrate_tools_migrate_status($migration_names = '') {
|
||||
$group_name = !empty($group) ? "{$group->label()} ({$group->id()})" : $group_id;
|
||||
if ($names_only) {
|
||||
$table[] = [
|
||||
dt('Group: @name', array('@name' => $group_name))
|
||||
dt('Group: @name', ['@name' => $group_name]),
|
||||
];
|
||||
}
|
||||
else {
|
||||
$table[] = [
|
||||
dt('Group: @name', array('@name' => $group_name)),
|
||||
dt('Group: @name', ['@name' => $group_name]),
|
||||
dt('Status'),
|
||||
dt('Total'),
|
||||
dt('Imported'),
|
||||
@@ -204,7 +206,7 @@ function drush_migrate_tools_migrate_status($migration_names = '') {
|
||||
$migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported');
|
||||
$last_imported = $migrate_last_imported_store->get($migration->id(), FALSE);
|
||||
if ($last_imported) {
|
||||
/** @var DateFormatter $date_formatter */
|
||||
/** @var \Drupal\Core\Datetime\DateFormatter $date_formatter */
|
||||
$date_formatter = \Drupal::service('date.formatter');
|
||||
$last_imported = $date_formatter->format($last_imported / 1000,
|
||||
'custom', 'Y-m-d H:i:s');
|
||||
@@ -212,7 +214,14 @@ function drush_migrate_tools_migrate_status($migration_names = '') {
|
||||
else {
|
||||
$last_imported = '';
|
||||
}
|
||||
$table[] = [$migration_id, $status, $source_rows, $imported, $unprocessed, $last_imported];
|
||||
$table[] = [
|
||||
$migration_id,
|
||||
$status,
|
||||
$source_rows,
|
||||
$imported,
|
||||
$unprocessed,
|
||||
$last_imported,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +229,10 @@ function drush_migrate_tools_migrate_status($migration_names = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a migration.
|
||||
*
|
||||
* @param string $migration_names
|
||||
* The migration names.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_import($migration_names = '') {
|
||||
$group_names = drush_get_option('group');
|
||||
@@ -257,17 +269,19 @@ function drush_migrate_tools_migrate_import($migration_names = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single migration. If the --execute-dependencies option was given,
|
||||
* the migration's dependencies will also be executed first.
|
||||
* Executes a single migration.
|
||||
*
|
||||
* If the --execute-dependencies option was given, the migration's dependencies
|
||||
* will also be executed first.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to execute.
|
||||
* The migration to execute.
|
||||
* @param string $migration_id
|
||||
* The migration ID (not used, just an artifact of array_walk()).
|
||||
* The migration ID (not used, just an artifact of array_walk()).
|
||||
* @param array $options
|
||||
* Additional options for the migration.
|
||||
* Additional options for the migration.
|
||||
*/
|
||||
function _drush_migrate_tools_execute_migration(MigrationInterface $migration, $migration_id, array $options = []) {
|
||||
function _drush_migrate_tools_execute_migration(MigrationInterface $migration, $migration_id, array $options = []) {
|
||||
$log = new DrushLogMigrateMessage();
|
||||
|
||||
if (drush_get_option('execute-dependencies')) {
|
||||
@@ -285,16 +299,22 @@ function _drush_migrate_tools_execute_migration(MigrationInterface $migration, $
|
||||
$migration->getIdMap()->prepareUpdate();
|
||||
}
|
||||
$executable = new MigrateExecutable($migration, $log, $options);
|
||||
// drush_op() provides --simulate support
|
||||
drush_op(array($executable, 'import'));
|
||||
// Function drush_op() provides --simulate support.
|
||||
drush_op([$executable, 'import']);
|
||||
if ($count = $executable->getFailedCount()) {
|
||||
// Nudge Drush to use a non-zero exit code.
|
||||
drush_set_error('MIGRATE_ERROR', dt('!name Migration - !count failed.', array('!name' => $migration_id, '!count' => $count)));
|
||||
drush_set_error('MIGRATE_ERROR', dt('!name Migration - !count failed.', [
|
||||
'!name' => $migration_id,
|
||||
'!count' => $count,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback migrations.
|
||||
*
|
||||
* @param string $migration_names
|
||||
* The migration names.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_rollback($migration_names = '') {
|
||||
$group_names = drush_get_option('group');
|
||||
@@ -324,17 +344,21 @@ function drush_migrate_tools_migrate_rollback($migration_names = '') {
|
||||
foreach ($migration_list as $migration_id => $migration) {
|
||||
$executable = new MigrateExecutable($migration, $log, $options);
|
||||
// drush_op() provides --simulate support.
|
||||
drush_op(array($executable, 'rollback'));
|
||||
drush_op([$executable, 'rollback']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a migration.
|
||||
*
|
||||
* @param string $migration_id
|
||||
* The migration id.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_stop($migration_id = '') {
|
||||
/** @var MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createInstance($migration_id);
|
||||
if ($migration) {
|
||||
$status = $migration->getStatus();
|
||||
switch ($status) {
|
||||
@@ -359,11 +383,15 @@ function drush_migrate_tools_migrate_stop($migration_id = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset status.
|
||||
*
|
||||
* @param string $migration_id
|
||||
* The migration id.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_reset_status($migration_id = '') {
|
||||
/** @var MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createInstance($migration_id);
|
||||
if ($migration) {
|
||||
$status = $migration->getStatus();
|
||||
if ($status == MigrationInterface::STATUS_IDLE) {
|
||||
@@ -380,11 +408,15 @@ function drush_migrate_tools_migrate_reset_status($migration_id = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print messages.
|
||||
*
|
||||
* @param string $migration_id
|
||||
* The migration id.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_messages($migration_id) {
|
||||
/** @var MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createInstance($migration_id);
|
||||
if ($migration) {
|
||||
$map = $migration->getIdMap();
|
||||
$first = TRUE;
|
||||
@@ -399,7 +431,7 @@ function drush_migrate_tools_migrate_messages($migration_id) {
|
||||
}
|
||||
$first = FALSE;
|
||||
}
|
||||
$table[] = (array)$row;
|
||||
$table[] = (array) $row;
|
||||
}
|
||||
if (empty($table)) {
|
||||
drush_log(dt('No messages for this migration'), 'status');
|
||||
@@ -425,11 +457,15 @@ function drush_migrate_tools_migrate_messages($migration_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print source fields.
|
||||
*
|
||||
* @param string $migration_id
|
||||
* The migration id.
|
||||
*/
|
||||
function drush_migrate_tools_migrate_fields_source($migration_id) {
|
||||
/** @var MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createInstance($migration_id);
|
||||
if ($migration) {
|
||||
$source = $migration->getSourcePlugin();
|
||||
$table = [];
|
||||
@@ -447,9 +483,10 @@ function drush_migrate_tools_migrate_fields_source($migration_id) {
|
||||
* Retrieve a list of active migrations.
|
||||
*
|
||||
* @param string $migration_ids
|
||||
* Comma-separated list of migrations - if present, return only these migrations.
|
||||
* Comma-separated list of migrations - if present, return only these
|
||||
* migrations.
|
||||
*
|
||||
* @return MigrationInterface[][]
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[][]
|
||||
* An array keyed by migration group, each value containing an array of
|
||||
* migrations or an empty array if no migrations match the input criteria.
|
||||
*/
|
||||
|
||||
@@ -7,8 +7,8 @@ dependencies:
|
||||
- drupal:migrate (>=8.3)
|
||||
- migrate_plus:migrate_plus
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-27
|
||||
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_tools'
|
||||
datestamp: 1511790488
|
||||
datestamp: 1519400307
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
* Implements hook_entity_type_build().
|
||||
*/
|
||||
function migrate_tools_entity_type_build(array &$entity_types) {
|
||||
// Inject our UI into the general migration and migration group config entities.
|
||||
// Inject our UI into the general migration and migration group config
|
||||
// entities.
|
||||
/** @var \Drupal\Core\Config\Entity\ConfigEntityType[] $entity_types */
|
||||
$entity_types['migration']
|
||||
->set('admin_permission', 'administer migrations')
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
logger.channel.migrate_tools:
|
||||
class: Drupal\Core\Logger\LoggerChannel
|
||||
factory: logger.factory:get
|
||||
arguments: ['migrate_tools']
|
||||
@@ -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>
|
||||
|
||||
@@ -12,10 +12,8 @@ use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManager;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Drupal\migrate_tools\Drush9LogMigrateMessage;
|
||||
use Drupal\migrate_tools\DrushLogMigrateMessage;
|
||||
use Drupal\migrate_tools\MigrateExecutable;
|
||||
use Drush\Commands\DrushCommands;
|
||||
use Drush\Drush;
|
||||
|
||||
/**
|
||||
* Migrate Tools drush commands.
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ class MessageController extends ControllerBase {
|
||||
public function overview($migration_group, $migration) {
|
||||
$rows = [];
|
||||
$classes = static::getLogLevelClassMap();
|
||||
/** @var MigrationInterface $migration */
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = $this->migrationPluginManager->createInstance($migration);
|
||||
$source_id_field_names = array_keys($migration->getSourcePlugin()->getIds());
|
||||
$column_number = 1;
|
||||
|
||||
+2
-2
@@ -34,13 +34,13 @@ class MigrationGroupListBuilder extends ConfigEntityListBuilder {
|
||||
/**
|
||||
* Builds a row for an entity in the entity listing.
|
||||
*
|
||||
* @param EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity for which to build the row.
|
||||
*
|
||||
* @return array
|
||||
* A render array of the table row for displaying the entity.
|
||||
*
|
||||
* @see Drupal\Core\Entity\EntityListController::render()
|
||||
* @see \Drupal\Core\Entity\EntityListController::render()
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $entity->label();
|
||||
|
||||
+23
-7
@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityHandlerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Logger\LoggerChannelInterface;
|
||||
use Drupal\Core\Routing\CurrentRouteMatch;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate_plus\Entity\MigrationGroup;
|
||||
@@ -37,6 +38,13 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
*/
|
||||
protected $migrationPluginManager;
|
||||
|
||||
/**
|
||||
* The logger service.
|
||||
*
|
||||
* @var \Drupal\Core\Logger\LoggerChannelInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityListBuilder object.
|
||||
*
|
||||
@@ -48,11 +56,14 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
* The current route match service.
|
||||
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
|
||||
* The plugin manager for config entity-based migrations.
|
||||
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
|
||||
* The logger service.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, CurrentRouteMatch $current_route_match, MigrationPluginManagerInterface $migration_plugin_manager) {
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, CurrentRouteMatch $current_route_match, MigrationPluginManagerInterface $migration_plugin_manager, LoggerChannelInterface $logger) {
|
||||
parent::__construct($entity_type, $storage);
|
||||
$this->currentRouteMatch = $current_route_match;
|
||||
$this->migrationPluginManager = $migration_plugin_manager;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +74,8 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
$entity_type,
|
||||
$container->get('entity.manager')->getStorage($entity_type->id()),
|
||||
$container->get('current_route_match'),
|
||||
$container->get('plugin.manager.migration')
|
||||
$container->get('plugin.manager.migration'),
|
||||
$container->get('logger.channel.migrate_tools')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,7 +133,7 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
* @param \Drupal\Core\Entity\EntityInterface $migration_entity
|
||||
* The migration plugin for which to build the row.
|
||||
*
|
||||
* @return array
|
||||
* @return array|null
|
||||
* A render array of the table row for displaying the plugin information.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityListController::render()
|
||||
@@ -147,7 +159,9 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
];
|
||||
$row['machine_name'] = $migration->id();
|
||||
$row['status'] = $migration->getStatusLabel();
|
||||
} catch (PluginException $e) {
|
||||
}
|
||||
catch (PluginException $e) {
|
||||
$this->logger->warning('Migration entity id %id is malformed', ['%id' => $migration_entity->id()]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -196,7 +210,8 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
],
|
||||
],
|
||||
];
|
||||
} catch (PluginException $e) {
|
||||
}
|
||||
catch (PluginException $e) {
|
||||
// Derive the stats.
|
||||
$row['status'] = $this->t('No data found');
|
||||
$row['total'] = $this->t('N/A');
|
||||
@@ -211,10 +226,11 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand
|
||||
}
|
||||
|
||||
/**
|
||||
* Add group route parameter.
|
||||
*
|
||||
* @param \Drupal\Core\Url $url
|
||||
* The URL associated with an operation.
|
||||
*
|
||||
* @param $migration_group
|
||||
* @param string $migration_group
|
||||
* The migration's parent group.
|
||||
*/
|
||||
protected function addGroupParameter(Url $url, $migration_group) {
|
||||
|
||||
@@ -4,6 +4,11 @@ namespace Drupal\migrate_tools;
|
||||
|
||||
use Drupal\migrate\MigrateMessageInterface;
|
||||
|
||||
/**
|
||||
* Class DrushLogMigrateMessage.
|
||||
*
|
||||
* @package Drupal\migrate_tools
|
||||
*/
|
||||
class DrushLogMigrateMessage implements MigrateMessageInterface {
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ use Drupal\Core\Url;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class MigrationDeleteForm.
|
||||
* Provides the delete form for our Migration entity.
|
||||
*
|
||||
* @package Drupal\migrate_tools\Form
|
||||
*
|
||||
@@ -23,7 +23,7 @@ class MigrationDeleteForm extends EntityConfirmFormBase {
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to delete migration %label?', [
|
||||
'%label' => $this->entity->label(),
|
||||
'%label' => $this->entity->label(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Class MigrationEditForm
|
||||
*
|
||||
* Provides the edit form for our Migration entity.
|
||||
*
|
||||
* @package Drupal\migrate_tools\Form
|
||||
@@ -37,10 +35,11 @@ class MigrationEditForm extends MigrationFormBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add group route parameter.
|
||||
*
|
||||
* @param \Drupal\Core\Url $url
|
||||
* The URL associated with an operation.
|
||||
*
|
||||
* @param $migration_group
|
||||
* @param string $migration_group
|
||||
* The migration's parent group.
|
||||
*/
|
||||
protected function addGroupParameter(Url $url, $migration_group) {
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\migrate_tools\Form\MigrationExecuteForm
|
||||
*/
|
||||
|
||||
namespace Drupal\migrate_tools\Form;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\MigrateMessageInterface;
|
||||
use Drupal\migrate\Plugin\Migration;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate_tools\MigrateBatchExecutable;
|
||||
use Drupal\migrate_tools\MigrateExecutable;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -129,13 +120,7 @@ class MigrationExecuteForm extends FormBase {
|
||||
completed.'),
|
||||
];
|
||||
// @TODO: Limit is not working. Perhaps because of batch? See
|
||||
// https://www.drupal.org/project/migrate_tools/issues/2924298
|
||||
// $form['options']['limit'] = [
|
||||
// '#type' => 'textfield',
|
||||
// '#title' => t('Limit to:'),
|
||||
// '#size' => 10,
|
||||
// '#description' => t('Set a limit of how many items to process for each migration task.'),
|
||||
// ];
|
||||
// https://www.drupal.org/project/migrate_tools/issues/2924298.
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -181,7 +166,7 @@ class MigrationExecuteForm extends FormBase {
|
||||
|
||||
if ($migration_name) {
|
||||
|
||||
/** @var MigrationInterface $migration */
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = $this->migrationPluginManager->createInstance($migration_name);
|
||||
$migrateMessage = new MigrateMessage();
|
||||
|
||||
@@ -204,7 +189,7 @@ class MigrationExecuteForm extends FormBase {
|
||||
$options = [
|
||||
'limit' => $limit,
|
||||
'update' => $update,
|
||||
'force' => $force
|
||||
'force' => $force,
|
||||
];
|
||||
|
||||
$executable = new MigrateBatchExecutable($migration, $migrateMessage, $options);
|
||||
|
||||
@@ -18,6 +18,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
class MigrationFormBase extends EntityForm {
|
||||
|
||||
/**
|
||||
* The entity query factory.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQueryFactory;
|
||||
@@ -25,8 +27,8 @@ class MigrationFormBase extends EntityForm {
|
||||
/**
|
||||
* Construct the MigrationGroupFormBase.
|
||||
*
|
||||
* For simple entity forms, there's no need for a constructor. Our migration form
|
||||
* base, however, requires an entity query factory to be injected into it
|
||||
* For simple entity forms, there's no need for a constructor. Our migration
|
||||
* form base, however, requires an entity query factory to be injected into it
|
||||
* from the container. We later use this query factory to build an entity
|
||||
* query for the exists() method.
|
||||
*
|
||||
@@ -38,12 +40,7 @@ class MigrationFormBase extends EntityForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for MigrationFormBase.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
* A container interface service.
|
||||
*
|
||||
* @return \Drupal\migrate_tools\Form\MigrationGroupFormBase
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('entity.query'));
|
||||
@@ -72,7 +69,7 @@ class MigrationFormBase extends EntityForm {
|
||||
$form['warning'] = [
|
||||
'#markup' => $this->t('Creating migrations is not yet supported. See <a href=":url">:url</a>', [
|
||||
':url' => 'https://www.drupal.org/node/2573241',
|
||||
])
|
||||
]),
|
||||
];
|
||||
|
||||
// Build the form.
|
||||
@@ -123,7 +120,7 @@ class MigrationFormBase extends EntityForm {
|
||||
* The entity ID.
|
||||
* @param array $element
|
||||
* The form element.
|
||||
* @param FormStateInterface $form_state
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
*
|
||||
* @return bool
|
||||
@@ -164,14 +161,7 @@ class MigrationFormBase extends EntityForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides Drupal\Core\Entity\EntityFormController::save().
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
*
|
||||
* @return $this
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$migration = $this->getEntity();
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ use Drupal\Core\Url;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class MigrationGroupDeleteForm.
|
||||
* Provides the delete form for our Migration Group entity.
|
||||
*
|
||||
* @package Drupal\migrate_tools\Form
|
||||
*
|
||||
@@ -23,7 +23,7 @@ class MigrationGroupDeleteForm extends EntityConfirmFormBase {
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to delete migration group %label?', [
|
||||
'%label' => $this->entity->label(),
|
||||
'%label' => $this->entity->label(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Drupal\migrate_tools\Form;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class MigrationGroupEditForm
|
||||
*
|
||||
* Provides the edit form for our Migration Group entity.
|
||||
*
|
||||
* @package Drupal\migrate_tools\Form
|
||||
|
||||
+9
-19
@@ -17,6 +17,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
class MigrationGroupFormBase extends EntityForm {
|
||||
|
||||
/**
|
||||
* The query factory service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQueryFactory;
|
||||
@@ -24,10 +26,10 @@ class MigrationGroupFormBase extends EntityForm {
|
||||
/**
|
||||
* Construct the MigrationGroupFormBase.
|
||||
*
|
||||
* For simple entity forms, there's no need for a constructor. Our migration group form
|
||||
* base, however, requires an entity query factory to be injected into it
|
||||
* from the container. We later use this query factory to build an entity
|
||||
* query for the exists() method.
|
||||
* For simple entity forms, there's no need for a constructor. Our migration
|
||||
* group form base, however, requires an entity query factory to be injected
|
||||
* into it from the container. We later use this query factory to build an
|
||||
* entity query for the exists() method.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
|
||||
* An entity query factory for the migration group entity type.
|
||||
@@ -37,12 +39,7 @@ class MigrationGroupFormBase extends EntityForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for MigrationGroupFormBase.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
* A container interface service.
|
||||
*
|
||||
* @return \Drupal\migrate_tools\Form\MigrationFormBase
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('entity.query'));
|
||||
@@ -112,7 +109,7 @@ class MigrationGroupFormBase extends EntityForm {
|
||||
* The entity ID.
|
||||
* @param array $element
|
||||
* The form element.
|
||||
* @param FormStateInterface $form_state
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
*
|
||||
* @return bool
|
||||
@@ -153,14 +150,7 @@ class MigrationGroupFormBase extends EntityForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides Drupal\Core\Entity\EntityFormController::save().
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
*
|
||||
* @return $this
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$migration_group = $this->getEntity();
|
||||
|
||||
@@ -66,8 +66,9 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
* Sets the current batch content so listeners can update the messages.
|
||||
*
|
||||
* @param array $context
|
||||
* The batch context.
|
||||
*/
|
||||
public function setBatchContext(&$context) {
|
||||
public function setBatchContext(array &$context) {
|
||||
$this->batchContext = &$context;
|
||||
}
|
||||
|
||||
@@ -75,6 +76,7 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
* Gets a reference to the current batch context.
|
||||
*
|
||||
* @return array
|
||||
* The batch context.
|
||||
*/
|
||||
public function &getBatchContext() {
|
||||
return $this->batchContext;
|
||||
@@ -90,7 +92,7 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
$operations = $this->batchOperations([$this->migration], 'import', [
|
||||
'limit' => $this->itemLimit,
|
||||
'update' => $this->updateExistingRows,
|
||||
'force' => $this->checkDependencies
|
||||
'force' => $this->checkDependencies,
|
||||
]);
|
||||
|
||||
if (count($operations) > 0) {
|
||||
@@ -110,20 +112,18 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
/**
|
||||
* Helper to generate the batch operations for importing migrations.
|
||||
*
|
||||
* @param array $migrations
|
||||
* @param array $operation
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
|
||||
* The migrations.
|
||||
* @param string $operation
|
||||
* The batch operation to perform.
|
||||
* @param array $options
|
||||
* The migration options.
|
||||
*
|
||||
* @return array
|
||||
* The batch operations to perform.
|
||||
*/
|
||||
protected function batchOperations($migrations, $operation, $options = []) {
|
||||
|
||||
protected function batchOperations(array $migrations, $operation, array $options = []) {
|
||||
$operations = [];
|
||||
|
||||
/**
|
||||
* @var string $id
|
||||
* @var Migration $migration
|
||||
*/
|
||||
foreach ($migrations as $id => $migration) {
|
||||
|
||||
if (!empty($options['update'])) {
|
||||
@@ -143,14 +143,14 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
$operations += $this->batchOperations($required_migrations, $operation, [
|
||||
'limit' => 0,
|
||||
'update' => $options['update'],
|
||||
'force' => $options['force']
|
||||
'force' => $options['force'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$operations[] = [
|
||||
'\Drupal\migrate_tools\MigrateBatchExecutable::batchProcessImport',
|
||||
[$migration->id(), $options]
|
||||
[$migration->id(), $options],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -158,15 +158,16 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch 'operation' callback
|
||||
* Batch 'operation' callback.
|
||||
*
|
||||
* @param string $migration_id
|
||||
* The migration id.
|
||||
* @param array $options
|
||||
* The batch executable options.
|
||||
* @param array $context
|
||||
*
|
||||
* The sandbox context.
|
||||
*/
|
||||
static public function batchProcessImport($migration_id, $options, &$context) {
|
||||
|
||||
public static function batchProcessImport($migration_id, array $options, array &$context) {
|
||||
if (empty($context['sandbox'])) {
|
||||
$context['finished'] = 0;
|
||||
$context['sandbox'] = [];
|
||||
@@ -178,7 +179,7 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
|
||||
// Prepare the migration executable.
|
||||
$message = new MigrateMessage();
|
||||
/** @var MigrationInterface $migration */
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = \Drupal::getContainer()->get('plugin.manager.migration')->createInstance($migration_id);
|
||||
$executable = new MigrateBatchExecutable($migration, $message, $options);
|
||||
|
||||
@@ -191,7 +192,7 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
'@updated' => 0,
|
||||
'@failures' => 0,
|
||||
'@ignored' => 0,
|
||||
'@name' => $migration->id()
|
||||
'@name' => $migration->id(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -204,14 +205,14 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
// Do the import.
|
||||
$result = $executable->import();
|
||||
|
||||
// Store the result, we will need to combine the results of all our iterations.
|
||||
// Store the result; will need to combine the results of all our iterations.
|
||||
$context['results'][$migration->id()] = [
|
||||
'@numitems' => $context['results'][$migration->id()]['@numitems'] + $executable->getProcessedCount(),
|
||||
'@created' => $context['results'][$migration->id()]['@created'] + $executable->getCreatedCount(),
|
||||
'@updated' => $context['results'][$migration->id()]['@updated'] + $executable->getUpdatedCount(),
|
||||
'@failures' => $context['results'][$migration->id()]['@failures'] + $executable->getFailedCount(),
|
||||
'@ignored' => $context['results'][$migration->id()]['@ignored'] + $executable->getIgnoredCount(),
|
||||
'@name' => $migration->id()
|
||||
'@name' => $migration->id(),
|
||||
];
|
||||
|
||||
// Do some housekeeping.
|
||||
@@ -226,7 +227,7 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
$context['finished'] = ((float) $context['sandbox']['counter'] / (float) $context['sandbox']['total']);
|
||||
$context['message'] = t('Importing %migration (@percent%).', [
|
||||
'%migration' => $migration->label(),
|
||||
'@percent' => (int) ($context['finished'] * 100)
|
||||
'@percent' => (int) ($context['finished'] * 100),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -236,12 +237,14 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
/**
|
||||
* Finished callback for import batches.
|
||||
*
|
||||
* @param $success
|
||||
* @param $results
|
||||
* @param $operations
|
||||
* @param $elapsed
|
||||
* @param bool $success
|
||||
* A boolean indicating whether the batch has completed successfully.
|
||||
* @param array $results
|
||||
* The value set in $context['results'] by callback_batch_operation().
|
||||
* @param array $operations
|
||||
* If $success is FALSE, contains the operations that remained unprocessed.
|
||||
*/
|
||||
static public function batchFinishedImport($success, $results, $operations, $elapsed) {
|
||||
public static function batchFinishedImport($success, array $results, array $operations) {
|
||||
if ($success) {
|
||||
foreach ($results as $migration_id => $result) {
|
||||
$singular_message = "Processed 1 item (@created created, @updated updated, @failures failed, @ignored ignored) - done with '@name'";
|
||||
@@ -255,7 +258,7 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkStatus() {
|
||||
$status = parent::checkStatus();
|
||||
@@ -278,11 +281,13 @@ class MigrateBatchExecutable extends MigrateExecutable {
|
||||
/**
|
||||
* Calculates how much a single batch iteration will handle.
|
||||
*
|
||||
* @param $context
|
||||
* @param array $context
|
||||
* The sandbox context.
|
||||
*
|
||||
* @return float
|
||||
* The batch limit.
|
||||
*/
|
||||
public function calculateBatchLimit($context) {
|
||||
public function calculateBatchLimit(array $context) {
|
||||
// TODO Maybe we need some other more sophisticated logic here?
|
||||
return ceil($context['sandbox']['total'] / 100);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ use Drupal\migrate\Event\MigrateMapDeleteEvent;
|
||||
use Drupal\migrate\Event\MigrateImportEvent;
|
||||
use Drupal\migrate_plus\Event\MigratePrepareRowEvent;
|
||||
|
||||
/**
|
||||
* Defines a migrate executable class for drush.
|
||||
*/
|
||||
class MigrateExecutable extends MigrateExecutableBase {
|
||||
|
||||
/**
|
||||
@@ -40,8 +43,9 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
protected $deleteCounter = 0;
|
||||
|
||||
/**
|
||||
* Maximum number of items to process in this migration. 0 indicates no limit
|
||||
* is to be applied.
|
||||
* Maximum number of items to process in this migration.
|
||||
*
|
||||
* 0 indicates no limit is to be applied.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
@@ -63,6 +67,7 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
|
||||
/**
|
||||
* Count of number of items processed so far in this migration.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $counter = 0;
|
||||
@@ -149,6 +154,7 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
* Return the number of items created.
|
||||
*
|
||||
* @return int
|
||||
* The number of items created.
|
||||
*/
|
||||
public function getCreatedCount() {
|
||||
return $this->saveCounters[MigrateIdMapInterface::STATUS_IMPORTED];
|
||||
@@ -158,6 +164,7 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
* Return the number of items updated.
|
||||
*
|
||||
* @return int
|
||||
* The updated count.
|
||||
*/
|
||||
public function getUpdatedCount() {
|
||||
return $this->saveCounters[MigrateIdMapInterface::STATUS_NEEDS_UPDATE];
|
||||
@@ -167,6 +174,7 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
* Return the number of items ignored.
|
||||
*
|
||||
* @return int
|
||||
* The ignored count.
|
||||
*/
|
||||
public function getIgnoredCount() {
|
||||
return $this->saveCounters[MigrateIdMapInterface::STATUS_IGNORED];
|
||||
@@ -176,17 +184,20 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
* Return the number of items that failed.
|
||||
*
|
||||
* @return int
|
||||
* The failed count.
|
||||
*/
|
||||
public function getFailedCount() {
|
||||
return $this->saveCounters[MigrateIdMapInterface::STATUS_FAILED];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the total number of items processed. Note that STATUS_NEEDS_UPDATE
|
||||
* is not counted, since this is typically set on stubs created as side
|
||||
* effects, not on the primary item being imported.
|
||||
* Return the total number of items processed.
|
||||
*
|
||||
* Note that STATUS_NEEDS_UPDATE is not counted, since this is typically set
|
||||
* on stubs created as side effects, not on the primary item being imported.
|
||||
*
|
||||
* @return int
|
||||
* The processed count.
|
||||
*/
|
||||
public function getProcessedCount() {
|
||||
return $this->saveCounters[MigrateIdMapInterface::STATUS_IMPORTED] +
|
||||
@@ -199,6 +210,7 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
* Return the number of items rolled back.
|
||||
*
|
||||
* @return int
|
||||
* The rollback count.
|
||||
*/
|
||||
public function getRollbackCount() {
|
||||
return $this->deleteCounter;
|
||||
@@ -237,10 +249,12 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit information on what we've done since the last feedback (or the
|
||||
* beginning of this migration).
|
||||
* Emit information on what we've done.
|
||||
*
|
||||
* Either since the last feedback or the beginning of this migration.
|
||||
*
|
||||
* @param bool $done
|
||||
* TRUE if this is the last items to process. Otherwise FALSE.
|
||||
*/
|
||||
protected function progressMessage($done = TRUE) {
|
||||
$processed = $this->getProcessedCount();
|
||||
@@ -254,12 +268,15 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
}
|
||||
$this->message->display(\Drupal::translation()->formatPlural($processed,
|
||||
$singular_message, $plural_message,
|
||||
['@numitems' => $processed,
|
||||
'@created' => $this->getCreatedCount(),
|
||||
'@updated' => $this->getUpdatedCount(),
|
||||
'@failures' => $this->getFailedCount(),
|
||||
'@ignored' => $this->getIgnoredCount(),
|
||||
'@name' => $this->migration->id()]));
|
||||
[
|
||||
'@numitems' => $processed,
|
||||
'@created' => $this->getCreatedCount(),
|
||||
'@updated' => $this->getUpdatedCount(),
|
||||
'@failures' => $this->getFailedCount(),
|
||||
'@ignored' => $this->getIgnoredCount(),
|
||||
'@name' => $this->migration->id(),
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,10 +291,12 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit information on what we've done since the last feedback (or the
|
||||
* beginning of this migration).
|
||||
* Emit information on what we've done.
|
||||
*
|
||||
* Either since the last feedback or the beginning of this migration.
|
||||
*
|
||||
* @param bool $done
|
||||
* TRUE if this is the last items to rollback. Otherwise FALSE.
|
||||
*/
|
||||
protected function rollbackMessage($done = TRUE) {
|
||||
$rolled_back = $this->getRollbackCount();
|
||||
@@ -290,9 +309,12 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
$plural_message = "Rolled back @numitems items - continuing with '@name'";
|
||||
}
|
||||
$this->message->display(\Drupal::translation()->formatPlural($rolled_back,
|
||||
$singular_message, $plural_message,
|
||||
['@numitems' => $rolled_back,
|
||||
'@name' => $this->migration->id()]));
|
||||
$singular_message, $plural_message,
|
||||
[
|
||||
'@numitems' => $rolled_back,
|
||||
'@name' => $this->migration->id(),
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,9 +357,8 @@ class MigrateExecutable extends MigrateExecutableBase {
|
||||
public function onPrepareRow(MigratePrepareRowEvent $event) {
|
||||
if (!empty($this->idlist)) {
|
||||
$row = $event->getRow();
|
||||
/**
|
||||
* @TODO replace for $source_id = $row->getSourceIdValues(); when https://www.drupal.org/node/2698023 is fixed
|
||||
*/
|
||||
// TODO: replace for $source_id = $row->getSourceIdValues();
|
||||
// when https://www.drupal.org/node/2698023 is fixed.
|
||||
$migration = $event->getMigration();
|
||||
$source_id = array_merge(array_flip(array_keys($migration->getSourcePlugin()
|
||||
->getIds())), $row->getSourceIdValues());
|
||||
|
||||
+3
-3
@@ -7,8 +7,8 @@ dependencies:
|
||||
- drupal:migrate (>=8.3)
|
||||
- migrate_plus:migrate_plus
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-27
|
||||
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_tools'
|
||||
datestamp: 1511790488
|
||||
datestamp: 1519400307
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Execution form test
|
||||
* Execution form test.
|
||||
*
|
||||
* @group migrate_tools
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user