Commit 498bcc79 authored by alexpott's avatar alexpott

Issue #2376141 by chx, benjy, ultimike, eliza411: Fix node and node revision author ids

parent c4223052
......@@ -180,7 +180,7 @@ protected function executeJoins() {
$fields = array();
foreach ($this->fields as $field_info) {
$this->fieldsWithTable[$field_info['table'] . '.' . $field_info['field']] = $field_info;
$fields[$field_info['table']][$field_info['field']] = NULL;
$fields[$field_info['table']][$field_info['field']] = $field_info['alias'];
}
foreach ($this->tables as $alias => $table_info) {
if ($table = reset($this->databaseContents[$table_info['table']])) {
......@@ -256,8 +256,8 @@ protected function executeJoins() {
*/
protected function getNewRow($table_alias, $fields, $candidate_row, $row = array()) {
$new_row[$table_alias]['all'] = $candidate_row;
foreach ($fields[$table_alias] as $field => $v) {
$new_row[$table_alias]['result'][$field] = $candidate_row[$field];
foreach ($fields[$table_alias] as $field => $alias) {
$new_row[$table_alias]['result'][$alias] = $candidate_row[$field];
}
return $new_row + $row;
}
......
......@@ -13,7 +13,14 @@ process:
source: language
default_value: "und"
title: title
uid: uid
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
......@@ -25,7 +32,7 @@ process:
source: format
'body/value': body
'body/summary': teaser
revision_uid: uid
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
......@@ -39,6 +46,7 @@ destination:
plugin: entity:node
migration_dependencies:
required:
- d6_user
- d6_node_type
- d6_node_settings
- d6_filter_format
......
......@@ -13,7 +13,7 @@ process:
source: language
default_value: "und"
title: title
uid: uid
uid: node_uid
status: status
created: created
changed: changed
......@@ -25,7 +25,7 @@ process:
source: format
'body/value': body
'body/summary': teaser
revision_uid: uid
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
......
......@@ -54,7 +54,6 @@ public function query() {
))
->fields('nr', array(
'vid',
'uid',
'title',
'body',
'teaser',
......@@ -62,6 +61,8 @@ public function query() {
'timestamp',
'format',
));
$query->addField('n', 'uid', 'node_uid');
$query->addField('nr', 'uid', 'revision_uid');
$query->innerJoin('node', 'n', static::JOIN);
if (isset($this->configuration['node_type'])) {
......@@ -90,7 +91,8 @@ public function fields() {
'body' => $this->t('Body'),
'format' => $this->t('Format'),
'teaser' => $this->t('Teaser'),
'uid' => $this->t('Authored by (uid)'),
'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'),
......
......@@ -37,6 +37,10 @@ protected function setUp() {
array(array(1), array('filtered_html')),
array(array(2), array('full_html')),
),
'd6_user' => array(
array(array(1), array(1)),
array(array(2), array(2)),
),
'd6_field_instance_widget_settings' => array(
array(
array('page', 'field_test'),
......
......@@ -86,6 +86,11 @@ class NodeByNodeTypeTest extends MigrateSqlSourceTestCase {
*/
protected function setUp() {
$database_contents = $this->expectedResults;
array_walk($this->expectedResults, function (&$row) {
$row['node_uid'] = $row['uid'];
$row['revision_uid'] = $row['uid'] + 1;
unset($row['uid']);
});
$database_contents[] = array(
// Node fields.
......@@ -115,11 +120,17 @@ protected function setUp() {
// Add another row with an article node and make sure it is not migrated.
foreach ($database_contents as $k => $row) {
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'format', 'timestamp', 'log') as $i => $field) {
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'format', 'timestamp', 'log') as $field) {
$this->databaseContents['node_revisions'][$k][$field] = $row[$field];
// Keep nid and vid.
if ($i > 1) {
unset($row[$field]);
switch ($field) {
case 'nid': case 'vid':
break;
case 'uid':
$this->databaseContents['node_revisions'][$k]['uid']++;
break;
default:
unset($row[$field]);
break;
}
}
$this->databaseContents['node'][$k] = $row;
......
......@@ -109,15 +109,26 @@ class NodeTest extends MigrateSqlSourceTestCase {
*/
protected function setUp() {
foreach ($this->expectedResults as $k => $row) {
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'log', 'timestamp', 'format') as $i => $field) {
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'format', 'timestamp', 'log') as $field) {
$this->databaseContents['node_revisions'][$k][$field] = $row[$field];
// Keep nid and vid.
if ($i > 1) {
unset($row[$field]);
switch ($field) {
case 'nid': case 'vid':
break;
case 'uid':
$this->databaseContents['node_revisions'][$k]['uid']++;
break;
default:
unset($row[$field]);
break;
}
}
$this->databaseContents['node'][$k] = $row;
}
array_walk($this->expectedResults, function (&$row) {
$row['node_uid'] = $row['uid'];
$row['revision_uid'] = $row['uid'] + 1;
unset($row['uid']);
});
parent::setUp();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment