diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Node.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Node.php index a55d520..c8a8b2b 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Node.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Node.php @@ -32,27 +32,6 @@ class Node extends Drupal6SqlBase implements RequirementsInterface { protected $joinRevisions = 'n.vid = nr.vid'; /** - * Fields to use from the node table. - */ - protected $nodeFields = array( - 'nid', - 'vid', - 'type', - 'language', - 'title', - 'uid', - 'status', - 'created', - 'changed', - 'comment', - 'promote', - 'moderate', - 'sticky', - 'tnid', - 'translate' - ); - - /** * {@inheritdoc} * * This also includes data from CCK fields. @@ -61,7 +40,23 @@ class Node extends Drupal6SqlBase implements RequirementsInterface { public function query() { // Select node in its last revision. $query = $this->select('node', 'n') - ->fields('n', $this->nodeFields); + ->fields('n', array( + 'nid', + 'vid', + 'type', + 'language', + 'title', + 'uid', + 'status', + 'created', + 'changed', + 'comment', + 'promote', + 'moderate', + 'sticky', + 'tnid', + 'translate' + )); $query->innerJoin('node_revisions', 'nr', $this->joinRevisions); $query->fields('nr', array('body', 'teaser', 'format')); @@ -77,7 +72,7 @@ public function prepareRow(Row $row) { // Pick up simple CCK fields. $cck_table = "content_type_$type"; if ($this->getDatabase()->schema()->tableExists($cck_table)) { - $query = $this->query()->condition('n.vid', $row->getSourceProperty('vid')); + $query = $this->select($cck_table, 'f')->condition('vid', $row->getSourceProperty('vid')); // The main column for the field should be rendered with the field name, // not the column name (e.g., field_foo rather than field_foo_value). $field_info = $this->getSourceFieldInfo($type); @@ -110,13 +105,13 @@ public function prepareRow(Row $row) { } } } - } - $results = $query->execute()->fetchAssoc(); - $source = $row->getSource(); - // We diff the results because the extra will be all the field columns. - $new_fields = array_diff($results, $source); - foreach ($new_fields as $key => $value) { - $row->setSourceProperty($key, $value); + $results = $query->execute()->fetchAssoc(); + $source = $row->getSource(); + // We diff the results because the extra will be all the field columns. + $new_fields = array_diff($results, $source); + foreach ($new_fields as $key => $value) { + $row->setSourceProperty($key, $value); + } } // Handle fields that have their own table. diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/NodeRevision.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/NodeRevision.php index eaaf27d..34d4f9c 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/NodeRevision.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/NodeRevision.php @@ -10,7 +10,6 @@ use Drupal\migrate\Plugin\RequirementsInterface; use Drupal\migrate\Row; - /** * Drupal 6 node revision source from database. * @@ -24,36 +23,17 @@ class NodeRevision extends Node implements RequirementsInterface { protected $joinRevisions = 'n.nid = nr.nid AND n.vid <> nr.vid'; /** - * Fields to use from the node table. - */ - protected $nodeFields = array( - 'nid', - 'type', - 'language', - 'status', - 'created', - 'changed', - 'comment', - 'promote', - 'moderate', - 'sticky', - 'tnid', - 'translate' - ); - - /** * {@inheritdoc} */ public function query() { // Select the revisions that are not the current one. $query = parent::query(); // Use all available fields from the node revision table. - $query->fields('nr', array('vid', 'title', 'uid', 'body', 'teaser', 'log', 'timestamp', 'format')); + $query->fields('nr', array('vid', 'title', 'uid', 'body', 'teaser', 'log', 'format')); return $query; } - /** * {@inheritdoc} */ @@ -62,11 +42,4 @@ public function fields() { return parent::fields() + array('vid' => t('The primary identifier for this version.')); } - /** - * {@inheritdoc} - */ - public function checkRequirements() { - return $this->moduleExists('node'); - } - } diff --git a/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeRevisionSourceTest.php b/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeRevisionSourceTest.php index a258475..af4b94d 100644 --- a/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeRevisionSourceTest.php +++ b/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeRevisionSourceTest.php @@ -14,7 +14,7 @@ * * @group migrate_drupal */ -class NodeRevisionSourceTest extends NodeSourceTest { +class NodeRevisionSourceTest extends MigrateSqlSourceTestCase { const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\d6\NodeRevision'; @@ -40,6 +40,215 @@ class NodeRevisionSourceTest extends NodeSourceTest { ), ); + protected $expectedResults = array( + array( + // Node fields. + 'nid' => 1, + 'type' => 'page', + 'language' => 'en', + 'status' => 1, + 'created' => 1279051598, + 'changed' => 1279051598, + 'comment' => 2, + 'promote' => 1, + 'moderate' => 0, + 'sticky' => 0, + 'tnid' => 0, + 'translate' => 0, + // Node revision fields. + 'vid' => 1, + 'uid' => 1, + 'title' => 'title for revision 1 (node 1)', + 'body' => 'body for revision 1 (node 1)', + 'teaser' => 'teaser for revision 1 (node 1)', + 'log' => 'log for revision 1 (node 1)', + 'format' => 1, + 'field_test_one_value' => 'text for node 1', + 'field_test_two' => array( + 'test field node 1, value 1', + 'test field node 1, value 2', + ), + + // This is just to help with databaseContents and gets unset later. + 'fields' => array( + 'field_test_one' => 'text for node 1', + ), + ), + array( + // Node fields. + 'nid' => 1, + 'type' => 'page', + 'language' => 'en', + 'status' => 1, + 'created' => 1279051598, + 'changed' => 1279051598, + 'comment' => 2, + 'promote' => 1, + 'moderate' => 0, + 'sticky' => 0, + 'tnid' => 0, + 'translate' => 0, + // Node revision fields. + 'vid' => 3, + 'uid' => 1, + 'title' => 'title for revision 3 (node 1)', + 'body' => 'body for revision 3 (node 1)', + 'teaser' => 'teaser for revision 3 (node 1)', + 'log' => 'log for revision 3 (node 1)', + 'format' => 1, + 'field_test_one_value' => 'text for node 1', + 'field_test_two' => array( + 'test field node 1, value 1', + 'test field node 1, value 2', + ), + + // This is just to help with databaseContents and gets unset later. + 'fields' => array( + 'field_test_one' => 'text for node 1', + ), + ), + array( + // Node fields. + 'nid' => 1, + 'type' => 'page', + 'language' => 'en', + 'status' => 1, + 'created' => 1279051598, + 'changed' => 1279051598, + 'comment' => 2, + 'promote' => 1, + 'moderate' => 0, + 'sticky' => 0, + 'tnid' => 0, + 'translate' => 0, + // Node revision fields. + 'vid' => 4, + 'uid' => 1, + 'title' => 'title for revision 4 (node 1)', + 'body' => 'body for revision 4 (node 1)', + 'teaser' => 'teaser for revision 4 (node 1)', + 'log' => 'log for revision 4 (node 1)', + 'format' => 1, + 'field_test_one_value' => 'text for node 1', + 'field_test_two' => array( + 'test field node 1, value 1', + 'test field node 1, value 2', + ), + // This is just to help with databaseContents and gets unset later. + 'fields' => array( + 'field_test_one' => 'text for node 1', + ), + ), + array( + // Node fields. + 'nid' => 2, + 'type' => 'page', + 'language' => 'en', + 'status' => 1, + 'created' => 1279290908, + 'changed' => 1279308993, + 'comment' => 0, + 'promote' => 1, + 'moderate' => 0, + 'sticky' => 0, + 'tnid' => 0, + 'translate' => 0, + // Node revision fields. + 'vid' => 2, + 'uid' => 1, + 'title' => 'title for revision 2 (node 2)', + 'body' => 'body for revision 2 (node 2)', + 'teaser' => 'teaser for revision 2 (node 2)', + 'log' => 'log for revision 2 (node 2)', + 'format' => 1, + 'field_test_two' => array( + 'test field node 2', + ), + + // This is just to help with databaseContents and gets unset later. + 'fields' => array( + 'field_test_one' => 'text for node 2', + ), + ), + ); + + protected $fields = array( + 'field_test_one' => array( + 'content_node_field_instance' => array( + 'field_name' => 'field_test_one', + 'type_name' => 'page', + 'weight' => 1, + 'label' => 'Field Label One', + 'widget_type' => 'text_textfield', + 'widget_settings' => 'a:4:{s:4:"rows";i:5;s:4:"size";s:2:"60";s:13:"default_value";a:1:{i:0;a:2:{s:5:"value";s:0:"";s:14:"_error_element";s:42:"default_value_widget][field_test][0][value";}}s:17:"default_value_php";N;}', + 'display_settings' => 'a:6:{s:6:"weight";s:2:"31";s:6:"parent";s:0:"";s:5:"label";a:1:{s:6:"format";s:5:"above";}s:6:"teaser";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', + 'description' => '', + 'widget_module' => 'text', + 'widget_active' => 1, + ), + 'content_node_field' => array( + 'field_name' => 'field_test_one', + 'type' => 'text', + 'global_settings' => 'a:4:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";s:18:"allowed_values_php";s:0:"";}', + 'required' => 0, + 'multiple' => 0, + 'db_storage' => 1, + 'module' => 'text', + 'db_columns' => 'a:1:{s:5:"value";a:5:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:0;s:8:"sortable";b:1;s:5:"views";b:1;}}', + 'active' => 1, + 'locked' => 0, + ), + ), + 'field_test_two' => array( + 'content_node_field_instance' => array( + 'field_name' => 'field_test_two', + 'type_name' => 'page', + 'weight' => 1, + 'label' => 'Field Label One', + 'widget_type' => 'text_textfield', + 'widget_settings' => 'a:4:{s:4:"rows";i:5;s:4:"size";s:2:"60";s:13:"default_value";a:1:{i:0;a:2:{s:5:"value";s:0:"";s:14:"_error_element";s:42:"default_value_widget][field_test][0][value";}}s:17:"default_value_php";N;}', + 'display_settings' => 'a:6:{s:6:"weight";s:2:"31";s:6:"parent";s:0:"";s:5:"label";a:1:{s:6:"format";s:5:"above";}s:6:"teaser";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', + 'description' => '', + 'widget_module' => 'text', + 'widget_active' => 1, + ), + 'content_node_field' => array( + 'field_name' => 'field_test_two', + 'type' => 'text', + 'global_settings' => 'a:4:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";s:18:"allowed_values_php";s:0:"";}', + 'required' => 0, + 'multiple' => 1, + 'db_storage' => 0, + 'module' => 'text', + 'db_columns' => 'a:1:{s:5:"value";a:5:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:0;s:8:"sortable";b:1;s:5:"views";b:1;}}', + 'active' => 1, + 'locked' => 0, + ), + + // Multi field values. + 'values' => array( + array( + 'vid' => 1, + 'nid' => 1, + 'field_test_two_value' => 'test field node 1, value 1', + 'delta' => 0, + ), + array( + 'vid' => 1, + 'nid' => 1, + 'field_test_two_value' => 'test field node 1, value 2', + 'delta' => 1, + ), + array( + 'vid' => 2, + 'nid' => 2, + 'field_test_two_value' => 'test field node 2', + 'delta' => 0, + ), + ), + ), + ); + /** * {@inheritdoc} */ @@ -51,6 +260,58 @@ public static function getInfo() { ); } + /** + * {@inheritdoc} + */ + public function setUp() { + foreach ($this->expectedResults as $k => $row) { + $this->databaseContents['node_revisions'][$k]['nid'] = $row['nid']; + $this->databaseContents['node_revisions'][$k]['vid'] = $row['vid']; + $this->databaseContents['node_revisions'][$k]['uid'] = $row['uid']; + $this->databaseContents['node_revisions'][$k]['title'] = $row['title']; + $this->databaseContents['node_revisions'][$k]['body'] = $row['body']; + $this->databaseContents['node_revisions'][$k]['teaser'] = $row['teaser']; + $this->databaseContents['node_revisions'][$k]['format'] = $row['format']; + $this->databaseContents['node_revisions'][$k]['log'] = $row['log']; + + unset($row['body']); + unset($row['teaser']); + unset($row['format']); + unset($row['log']); + unset($row['title']); + + $this->databaseContents['node'][$k] = $row; + $this->databaseContents['node'][$k] = $row; + + // Add the column field storage data. + $table = 'content_type_' . $row['type']; + foreach ($row['fields'] as $field_name => $value) { + $this->databaseContents[$table][$k][$field_name . "_value"] = $value; + $this->databaseContents[$table][$k]['vid'] = $row['vid']; + $this->databaseContents[$table][$k]['nid'] = $row['nid']; + } + // Unset from results. + unset($row['fields']); + unset($this->expectedResults[$k]['fields']); + } + + // Setup field tables. + foreach ($this->fields as $field) { + $cnf = $field['content_node_field']; + $this->databaseContents['content_node_field'][] = $cnf; + $this->databaseContents['content_node_field_instance'][] = $field['content_node_field_instance']; + + // If it's a multi-field then setup a new table. + if ($cnf['multiple']) { + foreach ($field['values'] as $value) { + $this->databaseContents['content_' . $cnf['field_name']][] = $value; + } + } + } + + parent::setUp(); + } + } namespace Drupal\migrate_drupal\Tests\source\d6; diff --git a/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeSourceTest.php b/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeSourceTest.php index 4f41df0..84b92f8 100644 --- a/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeSourceTest.php +++ b/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/NodeSourceTest.php @@ -60,7 +60,7 @@ class NodeSourceTest extends MigrateSqlSourceTestCase { 'translate' => 0, // Node revision fields. 'body' => 'body for node 1', - 'teaser' => 'body for node 1', + 'teaser' => 'teaser for node 1', 'format' => 1, 'field_test_one_value' => 'text for node 1', 'field_test_two' => array( @@ -91,8 +91,8 @@ class NodeSourceTest extends MigrateSqlSourceTestCase { 'tnid' => 0, 'translate' => 0, // Node revision fields. - 'body' => 'body for node 3', - 'teaser' => 'body for node 3', + 'body' => 'body for node 2', + 'teaser' => 'teaser for node 2', 'format' => 1, 'field_test_one_value' => 'text for node 2', 'field_test_two' => array(