Commit 982d01f8 authored by webchick's avatar webchick

Issue #2423103 by phenaproxima, quietone, miguelc303, mikeryan: Migration...

Issue #2423103 by phenaproxima, quietone, miguelc303, mikeryan: Migration Files for Drupal 7 Content
parent 475299e6
......@@ -135,10 +135,10 @@ public function load() {
'type' => 'test_content_type',
'language' => 'en',
'title' => 'A Node',
'uid' => '1',
'uid' => '2',
'status' => '1',
'created' => '1421727515',
'changed' => '1421727515',
'changed' => '1441032132',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
......@@ -148,4 +148,4 @@ public function load() {
}
}
#ad72334d15f155644075803c26757ee5
#06cbcf4df265ff717f83f472c22fdbcf
......@@ -106,7 +106,7 @@ public function load() {
'uid' => '1',
'title' => 'A Node',
'log' => '',
'timestamp' => '1421727515',
'timestamp' => '1441032132',
'status' => '1',
'comment' => '2',
'promote' => '1',
......@@ -115,4 +115,4 @@ public function load() {
}
}
#02a3aed2de9a2df056ef6b81d329213e
#e202cc75a51afc39cabf52cbf0a0f9e2
......@@ -122,7 +122,7 @@ public function load() {
'base' => 'node_content',
'module' => 'node',
'description' => 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.',
'help' => '',
'help' => 'Help text for articles',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '1',
......@@ -136,11 +136,11 @@ public function load() {
'base' => 'blog',
'module' => 'blog',
'description' => 'Use for multi-user blogs. Every user gets a personal blog.',
'help' => '',
'help' => 'Blog away, good sir!',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '0',
'modified' => '0',
'modified' => '1',
'locked' => '1',
'disabled' => '0',
'orig_type' => 'blog',
......@@ -164,11 +164,11 @@ public function load() {
'base' => 'forum',
'module' => 'forum',
'description' => 'A <em>forum topic</em> starts a new discussion thread within a forum.',
'help' => '',
'help' => 'No name-calling, no flame wars. Be nice.',
'has_title' => '1',
'title_label' => 'Subject',
'custom' => '0',
'modified' => '0',
'modified' => '1',
'locked' => '1',
'disabled' => '0',
'orig_type' => 'forum',
......@@ -178,7 +178,7 @@ public function load() {
'base' => 'node_content',
'module' => 'node',
'description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.",
'help' => '',
'help' => 'Help text for basic pages',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '1',
......@@ -192,7 +192,7 @@ public function load() {
'base' => 'node_content',
'module' => 'node',
'description' => 'This is the description of the test content type.',
'help' => '',
'help' => 'Help text for test content type',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '1',
......@@ -204,4 +204,4 @@ public function load() {
}
}
#c3cc0500356b35e3e6b106aabf2c7aac
#9bef45bc61d3712f730ca19ec8be6f21
......@@ -26,17 +26,33 @@ migrate.source.d6_node:
label: 'Drupal 6 node'
mapping:
node_type:
# The node type can be specified both as a string ID of a node type or an
# array of node type IDs, so there is no way to consistently parse this.
type: ignore
type: string
label: 'Node type'
migrate.source.d7_node:
type: migrate_source_sql
label: 'Drupal 7 node'
mapping:
node_type:
type: string
label: 'Node type'
migrate.source.d6_node_revision:
type: migrate_source_sql
label: 'Drupal 6 node'
label: 'Drupal 6 node revision'
mapping:
node_type:
# The node type can be specified both as a string ID of a node type or an
# array of node type IDs, so there is no way to consistently parse this.
type: ignore
type: string
label: 'Node type'
migrate.source.d7_node_revision:
type: migrate_source_sql
label: 'Drupal 7 node revision'
mapping:
node_type:
type: string
label: 'Node type'
migrate.source.d7_node_type:
type: migrate_source_sql
label: 'Drupal 7 node type'
......@@ -16,13 +16,6 @@ process:
default_value: "und"
title: title
uid: node_uid
# Core migrations are designed for replacing the upgrade path and therefore
# all node and user ids are preserved. For that reason we do not need to look-up
# the user id for the node. If you're writing a custom migration, user ids will
# vary from the source site and a lookup as shown below will be required.
# plugin: migration
# migration: d6_user
# source: node_uid
status: status
created: created
changed: changed
......
id: d7_node
label: Drupal 7 nodes
migration_tags:
- Drupal 7
builder:
plugin: d7_node
source:
plugin: d7_node
process:
nid: nid
vid: vid
type: type
langcode:
plugin: default_value
source: language
default_value: "und"
title: title
uid: node_uid
status: status
created: created
changed: changed
promote: promote
sticky: sticky
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
destination:
plugin: entity:node
migration_dependencies:
required:
- d7_user
- d7_node_type
id: d7_node_revision
label: Drupal 7 node revisions
migration_tags:
- Drupal 7
builder:
plugin: d7_node
source:
plugin: d7_node_revision
process:
nid: nid
vid: vid
type: type
langcode:
plugin: default_value
source: language
default_value: "und"
title: title
uid: node_uid
status: status
created: created
changed: changed
promote: promote
sticky: sticky
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
destination:
plugin: entity_revision:node
migration_dependencies:
required:
- d7_node:*
id: d7_node_settings
label: Drupal 7 node configuration
migration_tags:
- Drupal 7
source:
plugin: variable
variables:
- node_admin_theme
process:
use_admin_theme: node_admin_theme
destination:
plugin: config
config_name: node.settings
id: d7_node_title_label
label: Drupal 7 node title label
migration_tags:
- Drupal 7
source:
plugin: d7_node_type
constants:
entity_type: node
field_name: title
process:
entity_type: 'constants/entity_type'
bundle: type
field_name: 'constants/field_name'
label: title_label
destination:
plugin: entity:base_field_override
migration_dependencies:
required:
- d7_node_type
id: d7_node_type
label: Drupal 7 node type configuration
migration_tags:
- Drupal 7
source:
plugin: d7_node_type
constants:
preview: 1 # DRUPAL_OPTIONAL
process:
type: type
name: name
description: description
help: help
title_label: title_label
preview_mode: 'constants/preview'
display_submitted: display_submitted
new_revision: 'options/revision'
create_body: create_body
create_body_label: body_label
destination:
plugin: entity:node_type
<?php
/**
* @file
* Contains \Drupal\node\Plugin\migrate\builder\d7\Node.
*/
namespace Drupal\node\Plugin\migrate\builder\d7;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Plugin\migrate\builder\BuilderBase;
/**
* @PluginID("d7_node")
*/
class Node extends BuilderBase {
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template) {
$migrations = [];
$fields = [];
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();
}
foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) {
$bundle = $node_type->getSourceProperty('type');
$values = $template;
$values['id'] .= '__' . $bundle;
$values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $node_type->getSourceProperty('name')]);
$values['source']['node_type'] = $bundle;
$migration = Migration::create($values);
if (isset($fields['node'][$bundle])) {
foreach (array_keys($fields['node'][$bundle]) as $field) {
$migration->setProcessOfProperty($field, $field);
}
}
$migrations[] = $migration;
}
return $migrations;
}
}
<?php
/**
* @file
* Contains \Drupal\node\Plugin\migrate\source\d7\Node.
*/
namespace Drupal\node\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
/**
* Drupal 7 node source from database.
*
* @MigrateSource(
* id = "d7_node",
* source_provider = "node"
* )
*/
class Node extends FieldableEntity {
/**
* The join options between the node and the node_revisions table.
*/
const JOIN = 'n.vid = nr.vid';
/**
* {@inheritdoc}
*/
public function query() {
// Select node in its last revision.
$query = $this->select('node_revision', 'nr')
->fields('n', array(
'nid',
'type',
'language',
'status',
'created',
'changed',
'comment',
'promote',
'sticky',
'tnid',
'translate',
))
->fields('nr', array(
'vid',
'title',
'log',
'timestamp',
));
$query->addField('n', 'uid', 'node_uid');
$query->addField('nr', 'uid', 'revision_uid');
$query->innerJoin('node', 'n', static::JOIN);
if (isset($this->configuration['node_type'])) {
$query->condition('type', $this->configuration['node_type']);
}
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Get Field API field values.
foreach (array_keys($this->getFields('node', $row->getSourceProperty('type'))) as $field) {
$nid = $row->getSourceProperty('nid');
$vid = $row->getSourceProperty('vid');
$row->setSourceProperty($field, $this->getFieldValues('node', $field, $nid, $vid));
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = array(
'nid' => $this->t('Node ID'),
'type' => $this->t('Type'),
'title' => $this->t('Title'),
'node_uid' => $this->t('Node authored by (uid)'),
'revision_uid' => $this->t('Revision authored by (uid)'),
'created' => $this->t('Created timestamp'),
'changed' => $this->t('Modified timestamp'),
'status' => $this->t('Published'),
'promote' => $this->t('Promoted to front page'),
'sticky' => $this->t('Sticky at top of lists'),
'revision' => $this->t('Create new revision'),
'language' => $this->t('Language (fr, en, ...)'),
'tnid' => $this->t('The translation set id for this node'),
'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
);
return $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['nid']['type'] = 'integer';
$ids['nid']['alias'] = 'n';
return $ids;
}
}
<?php
/**
* @file
* Contains \Drupal\node\Plugin\migrate\source\d7\NodeRevision.
*/
namespace Drupal\node\Plugin\migrate\source\d7;
/**
* Drupal 7 node revision source from database.
*
* @MigrateSource(
* id = "d7_node_revision",
* source_provider = "node"
* )
*/
class NodeRevision extends Node {
/**
* The join options between the node and the node_revisions_table.
*/
const JOIN = 'n.nid = nr.nid AND n.vid <> nr.vid';
/**
* {@inheritdoc}
*/
public function fields() {
// Use all the node fields plus the vid that identifies the version.
return parent::fields() + array(
'vid' => t('The primary identifier for this version.'),
'log' => $this->t('Revision Log message'),
'timestamp' => $this->t('Revision timestamp'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
$ids['vid']['alias'] = 'nr';
return $ids;
}
}
<?php
/**
* @file
* Contains \Drupal\node\Plugin\migrate\source\d7\NodeType.
*/
namespace Drupal\node\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 Node types source from database.
*
* @MigrateSource(
* id = "d7_node_type",
* source_provider = "node"
* )
*/
class NodeType extends DrupalSqlBase {
/**
* The teaser length
*
* @var int
*/
protected $teaserLength;
/**
* Node preview optional / required.
*
* @var int
*/
protected $nodePreview;
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('node_type', 't')->fields('t');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'type' => $this->t('Machine name of the node type.'),
'name' => $this->t('Human name of the node type.'),
'description' => $this->t('Description of the node type.'),
'help' => $this->t('Help text for the node type.'),
'title_label' => $this->t('Title label.'),
'disabled' => $this->t('Flag indicating the node type is enable'),
'base' => $this->t('base node.'),
'custom' => $this->t('Flag.'),
'modified' => $this->t('Flag.'),
'locked' => $this->t('Flag.'),
'orig_type' => $this->t('The original type.'),
'teaser_length' => $this->t('Teaser length'),
);
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$this->teaserLength = $this->variableGet('teaser_length', 600);
$this->nodePreview = $this->variableGet('node_preview', 0);
return parent::initializeIterator();
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$row->setSourceProperty('teaser_length', $this->teaserLength);
$row->setSourceProperty('node_preview', $this->nodePreview);
$type = $row->getSourceProperty('type');
$source_options = $this->variableGet('node_options_' . $type, array('promote', 'sticky'));
$options = array();
foreach (array('promote', 'sticky', 'status', 'revision') as $item) {
$options[$item] = in_array($item, $source_options);
}
$row->setSourceProperty('options', $options);
// Don't create a body field until we prove that this node type has one.
$row->setSourceProperty('create_body', FALSE);
if ($this->moduleExists('field')) {
// Find body field for this node type.
$body = $this->select('field_config_instance', 'fci')
->fields('fci', array('data'))
->condition('entity_type', 'node')
->condition('bundle', $row->getSourceProperty('type'))
->condition('field_name', 'body')
->execute()
->fetchAssoc();
if ($body) {
$row->setSourceProperty('create_body', TRUE);
$body['data'] = unserialize($body['data']);
$row->setSourceProperty('body_label', $body['data']['label']);
}
}
$row->setSourceProperty('display_submitted', $this->variableGet('node_submitted_' . $type, TRUE));
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['type']['type'] = 'string';
return $ids;
}
}
<?php
/**
* @file
* Contains \Drupal\node\Tests\Migrate\d7\MigrateNodeSettingsTest.
*/
namespace Drupal\node\Tests\Migrate\d7;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Upgrade variables to node.settings config object.
*
* @group node
*/
class MigrateNodeSettingsTest extends MigrateDrupal7TestBase {
use SchemaCheckTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d7_node_settings');
}
/**
* Tests migration of node variables to node.settings config object.
*/
public function testAggregatorSettings() {
$config = $this->config('node.settings');
$this->assertEqual(1, $config->get('use_admin_theme'));
}
}
<?php
/**
* @file
* Contains \Drupal\node\Tests\Migrate\d7\MigrateNodeTest.
*/
namespace Drupal\node\Tests\Migrate\d7;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
/**
* Tests node migration.
*
* @group node
*/
class MigrateNodeTest extends MigrateDrupal7TestBase {
static $modules = array('node', 'text', 'filter', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installConfig(['node']);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
$this->executeMigration('d7_user_role');
$this->executeMigration('d7_user');
$this->executeMigration('d7_node_type');
$this->executeMigration('d7_node__test_content_type');
}
/**
* Asserts various aspects of a node.
*
* @param string $id
* The node ID.
* @param string $type
* The node type.
* @param string $langcode
* The expected language code.
* @param string $title
* The expected title.
* @param int $uid
* The expected author ID.
* @param bool $status