Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
M
migrate_plus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
migrate_plus
Commits
7a526044
Commit
7a526044
authored
Feb 13, 2018
by
heddn
Committed by
heddn
Feb 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2944544
by heddn: Fix failing phpcs testing
parent
81482505
Changes
35
Hide whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
974 additions
and
321 deletions
+974
-321
migrate_example/migrate_example_setup/migrate_example_setup.install
...ample/migrate_example_setup/migrate_example_setup.install
+168
-13
migrate_example/src/Plugin/migrate/source/BeerComment.php
migrate_example/src/Plugin/migrate/source/BeerComment.php
+11
-2
migrate_example/src/Plugin/migrate/source/BeerNode.php
migrate_example/src/Plugin/migrate/source/BeerNode.php
+25
-19
migrate_example/src/Plugin/migrate/source/BeerTerm.php
migrate_example/src/Plugin/migrate/source/BeerTerm.php
+24
-28
migrate_example/src/Plugin/migrate/source/BeerUser.php
migrate_example/src/Plugin/migrate/source/BeerUser.php
+25
-20
migrate_example_advanced/migrate_example_advanced.install
migrate_example_advanced/migrate_example_advanced.install
+6
-6
migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.install
...ple_advanced_setup/migrate_example_advanced_setup.install
+366
-40
migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyItems.php
..._advanced_setup/src/Plugin/rest/resource/VarietyItems.php
+8
-4
migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php
...nced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php
+8
-4
migrate_example_advanced/src/Plugin/migrate/source/WineTerm.php
...e_example_advanced/src/Plugin/migrate/source/WineTerm.php
+10
-3
phpcs.xml
phpcs.xml
+174
-93
src/Annotation/Authentication.php
src/Annotation/Authentication.php
+1
-1
src/Annotation/DataFetcher.php
src/Annotation/DataFetcher.php
+1
-1
src/Annotation/DataParser.php
src/Annotation/DataParser.php
+1
-1
src/AuthenticationPluginManager.php
src/AuthenticationPluginManager.php
+1
-1
src/DataFetcherPluginInterface.php
src/DataFetcherPluginInterface.php
+4
-3
src/DataFetcherPluginManager.php
src/DataFetcherPluginManager.php
+1
-1
src/DataParserPluginBase.php
src/DataParserPluginBase.php
+4
-3
src/DataParserPluginManager.php
src/DataParserPluginManager.php
+1
-1
src/Event/MigrateEvents.php
src/Event/MigrateEvents.php
+2
-1
src/Plugin/migrate/destination/Table.php
src/Plugin/migrate/destination/Table.php
+14
-0
src/Plugin/migrate/process/EntityGenerate.php
src/Plugin/migrate/process/EntityGenerate.php
+1
-1
src/Plugin/migrate/process/EntityLookup.php
src/Plugin/migrate/process/EntityLookup.php
+5
-5
src/Plugin/migrate/process/FileBlob.php
src/Plugin/migrate/process/FileBlob.php
+1
-1
src/Plugin/migrate/process/SkipOnValue.php
src/Plugin/migrate/process/SkipOnValue.php
+4
-4
src/Plugin/migrate/process/StrReplace.php
src/Plugin/migrate/process/StrReplace.php
+26
-26
src/Plugin/migrate/process/Transliteration.php
src/Plugin/migrate/process/Transliteration.php
+3
-3
src/Plugin/migrate_plus/authentication/OAuth2.php
src/Plugin/migrate_plus/authentication/OAuth2.php
+1
-1
src/Plugin/migrate_plus/data_fetcher/Http.php
src/Plugin/migrate_plus/data_fetcher/Http.php
+2
-2
tests/src/Kernel/MigrateTableTest.php
tests/src/Kernel/MigrateTableTest.php
+32
-4
tests/src/Kernel/MigrationConfigEntityTest.php
tests/src/Kernel/MigrationConfigEntityTest.php
+8
-0
tests/src/Kernel/MigrationGroupTest.php
tests/src/Kernel/MigrationGroupTest.php
+33
-25
tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php
.../src/Kernel/Plugin/migrate/process/EntityGenerateTest.php
+2
-2
tests/src/Kernel/Plugin/migrate_plus/data_fetcher/HttpTest.php
.../src/Kernel/Plugin/migrate_plus/data_fetcher/HttpTest.php
+1
-1
tests/src/Unit/process/StrReplaceTest.php
tests/src/Unit/process/StrReplaceTest.php
+0
-1
No files found.
migrate_example/migrate_example_setup/migrate_example_setup.install
View file @
7a526044
...
@@ -2,11 +2,16 @@
...
@@ -2,11 +2,16 @@
/**
/**
* @file
* @file
* Install file for migrate example module.
*
* Set up source data and destination configuration for the migration example
* 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
* module. We do this in a separate module so migrate_example itself is a pure
* migration module.
* migration module.
*/
*/
/**
* Implements hook_schema().
*/
function
migrate_example_setup_schema
()
{
function
migrate_example_setup_schema
()
{
$schema
[
'migrate_example_beer_account'
]
=
migrate_example_beer_schema_account
();
$schema
[
'migrate_example_beer_account'
]
=
migrate_example_beer_schema_account
();
$schema
[
'migrate_example_beer_node'
]
=
migrate_example_beer_schema_node
();
$schema
[
'migrate_example_beer_node'
]
=
migrate_example_beer_schema_node
();
...
@@ -17,6 +22,9 @@ function migrate_example_setup_schema() {
...
@@ -17,6 +22,9 @@ function migrate_example_setup_schema() {
return
$schema
;
return
$schema
;
}
}
/**
* Implements hook_install().
*/
function
migrate_example_setup_install
()
{
function
migrate_example_setup_install
()
{
// Populate our tables.
// Populate our tables.
migrate_example_beer_data_account
();
migrate_example_beer_data_account
();
...
@@ -26,6 +34,12 @@ function migrate_example_setup_install() {
...
@@ -26,6 +34,12 @@ function migrate_example_setup_install() {
migrate_example_beer_data_topic_node
();
migrate_example_beer_data_topic_node
();
}
}
/**
* The hook_schema definition for node.
*
* @return array
* The schema definition.
*/
function
migrate_example_beer_schema_node
()
{
function
migrate_example_beer_schema_node
()
{
return
[
return
[
'description'
=>
'Beers of the world.'
,
'description'
=>
'Beers of the world.'
,
...
@@ -92,6 +106,12 @@ function migrate_example_beer_schema_node() {
...
@@ -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
()
{
function
migrate_example_beer_schema_topic
()
{
return
[
return
[
'description'
=>
'Categories'
,
'description'
=>
'Categories'
,
...
@@ -129,6 +149,12 @@ function migrate_example_beer_schema_topic() {
...
@@ -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
()
{
function
migrate_example_beer_schema_topic_node
()
{
return
[
return
[
'description'
=>
'Beers topic pairs.'
,
'description'
=>
'Beers topic pairs.'
,
...
@@ -149,6 +175,12 @@ function migrate_example_beer_schema_topic_node() {
...
@@ -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
()
{
function
migrate_example_beer_schema_comment
()
{
return
[
return
[
'description'
=>
'Beers comments.'
,
'description'
=>
'Beers comments.'
,
...
@@ -202,6 +234,12 @@ function migrate_example_beer_schema_comment() {
...
@@ -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
()
{
function
migrate_example_beer_schema_account
()
{
return
[
return
[
'description'
=>
'Beers accounts.'
,
'description'
=>
'Beers accounts.'
,
...
@@ -262,16 +300,63 @@ function migrate_example_beer_schema_account() {
...
@@ -262,16 +300,63 @@ function migrate_example_beer_schema_account() {
];
];
}
}
/**
* Populate node table.
*/
function
migrate_example_beer_data_node
()
{
function
migrate_example_beer_data_node
()
{
$fields
=
[
'bid'
,
'name'
,
'body'
,
'excerpt'
,
'countries'
,
'aid'
,
'image'
,
$fields
=
[
'image_alt'
,
'image_title'
,
'image_description'
];
'bid'
,
'name'
,
'body'
,
'excerpt'
,
'countries'
,
'aid'
,
'image'
,
'image_alt'
,
'image_title'
,
'image_description'
,
];
$query
=
db_insert
(
'migrate_example_beer_node'
)
$query
=
db_insert
(
'migrate_example_beer_node'
)
->
fields
(
$fields
);
->
fields
(
$fields
);
// Use high bid numbers to avoid overwriting an existing node id.
// Use high bid numbers to avoid overwriting an existing node id.
$data
=
[
$data
=
[
[
99999999
,
'Heineken'
,
'Blab Blah Blah Green'
,
'Green'
,
'Netherlands|Belgium'
,
0
,
'heineken.jpg'
,
'Heinekin alt'
,
'Heinekin title'
,
'Heinekin description'
],
// comes with migrate_example project.
// 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
],
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
)
{
foreach
(
$data
as
$row
)
{
$query
->
values
(
array_combine
(
$fields
,
$row
));
$query
->
values
(
array_combine
(
$fields
,
$row
));
...
@@ -280,18 +365,65 @@ function migrate_example_beer_data_node() {
...
@@ -280,18 +365,65 @@ function migrate_example_beer_data_node() {
}
}
/**
/**
* Populate account table.
*
* Note that alice has duplicate username. Exercises dedupe_entity plugin.
* Note that alice has duplicate username. Exercises dedupe_entity plugin.
*
@
TODO duplicate email also.
*
TODO duplicate email also.
*/
*/
function
migrate_example_beer_data_account
()
{
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'
)
$query
=
db_insert
(
'migrate_example_beer_account'
)
->
fields
(
$fields
);
->
fields
(
$fields
);
$data
=
[
$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'
],
1
,
[
0
,
'2007-03-15 10:31:05'
,
'bob'
,
'rebob'
,
'bobpass'
,
'bob@example.com'
,
'0'
,
'99999999|99999997'
],
'2010-03-30 10:31:05'
,
[
1
,
'2004-02-29 10:31:05'
,
'charlie'
,
'charlie chocolate'
,
'mykids'
,
'charlie@example.com'
,
'0'
,
'99999999|99999998'
],
'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
)
{
foreach
(
$data
as
$row
)
{
$query
->
values
(
array_combine
(
$fields
,
$row
));
$query
->
values
(
array_combine
(
$fields
,
$row
));
...
@@ -299,6 +431,9 @@ function migrate_example_beer_data_account() {
...
@@ -299,6 +431,9 @@ function migrate_example_beer_data_account() {
$query
->
execute
();
$query
->
execute
();
}
}
/**
* Populate comment table.
*/
function
migrate_example_beer_data_comment
()
{
function
migrate_example_beer_data_comment
()
{
$fields
=
[
'bid'
,
'cid_parent'
,
'subject'
,
'body'
,
'name'
,
'mail'
,
'aid'
];
$fields
=
[
'bid'
,
'cid_parent'
,
'subject'
,
'body'
,
'name'
,
'mail'
,
'aid'
];
$query
=
db_insert
(
'migrate_example_beer_comment'
)
$query
=
db_insert
(
'migrate_example_beer_comment'
)
...
@@ -308,7 +443,15 @@ function migrate_example_beer_data_comment() {
...
@@ -308,7 +443,15 @@ function migrate_example_beer_data_comment() {
[
99999998
,
NULL
,
'im second'
,
'aromatic'
,
'alice'
,
'alice@example.com'
,
0
],
[
99999998
,
NULL
,
'im second'
,
'aromatic'
,
'alice'
,
'alice@example.com'
,
0
],
[
99999999
,
NULL
,
'im parent'
,
'malty'
,
'alice'
,
'alice@example.com'
,
0
],
[
99999999
,
NULL
,
'im parent'
,
'malty'
,
'alice'
,
'alice@example.com'
,
0
],
[
99999999
,
1
,
'im child'
,
'cold body'
,
'bob'
,
NULL
,
1
],
[
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
)
{
foreach
(
$data
as
$row
)
{
$query
->
values
(
array_combine
(
$fields
,
$row
));
$query
->
values
(
array_combine
(
$fields
,
$row
));
...
@@ -316,6 +459,9 @@ function migrate_example_beer_data_comment() {
...
@@ -316,6 +459,9 @@ function migrate_example_beer_data_comment() {
$query
->
execute
();
$query
->
execute
();
}
}
/**
* Populate topic table.
*/
function
migrate_example_beer_data_topic
()
{
function
migrate_example_beer_data_topic
()
{
$fields
=
[
'style'
,
'details'
,
'style_parent'
,
'region'
,
'hoppiness'
];
$fields
=
[
'style'
,
'details'
,
'style_parent'
,
'region'
,
'hoppiness'
];
$query
=
db_insert
(
'migrate_example_beer_topic'
)
$query
=
db_insert
(
'migrate_example_beer_topic'
)
...
@@ -323,7 +469,13 @@ function migrate_example_beer_data_topic() {
...
@@ -323,7 +469,13 @@ function migrate_example_beer_data_topic() {
$data
=
[
$data
=
[
[
'ale'
,
'traditional'
,
NULL
,
'Medieval British Isles'
,
'Medium'
],
[
'ale'
,
'traditional'
,
NULL
,
'Medieval British Isles'
,
'Medium'
],
[
'red ale'
,
'colorful'
,
'ale'
,
NULL
,
NULL
],
[
'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
)
{
foreach
(
$data
as
$row
)
{
$query
->
values
(
array_combine
(
$fields
,
$row
));
$query
->
values
(
array_combine
(
$fields
,
$row
));
...
@@ -331,6 +483,9 @@ function migrate_example_beer_data_topic() {
...
@@ -331,6 +483,9 @@ function migrate_example_beer_data_topic() {
$query
->
execute
();
$query
->
execute
();
}
}
/**
* Populate topic node table.
*/
function
migrate_example_beer_data_topic_node
()
{
function
migrate_example_beer_data_topic_node
()
{
$fields
=
[
'bid'
,
'style'
];
$fields
=
[
'bid'
,
'style'
];
$query
=
db_insert
(
'migrate_example_beer_topic_node'
)
$query
=
db_insert
(
'migrate_example_beer_topic_node'
)
...
...
migrate_example/src/Plugin/migrate/source/BeerComment.php
View file @
7a526044
...
@@ -17,9 +17,18 @@ class BeerComment extends SqlBase {
...
@@ -17,9 +17,18 @@ class BeerComment extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
query
()
{
public
function
query
()
{
$fields
=
[
'cid'
,
'cid_parent'
,
'name'
,
'mail'
,
'aid'
,
'body'
,
'bid'
,
'subject'
,
];
$query
=
$this
->
select
(
'migrate_example_beer_comment'
,
'mec'
)
$query
=
$this
->
select
(
'migrate_example_beer_comment'
,
'mec'
)
->
fields
(
'mec'
,
[
'cid'
,
'cid_parent'
,
'name'
,
'mail'
,
'aid'
,
->
fields
(
'mec'
,
$fields
)
'body'
,
'bid'
,
'subject'
])
->
orderBy
(
'cid_parent'
,
'ASC'
);
->
orderBy
(
'cid_parent'
,
'ASC'
);
return
$query
;
return
$query
;
}
}
...
...
migrate_example/src/Plugin/migrate/source/BeerNode.php
View file @
7a526044
...
@@ -18,21 +18,29 @@ class BeerNode extends SqlBase {
...
@@ -18,21 +18,29 @@ class BeerNode extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
query
()
{
public
function
query
()
{
/**
// An important point to note is that your query *must* return a single row
* 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
* 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
* migrate_example_beer_topic_node in our query, to pull in the
// relationships to our categories. Doing this would cause the query to
* relationships to our categories. Doing this would cause the query to
// return multiple rows for a given node, once per related value, thus
* 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
* 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
* multiple values that should be imported. To avoid that, we simply query
// the base node data here, and pull in the relationships in prepareRow()
* the base node data here, and pull in the relationships in prepareRow()
// below.
* below.
$fields
=
[
*/
'bid'
,
'name'
,
'body'
,
'excerpt'
,
'aid'
,
'countries'
,
'image'
,
'image_alt'
,
'image_title'
,
'image_description'
,
];
$query
=
$this
->
select
(
'migrate_example_beer_node'
,
'b'
)
$query
=
$this
->
select
(
'migrate_example_beer_node'
,
'b'
)
->
fields
(
'b'
,
[
'bid'
,
'name'
,
'body'
,
'excerpt'
,
'aid'
,
->
fields
(
'b'
,
$fields
);
'countries'
,
'image'
,
'image_alt'
,
'image_title'
,
'image_description'
]);
return
$query
;
return
$query
;
}
}
...
@@ -76,11 +84,9 @@ class BeerNode extends SqlBase {
...
@@ -76,11 +84,9 @@ class BeerNode extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
prepareRow
(
Row
$row
)
{
public
function
prepareRow
(
Row
$row
)
{
/**
// As explained above, we need to pull the style relationships into our
* 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
* source row here, as an array of 'style' values (the unique ID for
// the beer_term migration).
* the beer_term migration).
*/
$terms
=
$this
->
select
(
'migrate_example_beer_topic_node'
,
'bt'
)
$terms
=
$this
->
select
(
'migrate_example_beer_topic_node'
,
'bt'
)
->
fields
(
'bt'
,
[
'style'
])
->
fields
(
'bt'
,
[
'style'
])
->
condition
(
'bid'
,
$row
->
getSourceProperty
(
'bid'
))
->
condition
(
'bid'
,
$row
->
getSourceProperty
(
'bid'
))
...
...
migrate_example/src/Plugin/migrate/source/BeerTerm.php
View file @
7a526044
...
@@ -5,11 +5,12 @@ namespace Drupal\migrate_example\Plugin\migrate\source;
...
@@ -5,11 +5,12 @@ namespace Drupal\migrate_example\Plugin\migrate\source;
use
Drupal\migrate\Plugin\migrate\source\SqlBase
;
use
Drupal\migrate\Plugin\migrate\source\SqlBase
;
/**
/**
* This is an example of a simple SQL-based source plugin. Source plugins are
* This is an example of a simple SQL-based source plugin.
* classes which deliver source data to the processing pipeline. For SQL
*
* sources, the SqlBase class provides most of the functionality needed - for
* Source plugins are classes which deliver source data to the processing
* a specific migration, you are required to implement the three simple public
* pipeline. For SQL sources, the SqlBase class provides most of the
* methods you see below.
* 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
* 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
* implemented by this class is "beer_term". This is the name that the migration
...
@@ -25,16 +26,15 @@ class BeerTerm extends SqlBase {
...
@@ -25,16 +26,15 @@ class BeerTerm extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
query
()
{
public
function
query
()
{
/**
// The most important part of a SQL source plugin is the SQL query to
* 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
* retrieve the data to be imported. Note that the query is not executed
// here - the migration process will control execution of the query. Also
* here - the migration process will control execution of the query. Also
// note that it is constructed from a $this->select() call - this ensures
* note that it is constructed from a $this->select() call - this ensures
// that the query is executed against the database configured for this
* that the query is executed against the database configured for this
// source plugin.
* source plugin.
$fields
=
[
'style'
,
'details'
,
'style_parent'
,
'region'
,
'hoppiness'
];
*/
return
$this
->
select
(
'migrate_example_beer_topic'
,
'met'
)
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.
// We sort this way to ensure parent terms are imported first.
->
orderBy
(
'style_parent'
,
'ASC'
);
->
orderBy
(
'style_parent'
,
'ASC'
);
}
}
...
@@ -43,12 +43,10 @@ class BeerTerm extends SqlBase {
...
@@ -43,12 +43,10 @@ class BeerTerm extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
fields
()
{
public
function
fields
()
{
/**
// This method simply documents the available source fields provided by the
* This method simply documents the available source fields provided by
// source plugin, for use by front-end tools. It returns an array keyed by
* the source plugin, for use by front-end tools. It returns an array keyed
// field/column name, with the value being a translated string explaining
* by field/column name, with the value being a translated string explaining
// to humans what the field represents.
* to humans what the field represents. You should always
*/
$fields
=
[
$fields
=
[
'style'
=>
$this
->
t
(
'Beer style'
),
'style'
=>
$this
->
t
(
'Beer style'
),
'details'
=>
$this
->
t
(
'Style details'
),
'details'
=>
$this
->
t
(
'Style details'
),
...
@@ -66,14 +64,12 @@ class BeerTerm extends SqlBase {
...
@@ -66,14 +64,12 @@ class BeerTerm extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
getIds
()
{
public
function
getIds
()
{
/**
// This method indicates what field(s) from the source row uniquely identify
* This method indicates what field(s) from the source row uniquely identify
// that source row, and what their types are. This is critical information
* 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
* 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
* names from the query which comprise the unique identifier. The values are
// arrays indicating the type of the field, used for creating compatible
* arrays indicating the type of the field, used for creating compatible
// columns in the map tables that track processed items.
* columns in the map tables that track processed items.
*/
return
[
return
[
'style'
=>
[
'style'
=>
[
'type'
=>
'string'
,
'type'
=>
'string'
,
...
...
migrate_example/src/Plugin/migrate/source/BeerUser.php
View file @
7a526044
...
@@ -18,9 +18,19 @@ class BeerUser extends SqlBase {
...
@@ -18,9 +18,19 @@ class BeerUser extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
query
()
{
public
function
query
()
{
$fields
=
[
'aid'
,
'status'
,
'registered'
,
'username'
,
'nickname'
,
'password'
,
'email'
,
'sex'
,
'beers'
,
];
return
$this
->
select
(
'migrate_example_beer_account'
,
'mea'
)
return
$this
->
select
(
'migrate_example_beer_account'
,
'mea'
)
->
fields
(
'mea'
,
[
'aid'
,
'status'
,
'registered'
,
'username'
,
'nickname'
,
->
fields
(
'mea'
,
$fields
);
'password'
,
'email'
,
'sex'
,
'beers'
]);
}
}
/**
/**
...
@@ -58,27 +68,22 @@ class BeerUser extends SqlBase {
...
@@ -58,27 +68,22 @@ class BeerUser extends SqlBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
prepareRow
(
Row
$row
)
{
public
function
prepareRow
(
Row
$row
)
{
/**
// A prepareRow() is the most common place to perform custom run-time
* prepareRow() is the most common place to perform custom run-time
// processing that isn't handled by an existing process plugin. It is called
* 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
* 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
* opportunity to modify or add to that data, creating the canonical set of
// source data that will be fed into the processing pipeline.
* 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
* In our particular case, the list of a user's favorite beers is a pipe-
// representing multi-value fields naturally, so we want to explode that
* separated list of beer IDs. The processing pipeline deals with arrays
// string to an array of individual beer IDs.
* representing multi-value fields naturally, so we want to explode that
* string to an array of individual beer IDs.
*/
if
(
$value
=
$row
->
getSourceProperty
(
'beers'
))
{
if
(
$value
=
$row
->
getSourceProperty
(
'beers'
))
{
$row
->
setSourceProperty
(
'beers'
,
explode
(
'|'
,
$value
));
$row
->
setSourceProperty
(
'beers'
,
explode
(
'|'
,
$value
));