Unverified Commit 4a30675b authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2937989 by Matroskeen, quietone, jcisio, alexpott, heddn: Support...

Issue #2937989 by Matroskeen, quietone, jcisio, alexpott, heddn: Support multiple node types in node source plugins
parent 3434dee1
Loading
Loading
Loading
Loading
+26 −2
Changes for core/modules/node/src/Plugin/migrate/source/d6/Node.php: 26 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -14,11 +14,35 @@
/**
 * Drupal 6 node source from database.
 *
 * Available configuration keys:
 * - node_type: The node_types to get from the source - can be a string or
 *   an array. If not declared then nodes of all types will be retrieved.
 *
 * Examples:
 *
 * @code
 * source:
 *   plugin: d6_node
 *   node_type: page
 * @endcode
 *
 * In this example nodes type page are retrieved from the source database.
 *
 * @code
 * source:
 *   plugin: d6_node
 *   node_type: [page, test]
 * @endcode
 *
 * In this example nodes of type page and test are retrieved from the source
 * database.
 *
 * @MigrateSource(
 *   id = "d6_node",
 *   source_module = "node"
 *
 * )
 *
 * @see \Drupal\migrate\Plugin\migrate\source\SqlBase
 */
class Node extends DrupalSqlBase {

@@ -113,7 +137,7 @@ public function query() {
    }

    if (isset($this->configuration['node_type'])) {
      $query->condition('n.type', $this->configuration['node_type']);
      $query->condition('n.type', (array) $this->configuration['node_type'], 'IN');
    }

    return $query;
+26 −1
Changes for core/modules/node/src/Plugin/migrate/source/d7/Node.php: 26 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -14,10 +14,35 @@
/**
 * Drupal 7 node source from database.
 *
 * Available configuration keys:
 * - node_type: The node_types to get from the source - can be a string or
 *   an array. If not declared then nodes of all types will be retrieved.
 *
 * Examples:
 *
 * @code
 * source:
 *   plugin: d7_node
 *   node_type: page
 * @endcode
 *
 * In this example nodes type page are retrieved from the source database.
 *
 * @code
 * source:
 *   plugin: d7_node
 *   node_type: [page, test]
 * @endcode
 *
 * In this example nodes of type page and test are retrieved from the source
 * database.
 *
 * @MigrateSource(
 *   id = "d7_node",
 *   source_module = "node"
 * )
 *
 * @see \Drupal\migrate\Plugin\migrate\source\SqlBase
 */
class Node extends FieldableEntity {
  /**
@@ -93,7 +118,7 @@ public function query() {
    $this->handleTranslations($query);

    if (isset($this->configuration['node_type'])) {
      $query->condition('n.type', $this->configuration['node_type']);
      $query->condition('n.type', (array) $this->configuration['node_type'], 'IN');
    }

    return $query;
+26 −1
Changes for core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php: 26 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -8,10 +8,35 @@
/**
 * Provides Drupal 7 node entity translations source plugin.
 *
 * Available configuration keys:
 * - node_type: The node_types to get from the source - can be a string or
 *   an array. If not declared then nodes of all types will be retrieved.
 *
 * Examples:
 *
 * @code
 * source:
 *   plugin: d7_node_entity_translation
 *   node_type: page
 * @endcode
 *
 * In this example nodes type page are retrieved from the source database.
 *
 * @code
 * source:
 *   plugin: d7_node_entity_translation
 *   node_type: [page, test]
 * @endcode
 *
 * In this example nodes of type page and test are retrieved from the source
 * database.
 *
 * @MigrateSource(
 *   id = "d7_node_entity_translation",
 *   source_module = "entity_translation"
 * )
 *
 * @see \Drupal\migrate\Plugin\migrate\source\SqlBase
 */
class NodeEntityTranslation extends FieldableEntity {

@@ -40,7 +65,7 @@ public function query() {
    $query->innerJoin('node_revision', 'nr', 'nr.vid = et.revision_id');

    if (isset($this->configuration['node_type'])) {
      $query->condition('n.type', $this->configuration['node_type']);
      $query->condition('n.type', (array) $this->configuration['node_type'], 'IN');
    }

    return $query;
+36 −1
Changes for core/modules/node/tests/src/Kernel/Plugin/migrate/source/d6/NodeByNodeTypeTest.php: 36 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ public function providerSource() {
        'uid' => 2,
        'timestamp' => 1279290908,
        'body' => 'body for node 5',
        'teaser' => 'body for node 5',
        'teaser' => 'teaser for node 5',
        'format' => 1,
        'log' => 'log message 3',
      ],
@@ -179,6 +179,41 @@ public function providerSource() {
      'node_type' => 'page',
    ];

    // Tests retrieval of article and page content types.
    $tests[1] = $tests[0];
    $tests[1]['configuration'] = [
      'node_type' => ['article', 'page'],
    ];
    // The expected results should include previous results and article.
    $tests[1]['expected_data'][] = [
      'nid' => 5,
      'vid' => 5,
      'type' => 'article',
      'language' => 'en',
      'title' => 'node title 5',
      'status' => 1,
      'created' => 1279290908,
      'changed' => 1279308993,
      'comment' => 0,
      'promote' => 1,
      'moderate' => 0,
      'sticky' => 0,
      'tnid' => 5,
      'translate' => 0,
      // Node revision fields.
      'body' => 'body for node 5',
      'teaser' => 'teaser for node 5',
      'format' => 1,
      'log' => 'log message 3',
    ];

    // Test retrieval of article and page content types when configuration
    // key 'node_type' is not set.
    $tests[2] = $tests[0];
    unset($tests[2]['configuration']);

    // The expected results should be the same as the previous ones.
    $tests[2]['expected_data'] = $tests[1]['expected_data'];
    return $tests;
  }

+105 −11
Changes for core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeEntityTranslationTest.php: 105 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -62,6 +62,18 @@ public function providerSource() {
        'created' => 1531343528,
        'changed' => 1531343528,
      ],
      [
        'entity_type' => 'node',
        'entity_id' => 3,
        'revision_id' => 3,
        'language' => 'fr',
        'source' => 'en',
        'uid' => 1,
        'status' => 0,
        'translate' => 0,
        'created' => 1531343528,
        'changed' => 1531343528,
      ],
    ];
    $tests[0]['source_data']['field_config'] = [
      [
@@ -123,6 +135,15 @@ public function providerSource() {
        'data' => 'a:0:{}',
        'deleted' => 0,
      ],
      [
        'id' => 4,
        'field_id' => 2,
        'field_name' => 'title_field',
        'entity_type' => 'node',
        'bundle' => 'article',
        'data' => 'a:0:{}',
        'deleted' => 0,
      ],
    ];
    $tests[0]['source_data']['field_revision_body'] = [
      [
@@ -173,6 +194,18 @@ public function providerSource() {
        'body_summary' => 'Spanish summary',
        'body_format' => 'filtered_html',
      ],
      [
        'entity_type' => 'node',
        'bundle' => 'article',
        'deleted' => 0,
        'entity_id' => 3,
        'revision_id' => 3,
        'language' => 'fr',
        'delta' => 0,
        'body_value' => 'French body',
        'body_summary' => 'French summary',
        'body_format' => 'filtered_html',
      ],
    ];
    $tests[0]['source_data']['field_revision_title_field'] = [
      [
@@ -208,6 +241,17 @@ public function providerSource() {
        'title_field_value' => 'Spanish Translation',
        'title_field_format' => NULL,
      ],
      [
        'entity_type' => 'node',
        'bundle' => 'article',
        'deleted' => '0',
        'entity_id' => '3',
        'revision_id' => '3',
        'language' => 'fr',
        'delta' => '0',
        'title_field_value' => 'French Translation',
        'title_field_format' => NULL,
      ],
    ];
    $tests[0]['source_data']['node'] = [
      [
@@ -242,6 +286,22 @@ public function providerSource() {
        'tnid' => 0,
        'translate' => 0,
      ],
      [
        'nid' => 3,
        'vid' => 3,
        'type' => 'article',
        'language' => 'en',
        'title' => 'Translated article',
        'uid' => 1,
        'status' => 1,
        'created' => 1531343456,
        'changed' => 1531343456,
        'comment' => 2,
        'promote' => 0,
        'sticky' => 0,
        'tnid' => 0,
        'translate' => 0,
      ],
    ];
    $tests[0]['source_data']['node_revision'] = [
      [
@@ -268,6 +328,18 @@ public function providerSource() {
        'promote' => 0,
        'sticky' => 0,
      ],
      [
        'nid' => 3,
        'vid' => 3,
        'uid' => 1,
        'title' => 'Translated article',
        'log' => '',
        'timestamp' => 1531343528,
        'status' => 1,
        'comment' => 1,
        'promote' => 0,
        'sticky' => 0,
      ],
    ];
    $tests[0]['source_data']['system'] = [
      [
@@ -341,19 +413,41 @@ public function providerSource() {
      'node_type' => 'page',
    ];

    // The source data.
    $tests[1]['source_data'] = $tests[0]['source_data'];

    // The expected results.
    $tests[1]['expected_data'] = [];

    // Do an automatic count.
    $tests[1]['expected_count'] = NULL;

    // Set up source plugin configuration.
    // Tests retrieval translations of article and page content types.
    $tests[1] = $tests[0];
    $tests[1]['configuration'] = [
      'node_type' => 'article',
      'node_type' => ['article', 'page'],
    ];
    $tests[1]['expected_data'][] = [
      'entity_type' => 'node',
      'entity_id' => 3,
      'revision_id' => 3,
      'language' => 'fr',
      'source' => 'en',
      'uid' => 1,
      'status' => 0,
      'translate' => 0,
      'created' => 1531343528,
      'changed' => 1531343528,
      'type' => 'article',
      'title' => 'French Translation',
      'promote' => 0,
      'sticky' => 0,
      'log' => '',
      'timestamp' => 1531343528,
      'revision_uid' => 1,
      'body' => [
        [
          'value' => 'French body',
          'summary' => 'French summary',
          'format' => 'filtered_html',
        ],
      ],
    ];

    // Tests retrieval of entity translations without configuration.
    $tests[2] = $tests[1];
    $tests[2]['configuration'] = [];

    return $tests;
  }
Loading