Only Migrating Published Nodes in a D7 to D8 Migration
I’m not going into much detail here but hopefully this helps someone.
If you need to migrate only published nodes you can extend the d7_node plugin and add a condition to the query.
First, create a file in your module like /modules/custom/mysite_migrate/src/Plugin/migrate/source/MysiteNewsNode.php that extends the d7_node plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<?php namespace Drupal\mysite_migrate\Plugin\migrate\source; use Drupal\migrate\Row; use Drupal\node\Plugin\migrate\source\d7\Node as d7_node; /** * Published news nodes from the d7 database. * * @MigrateSource( * id = "mysite_news_node", * source_module = "node" * ) */ class MysiteNewsNode extends d7_node { /** * {@inheritdoc} */ public function query() { $query = parent::query(); // Only migrate published records. $query->condition('n.status', 1); return $query; } } |
Then, use the mysite_news_node source plugin instead of d7_node.
1 2 3 |
source: plugin: mysite_news_node node_type: news_item |
I would encourage you to have a look at the code in /core/modules/node/src/Plugin/migrate/source/d7/Node.php to see what happens in the query() method you’re extending, as well as what’s going on in prepareRows() and fields() in particular.