Commit 10c624b4 authored by webchick's avatar webchick

Issue #2410875 by phenaproxima, miguelc303, mikeryan, webchick, ultimike,...

Issue #2410875 by phenaproxima, miguelc303, mikeryan, webchick, ultimike, benjy: Migration for Drupal 7 Taxonomy vocabularies and terms
parent 7aa798fb
......@@ -24,10 +24,19 @@ class FieldSettings extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$value = $row->getSourceProperty('settings');
if ($row->getSourceProperty('type') == 'image' && !is_array($value['default_image'])) {
$value['default_image'] = array(
'uuid' => '',
);
switch ($row->getSourceProperty('type')) {
case 'image':
if (!is_array($value['default_image'])) {
$value['default_image'] = array('uuid' => '');
}
break;
case 'taxonomy_term_reference':
$value['target_type'] = 'taxonomy_term';
break;
default:
break;
}
return $value;
......
......@@ -28,7 +28,9 @@ public function query() {
->condition('fci.deleted', 0)
->condition('fc.active', 1)
->condition('fc.deleted', 0)
->condition('fc.storage_active', 1);
->condition('fc.storage_active', 1)
->fields('fc', array('type'));
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
// Optionally filter by entity type and bundle.
......
......@@ -29,6 +29,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
'image',
'link',
'node',
'taxonomy',
'telephone',
'text',
];
......@@ -38,7 +39,11 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
CommentType::create([
'id' => 'comment_node_page',
'label' => $this->randomMachineName(),
......@@ -64,7 +69,6 @@ protected function setUp() {
'label' => $this->randomMachineName(),
])->save();
$this->installEntitySchema('node');
NodeType::create([
'type' => 'page',
'label' => $this->randomMachineName(),
......
......@@ -106,6 +106,13 @@ public function testFields() {
$this->assertEntity('node.field_phone', 'telephone', FALSE, 1);
$this->assertEntity('node.field_date', 'datetime', FALSE, 1);
$this->assertEntity('node.field_date_with_end_time', 'datetime', FALSE, 1);
// Assert that the taxonomy term reference fields are referencing the
// correct entity type.
$field = FieldStorageConfig::load('node.field_term_reference');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.taxonomy_forums');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
}
}
......@@ -2,12 +2,13 @@
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\builder\d6\CckBuilder.
* Contains \Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\builder\d6;
namespace Drupal\migrate_drupal\Plugin\migrate\builder;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Plugin\migrate\builder\BuilderBase;
use Drupal\migrate\Plugin\MigratePluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -24,6 +25,13 @@ abstract class CckBuilder extends BuilderBase implements ContainerFactoryPluginI
*/
protected $cckPluginManager;
/**
* Already-instantiated cckfield plugins, keyed by ID.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[]
*/
protected $cckPluginCache = [];
/**
* Constructs a CckBuilder.
*
......@@ -53,4 +61,22 @@ public static function create(ContainerInterface $container, array $configuratio
);
}
/**
* Gets a cckfield plugin instance.
*
* @param string $field_type
* The field type (plugin ID).
* @param \Drupal\migrate\Entity\MigrationInterface|NULL $migration
* The migration, if any.
*
* @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
* The cckfield plugin instance.
*/
protected function getCckPlugin($field_type, MigrationInterface $migration = NULL) {
if (empty($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $migration);
}
return $this->cckPluginCache[$field_type];
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\builder\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder;
/**
* @PluginID("d6_cck_migration")
......
......@@ -759,6 +759,28 @@ public function load() {
'schema_version' => '-1',
'weight' => '0',
'info' => 'a:10:{s:4:"name";s:14:"FileField Meta";s:11:"description";s:48:"Add metadata gathering and storage to FileField.";s:12:"dependencies";a:2:{i:0;s:9:"filefield";i:1;s:6:"getid3";}s:7:"package";s:3:"CCK";s:4:"core";s:3:"6.x";s:3:"php";s:3:"5.0";s:7:"version";s:8:"6.x-3.11";s:7:"project";s:9:"filefield";s:9:"datestamp";s:10:"1365968724";s:10:"dependents";a:0:{}}',
))->values(array(
'filename' => 'sites/all/modules/imageapi/imageapi.module',
'name' => 'imageapi',
'type' => 'module',
'owner' => '',
'status' => '1',
'throttle' => '0',
'bootstrap' => '0',
'schema_version' => '0',
'weight' => '0',
'info' => 'a:10:{s:4:"name";s:8:"ImageAPI";s:11:"description";s:38:"ImageAPI supporting multiple toolkits.";s:7:"package";s:10:"ImageCache";s:4:"core";s:3:"6.x";s:3:"php";s:3:"5.1";s:7:"version";s:8:"6.x-1.10";s:7:"project";s:8:"imageapi";s:9:"datestamp";s:10:"1305563215";s:12:"dependencies";a:0:{}s:10:"dependents";a:0:{}}',
))->values(array(
'filename' => 'sites/all/modules/imagecache/imagecache.module',
'name' => 'imagecache',
'type' => 'module',
'owner' => '',
'status' => '1',
'throttle' => '0',
'bootstrap' => '0',
'schema_version' => '6001',
'weight' => '0',
'info' => 'a:10:{s:4:"name";s:8:"ImageAPI";s:11:"description";s:38:"ImageAPI supporting multiple toolkits.";s:7:"package";s:10:"ImageCache";s:4:"core";s:3:"6.x";s:3:"php";s:3:"5.1";s:7:"version";s:8:"6.x-1.10";s:7:"project";s:8:"imageapi";s:9:"datestamp";s:10:"1305563215";s:12:"dependencies";a:0:{}s:10:"dependents";a:0:{}}',
))->values(array(
'filename' => 'sites/all/modules/imagefield/imagefield.module',
'name' => 'imagefield',
......@@ -847,28 +869,6 @@ public function load() {
'schema_version' => '-1',
'weight' => '0',
'info' => 'a:10:{s:4:"name";s:8:"Views UI";s:11:"description";s:93:"Administrative interface to views. Without this module, you cannot create or edit your views.";s:7:"package";s:5:"Views";s:4:"core";s:3:"6.x";s:12:"dependencies";a:1:{i:0;s:5:"views";}s:7:"version";s:7:"6.x-3.0";s:7:"project";s:5:"views";s:9:"datestamp";s:10:"1325638545";s:10:"dependents";a:0:{}s:3:"php";s:5:"4.3.5";}',
))->values(array(
'filename' => 'sites/all/modules/imageapi/imageapi.module',
'name' => 'imageapi',
'type' => 'module',
'owner' => '',
'status' => '1',
'throttle' => '0',
'bootstrap' => '0',
'schema_version' => '0',
'weight' => '0',
'info' => 'a:10:{s:4:"name";s:8:"ImageAPI";s:11:"description";s:38:"ImageAPI supporting multiple toolkits.";s:7:"package";s:10:"ImageCache";s:4:"core";s:3:"6.x";s:3:"php";s:3:"5.1";s:7:"version";s:8:"6.x-1.10";s:7:"project";s:8:"imageapi";s:9:"datestamp";s:10:"1305563215";s:12:"dependencies";a:0:{}s:10:"dependents";a:0:{}}',
))->values(array(
'filename' => 'sites/all/modules/imagecache/imagecache.module',
'name' => 'imagecache',
'type' => 'module',
'owner' => '',
'status' => '1',
'throttle' => '0',
'bootstrap' => '0',
'schema_version' => '6001',
'weight' => '0',
'info' => 'a:10:{s:4:"name";s:8:"ImageAPI";s:11:"description";s:38:"ImageAPI supporting multiple toolkits.";s:7:"package";s:10:"ImageCache";s:4:"core";s:3:"6.x";s:3:"php";s:3:"5.1";s:7:"version";s:8:"6.x-1.10";s:7:"project";s:8:"imageapi";s:9:"datestamp";s:10:"1305563215";s:12:"dependencies";a:0:{}s:10:"dependents";a:0:{}}',
))->values(array(
'filename' => 'themes/bluemarine/bluemarine.info',
'name' => 'bluemarine',
......@@ -939,4 +939,4 @@ public function load() {
}
}
#f7d26efda87933cbe199c1f232d329b2
#67a0176adb132bf6a171a703fa411e49
......@@ -101,8 +101,19 @@ public function load() {
'body_summary',
'body_format',
))
->execute();
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'body_value' => "...is that it's the absolute best show ever. Trust me, I would know.",
'body_summary' => '',
'body_format' => 'filtered_html',
))->execute();
}
}
#58f5b8a4637fcf4163189ea05cf087f7
#7fc3d3e12c126c8ef003d5f5ef2b8837
......@@ -90,8 +90,35 @@ public function load() {
'delta',
'field_tags_tid',
))
->execute();
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'field_tags_tid' => '9',
))->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '1',
'field_tags_tid' => '14',
))->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '2',
'field_tags_tid' => '17',
))->execute();
}
}
#9e0f85739f8ae8d2c27054edb43f388d
#b72078545dd0cae56f1c0b4698d064ad
......@@ -102,8 +102,19 @@ public function load() {
'body_summary',
'body_format',
))
->execute();
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'body_value' => "...is that it's the absolute best show ever. Trust me, I would know.",
'body_summary' => '',
'body_format' => 'filtered_html',
))->execute();
}
}
#088085ffa6940ff7b87442b920d39de3
#eb2f8f6fd180db91769e5e2a6d5ff950
......@@ -91,8 +91,35 @@ public function load() {
'delta',
'field_tags_tid',
))
->execute();
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'field_tags_tid' => '9',
))->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '1',
'field_tags_tid' => '14',
))->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '2',
'field_tags_tid' => '17',
))->execute();
}
}
#16ce847952ff261838323685dcf2dbc3
#3e8379dcd102dc753b93a396fa3e553c
......@@ -144,8 +144,23 @@ public function load() {
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
))->values(array(
'nid' => '2',
'vid' => '2',
'type' => 'article',
'language' => 'en',
'title' => 'The thing about Deep Space 9',
'uid' => '2',
'status' => '1',
'created' => '1441306772',
'changed' => '1441306832',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
))->execute();
}
}
#06cbcf4df265ff717f83f472c22fdbcf
#c0239fe20ab594399f7d89ece5d1705f
......@@ -111,8 +111,19 @@ public function load() {
'comment' => '2',
'promote' => '1',
'sticky' => '0',
))->values(array(
'nid' => '2',
'vid' => '2',
'uid' => '1',
'title' => 'The thing about Deep Space 9',
'log' => '',
'timestamp' => '1441306832',
'status' => '1',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
))->execute();
}
}
#e202cc75a51afc39cabf52cbf0a0f9e2
#e111edf15130b7307ccaffac6f8f9b6f
......@@ -62,8 +62,23 @@ public function load() {
'tid' => '4',
'sticky' => '0',
'created' => '1421727515',
))->values(array(
'nid' => '2',
'tid' => '9',
'sticky' => '0',
'created' => '1441306772',
))->values(array(
'nid' => '2',
'tid' => '14',
'sticky' => '0',
'created' => '1441306772',
))->values(array(
'nid' => '2',
'tid' => '17',
'sticky' => '0',
'created' => '1441306772',
))->execute();
}
}
#8204d7c1b294ccb506b5106f410bfa37
#c5beb19e23b4c7867ff9ea86a4d5b3ac
......@@ -127,8 +127,78 @@ public function load() {
'description' => '',
'format' => NULL,
'weight' => '0',
))->values(array(
'tid' => '9',
'vid' => '1',
'name' => 'Benjamin Sisko',
'description' => 'Portrayed by Avery Brooks',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '10',
'vid' => '1',
'name' => 'Kira Nerys',
'description' => 'Portrayed by Nana Visitor',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '11',
'vid' => '1',
'name' => 'Dax',
'description' => 'Portrayed by Terry Farrell',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '12',
'vid' => '1',
'name' => 'Jake Sisko',
'description' => 'Portrayed by Cirroc Lofton',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '13',
'vid' => '1',
'name' => 'Gul Dukat',
'description' => 'Portrayed by Marc Alaimo',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '14',
'vid' => '1',
'name' => 'Odo',
'description' => 'Portrayed by Rene Auberjonois',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '15',
'vid' => '1',
'name' => 'Worf',
'description' => 'Portrayed by Michael Dorn',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '16',
'vid' => '1',
'name' => "Miles O'Brien",
'description' => 'Portrayed by Colm Meaney',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '17',
'vid' => '1',
'name' => 'Quark',
'description' => 'Portrayed by Armin Shimerman',
'format' => 'filtered_html',
'weight' => '0',
))->values(array(
'tid' => '18',
'vid' => '1',
'name' => 'Elim Garak',
'description' => 'Portrayed by Andrew Robinson',
'format' => 'filtered_html',
'weight' => '0',
))->execute();
}
}
#77a4e5089be7384cbdf2b8c42efc2707
#96a4d71a6a8cfeef1c1b40e49ae22f16
......@@ -62,6 +62,36 @@ public function load() {
))->values(array(
'tid' => '6',
'parent' => '0',
))->values(array(
'tid' => '9',
'parent' => '0',
))->values(array(
'tid' => '10',
'parent' => '0',
))->values(array(
'tid' => '11',
'parent' => '0',
))->values(array(
'tid' => '12',
'parent' => '0',
))->values(array(
'tid' => '13',
'parent' => '0',
))->values(array(
'tid' => '14',
'parent' => '0',
))->values(array(
'tid' => '15',
'parent' => '0',
))->values(array(
'tid' => '16',
'parent' => '0',
))->values(array(
'tid' => '17',
'parent' => '0',
))->values(array(
'tid' => '18',
'parent' => '0',
))->values(array(
'tid' => '4',
'parent' => '3',
......@@ -75,4 +105,4 @@ public function load() {
}
}
#ea3220ca740097f9251ba194e9bd736d
#d93023562f8865e1410e3299511294d7
......@@ -124,7 +124,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
'd6_system_performance',
'd6_system_rss',
'd6_system_site',
'd6_taxonomy_settings',
'taxonomy_settings',
'd6_taxonomy_term',
'd6_taxonomy_vocabulary',
'd6_term_node_revision:*',
......
......@@ -8,45 +8,26 @@
namespace Drupal\node\Plugin\migrate\builder\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\builder\d6\CckBuilder;
use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder;
/**
* @PluginID("d6_node")
*/
class Node extends CckBuilder {
/**
* Already-instantiated cckfield plugins, keyed by ID.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[]
*/
protected $cckPluginCache = [];
/**
* Gets a cckfield plugin instance.
*
* @param string $field_type
* The field type (plugin ID).
* @param \Drupal\migrate\Entity\MigrationInterface|NULL $migration
* The migration, if any.
*
* @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
* The cckfield plugin instance.
*/
protected function getCckPlugin($field_type, MigrationInterface $migration = NULL) {
if (empty($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $migration);
}
return $this->cckPluginCache[$field_type];
}
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template) {
$migrations = [];
// Read all CCK field instance definitions in the source database.
$fields = array();
foreach ($this->getSourcePlugin('d6_field_instance', $template['source']) as $field) {
$info = $field->getSource();
$fields[$info['type_name']][$info['field_name']] = $info;
}
foreach ($this->getSourcePlugin('d6_node_type', $template['source']) as $row) {
$node_type = $row->getSourceProperty('type');
$values = $template;
......@@ -56,16 +37,15 @@ public function buildMigrations(array $template) {
$values['source']['node_type'] = $node_type;
$migration = Migration::create($values);
$fields = $this->getSourcePlugin('d6_field_instance', ['node_type' => $node_type] + $template['source']);
foreach ($fields as $field) {
$data = $field->getSource();
if ($this->cckPluginManager->hasDefinition($data['type'])) {
$this->getCckPlugin($data['type'])
->processCckFieldValues($migration, $data['field_name'], $data);
}
else {
$migration->setProcessOfProperty($data['field_name'], $data['field_name']);
if (isset($fields[$node_type])) {
foreach ($fields[$node_type] as $field => $info) {
if ($this->cckPluginManager->hasDefinition($info['type'])) {
$this->getCckPlugin($info['type'])
->processCckFieldValues($migration, $field, $info);
}
else {
$migration->setProcessOfProperty($field, $field);
}
}
}
......
......@@ -8,12 +8,12 @@
namespace Drupal\node\Plugin\migrate\builder\d7;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Plugin\migrate\builder\BuilderBase;
use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder;
/**
* @PluginID("d7_node")
*/
class Node extends BuilderBase {
class Node extends CckBuilder {
/**
* {@inheritdoc}
......@@ -21,12 +21,11 @@ class Node extends BuilderBase {
public function buildMigrations(array $template) {
$migrations = [];
$fields = [];
// Read all field instance definitions in the source database.
$fields = array();
foreach ($this->getSourcePlugin('d7_field_instance', $template['source']) as $field) {
$entity_type = $field->getSourceProperty('entity_type');
$bundle = $field->getSourceProperty('bundle');
$field_name = $field->getSourceProperty('field_name');
$fields[$entity_type][$bundle][$field_name] = $field->getSource();
$info = $field->getSource();
$fields[$info['entity_type']][$info['bundle']][$info['field_name']] = $info;
}
foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) {
......@@ -38,8 +37,14 @@ public function buildMigrations(array $template) {
$migration = Migration::create($values);
if (isset($fields['node'][$bundle])) {
foreach (array_keys($fields['node'][$bundle]) as $field) {
$migration->setProcessOfProperty($field, $field);
foreach ($fields['node'][$bundle] as $field => $data) {
if ($this->cckPluginManager->hasDefinition($data['type'])) {
$this->getCckPlugin($data['type'])
->processCckFieldValues($migration, $field, $data);
}
else {
$migration->setProcessOfProperty($field, $field);
}
}
}
......
......@@ -26,6 +26,7 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
'image',
'link',
'node',
'taxonomy',
'telephone',
'text',
);
......@@ -38,6 +39,7 @@ protected function setUp() {
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(static::$modules);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
......
......@@ -3,7 +3,7 @@ label: Drupal 6 taxonomy terms
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_term
plugin: taxonomy_term
process:
tid: tid
vid:
......@@ -14,13 +14,9 @@ process: