Unverified Commit 73d11b28 authored by alexpott's avatar alexpott

Issue #2500509 by maxocub, quietone, heddn: Upgrade path for RDF 7.x

(cherry picked from commit 0e0105fd)
parent abd11edb
......@@ -70,7 +70,7 @@ protected function getEntityCounts() {
'migration' => 73,
'node' => 5,
'node_type' => 6,
'rdf_mapping' => 7,
'rdf_mapping' => 8,
'search_page' => 2,
'shortcut' => 6,
'shortcut_set' => 2,
......@@ -138,6 +138,7 @@ protected function getAvailablePaths() {
'options',
'path',
'phone',
'rdf',
'search',
'shortcut',
'statistics',
......@@ -167,7 +168,6 @@ protected function getAvailablePaths() {
*/
protected function getMissingPaths() {
return [
'rdf',
// These modules are in the missing path list because they are installed
// on the source site but they are not installed on the destination site.
'syslog',
......
......@@ -76,6 +76,7 @@ protected function getAvailablePaths() {
'path',
'phone',
'profile',
'rdf',
'search',
'shortcut',
'statistics',
......@@ -137,7 +138,6 @@ protected function getAvailablePaths() {
*/
protected function getMissingPaths() {
return [
'rdf',
'views',
];
}
......
......@@ -78,7 +78,7 @@ protected function getEntityCounts() {
'migration' => 73,
'node' => 5,
'node_type' => 6,
'rdf_mapping' => 7,
'rdf_mapping' => 8,
'search_page' => 2,
'shortcut' => 6,
'shortcut_set' => 2,
......@@ -146,6 +146,7 @@ protected function getAvailablePaths() {
'options',
'path',
'phone',
'rdf',
'search',
'shortcut',
'statistics',
......@@ -175,7 +176,6 @@ protected function getAvailablePaths() {
*/
protected function getMissingPaths() {
return [
'rdf',
// These modules are in the missing path list because they are installed
// on the source site but they are not installed on the destination site.
'syslog',
......
id: d7_rdf_mapping
label: Drupal 7 RDF Mappings
migration_tags:
- Drupal 7
- Configuration
source:
plugin: d7_rdf_mapping
process:
targetEntityType: type
bundle: bundle
types: types
fieldMappings:
plugin: sub_process
source: fieldMappings
process:
properties: predicates
datatype: datatype
datatype_callback/callable: callback
mapping_type: type
destination:
plugin: entity:rdf_mapping
migration_dependencies:
optional:
- d7_comment_type
- d7_node_type
- d7_taxonomy_vocabulary
<?php
namespace Drupal\rdf\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 rdf source from database.
*
* @MigrateSource(
* id = "d7_rdf_mapping",
* source_module = "rdf"
* )
*/
class RdfMapping extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('rdf_mapping', 'r')->fields('r');
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$field_mappings = [];
foreach (unserialize($row->getSourceProperty('mapping')) as $field => $mapping) {
if ($field === 'rdftype') {
$row->setSourceProperty('types', $mapping);
}
else {
$field_mappings[$field] = $mapping;
}
}
$row->setSourceProperty('fieldMappings', $field_mappings);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'type' => $this->t('The name of the entity type a mapping applies to (node, user, comment, etc.'),
'bundle' => $this->t('The name of the bundle a mapping applies to.'),
'mapping' => $this->t('The serialized mapping of the bundle type and fields to RDF terms.'),
'types' => $this->t('RDF types.'),
'fieldMappings' => $this->t('RDF field mappings.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'type' => [
'type' => 'string',
],
'bundle' => [
'type' => 'string',
],
];
}
}
<?php
namespace Drupal\Tests\rdf\Kernel\Migrate\d7;
use Drupal\rdf\RdfMappingInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests RDF mappings migration from Drupal 7 to 8.
*
* @group rdf
*/
class MigrateRdfMappingTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'menu_ui',
'node',
'rdf',
'taxonomy',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_taxonomy_vocabulary',
'd7_rdf_mapping',
]);
}
/**
* Asserts various aspects of a RDF mapping.
*
* @param string $entity_type
* The entity type.
* @param string $bundle
* The bundle.
* @param string[] $types
* The expected RDF types.
* @param array[] $field_mappings
* The expected RDF field mappings.
*/
protected function assertRdfMapping($entity_type, $bundle, $types, $field_mappings) {
$rdf_mapping = rdf_get_mapping($entity_type, $bundle);
$this->assertInstanceOf(RdfMappingInterface::class, $rdf_mapping);
$this->assertSame($types, $rdf_mapping->getBundleMapping());
foreach ($field_mappings as $field => $mapping) {
$this->assertSame($mapping, $rdf_mapping->getFieldMapping($field));
}
}
/**
* Tests RDF mappings migration from Drupal 7 to 8.
*/
public function testRdfMappingMigration() {
$this->assertRdfMapping(
'node',
'article',
[
'types' => [
'sioc:Item',
'foaf:Document',
],
],
[
'field_image' => [
'properties' => [
'og:image',
'rdfs:seeAlso',
],
'mapping_type' => 'rel',
],
'field_tags' => [
'properties' => [
'dc:subject',
],
'mapping_type' => 'rel',
],
'title' => [
'properties' => [
'dc:title',
],
],
'created' => [
'properties' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'changed' => [
'properties' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'body' => [
'properties' => [
'content:encoded',
],
],
'uid' => [
'properties' => [
'sioc:has_creator',
],
'mapping_type' => 'rel',
],
'name' => [
'properties' => [
'foaf:name',
],
],
'comment_count' => [
'properties' => [
'sioc:num_replies',
],
'datatype' => 'xsd:integer',
],
'last_activity' => [
'properties' => [
'sioc:last_activity_date',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
]
);
$this->assertRdfMapping(
'node',
'blog',
[
'types' => [
'sioc:Post',
'sioct:BlogPost',
],
],
[
'title' => [
'properties' => [
'dc:title',
],
],
'created' => [
'properties' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'changed' => [
'properties' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'body' => [
'properties' => [
'content:encoded',
],
],
'uid' => [
'properties' => [
'sioc:has_creator',
],
'mapping_type' => 'rel',
],
'name' => [
'properties' => [
'foaf:name',
],
],
'comment_count' => [
'properties' => [
'sioc:num_replies',
],
'datatype' => 'xsd:integer',
],
'last_activity' => [
'properties' => [
'sioc:last_activity_date',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
]
);
$this->assertRdfMapping(
'node',
'forum',
[
'types' => [
'sioc:Post',
'sioct:BoardPost',
],
],
[
'taxonomy_forums' => [
'properties' => [
'sioc:has_container',
],
'mapping_type' => 'rel',
],
'title' => [
'properties' => [
'dc:title',
],
],
'created' => [
'properties' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'changed' => [
'properties' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'body' => [
'properties' => [
'content:encoded',
],
],
'uid' => [
'properties' => [
'sioc:has_creator',
],
'mapping_type' => 'rel',
],
'name' => [
'properties' => [
'foaf:name',
],
],
'comment_count' => [
'properties' => [
'sioc:num_replies',
],
'datatype' => 'xsd:integer',
],
'last_activity' => [
'properties' => [
'sioc:last_activity_date',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
]
);
$this->assertRdfMapping(
'node',
'page',
[
'types' => [
'foaf:Document',
],
],
[
'title' => [
'properties' => [
'dc:title',
],
],
'created' => [
'properties' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'changed' => [
'properties' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
'body' => [
'properties' => [
'content:encoded',
],
],
'uid' => [
'properties' => [
'sioc:has_creator',
],
'mapping_type' => 'rel',
],
'name' => [
'properties' => [
'foaf:name',
],
],
'comment_count' => [
'properties' => [
'sioc:num_replies',
],
'datatype' => 'xsd:integer',
],
'last_activity' => [
'properties' => [
'sioc:last_activity_date',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'date_iso8601',
],
],
]
);
$this->assertRdfMapping(
'taxonomy_term',
'forums',
[
'types' => [
'sioc:Container',
'sioc:Forum',
],
],
[
'name' => [
'properties' => [
'rdfs:label',
'skos:prefLabel',
],
],
'description' => [
'properties' => [
'skos:definition',
],
],
'vid' => [
'properties' => [
'skos:inScheme',
],
'mapping_type' => 'rel',
],
'parent' => [
'properties' => [
'skos:broader',
],
'mapping_type' => 'rel',
],
]
);
}
}
<?php
namespace Drupal\Tests\rdf\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests Drupal 7 RDF mappings source plugin.
*
* @covers \Drupal\rdf\Plugin\migrate\source\d7\RdfMapping
*
* @group rdf
*/
class RdfMappingTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'comment',
'migrate_drupal',
'node',
'rdf',
'taxonomy',
'user',
];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['rdf_mapping'] = [
[
'type' => 'comment',
'bundle' => 'comment_node_article',
'mapping' => 'a:8:{s:7:"rdftype";a:2:{i:0;s:9:"sioc:Post";i:1;s:13:"sioct:Comment";}s:5:"title";a:1:{s:10:"predicates";a:1:{i:0;s:8:"dc:title";}}s:7:"created";a:3:{s:10:"predicates";a:2:{i:0;s:7:"dc:date";i:1;s:10:"dc:created";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}s:7:"changed";a:3:{s:10:"predicates";a:1:{i:0;s:11:"dc:modified";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}s:12:"comment_body";a:1:{s:10:"predicates";a:1:{i:0;s:15:"content:encoded";}}s:3:"pid";a:2:{s:10:"predicates";a:1:{i:0;s:13:"sioc:reply_of";}s:4:"type";s:3:"rel";}s:3:"uid";a:2:{s:10:"predicates";a:1:{i:0;s:16:"sioc:has_creator";}s:4:"type";s:3:"rel";}s:4:"name";a:1:{s:10:"predicates";a:1:{i:0;s:9:"foaf:name";}}}',
],
[
'type' => 'node',
'bundle' => 'article',
'mapping' => 'a:9:{s:7:"rdftype";a:2:{i:0;s:9:"sioc:Item";i:1;s:13:"foaf:Document";}s:5:"title";a:1:{s:10:"predicates";a:1:{i:0;s:8:"dc:title";}}s:7:"created";a:3:{s:10:"predicates";a:2:{i:0;s:7:"dc:date";i:1;s:10:"dc:created";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}s:7:"changed";a:3:{s:10:"predicates";a:1:{i:0;s:11:"dc:modified";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}s:4:"body";a:1:{s:10:"predicates";a:1:{i:0;s:15:"content:encoded";}}s:3:"uid";a:2:{s:10:"predicates";a:1:{i:0;s:16:"sioc:has_creator";}s:4:"type";s:3:"rel";}s:4:"name";a:1:{s:10:"predicates";a:1:{i:0;s:9:"foaf:name";}}s:13:"comment_count";a:2:{s:10:"predicates";a:1:{i:0;s:16:"sioc:num_replies";}s:8:"datatype";s:11:"xsd:integer";}s:13:"last_activity";a:3:{s:10:"predicates";a:1:{i:0;s:23:"sioc:last_activity_date";}s:8:"datatype";s:12:"xsd:dateTime";s:8:"callback";s:12:"date_iso8601";}}',
],
[
'type' => 'taxonomy_term',
'bundle' => 'tags',
'mapping' => 'a:5:{s:7:"rdftype";a:1:{i:0;s:12:"skos:Concept";}s:4:"name";a:1:{s:10:"predicates";a:2:{i:0;s:10:"rdfs:label";i:1;s:14:"skos:prefLabel";}}s:11:"description";a:1:{s:10:"predicates";a:1:{i:0;s:15:"skos:definition";}}s:3:"vid";a:2:{s:10:"predicates";a:1:{i:0;s:13:"skos:inScheme";}s:4:"type";s:3:"rel";}s:6:"parent";a:2:{s:10:"predicates";a:1:{i:0;s:12:"skos:broader";}s:4:"type";s:3:"rel";}}',
],
[
'type' => 'user',
'bundle' => 'user',
'mapping' => 'a:3:{s:7:"rdftype";a:1:{i:0;s:16:"sioc:UserAccount";}s:4:"name";a:1:{s:10:"predicates";a:1:{i:0;s:9:"foaf:name";}}s:8:"homepage";a:2:{s:10:"predicates";a:1:{i:0;s:9:"foaf:page";}s:4:"type";s:3:"rel";}}',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'type' => 'comment',
'bundle' => 'comment_node_article',
'types' => [
'sioc:Post',
'sioct:Comment',
],
'fieldMappings' => [
'changed' => [
'predicates' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
],
'comment_body' => [
'predicates' => [
'content:encoded',
],
],
'created' => [
'predicates' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
],
'name' => [
'predicates' => [
'foaf:name',
],
],
'pid' => [
'predicates' => [
'sioc:reply_of',
],
'type' => 'rel',
],
'title' => [
'predicates' => [
'dc:title',
],
],
'uid' => [
'predicates' => [
'sioc:has_creator',
],
'type' => 'rel',
],
],
],
[
'type' => 'node',
'bundle' => 'article',
'types' => [
'sioc:Item',
'foaf:Document',
],
'fieldMappings' => [
'body' => [
'predicates' => [
'content:encoded',
],
],
'changed' => [
'predicates' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
],
'comment_count' => [
'predicates' => [
'sioc:num_replies',
],
'datatype' => 'xsd:integer',
],
'created' => [
'predicates' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
],
'last_activity' => [
'predicates' => [
'sioc:last_activity_date',
],
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
],
'name' => [
'predicates' => [
'foaf:name',
],
],
'title' => [
'predicates' => [