{"id":2155,"date":"2018-08-01T14:13:26","date_gmt":"2018-08-01T18:13:26","guid":{"rendered":"http:\/\/agileadam.com\/?p=2155"},"modified":"2018-10-21T11:28:16","modified_gmt":"2018-10-21T15:28:16","slug":"only-migrate-published-nodes-d7-d8-migration","status":"publish","type":"post","link":"https:\/\/agileadam.com\/2018\/08\/only-migrate-published-nodes-d7-d8-migration\/","title":{"rendered":"Only Migrating Published Nodes in a D7 to D8 Migration"},"content":{"rendered":"

I’m not going into much detail here but hopefully this helps someone.<\/p>\n

If you need to migrate only published nodes you can\u00a0extend the d7_node<\/em> plugin and add a condition to the query.<\/p>\n

First, create a file in your module like\u00a0\/modules\/custom\/mysite_migrate\/src\/Plugin\/migrate\/source\/MysiteNewsNode.php<\/em> that extends the d7_node<\/em> plugin:<\/p>\n

<?php\r\n\r\nnamespace Drupal\\mysite_migrate\\Plugin\\migrate\\source;\r\n\r\nuse Drupal\\migrate\\Row;\r\nuse Drupal\\node\\Plugin\\migrate\\source\\d7\\Node as d7_node;\r\n\r\n\/**\r\n * Published news nodes from the d7 database.\r\n *\r\n * @MigrateSource(\r\n *   id = \"mysite_news_node\",\r\n *   source_module = \"node\"\r\n * )\r\n *\/\r\nclass MysiteNewsNode extends d7_node {\r\n\r\n  \/**\r\n   * {@inheritdoc}\r\n   *\/\r\n  public function query() {\r\n    $query = parent::query();\r\n\r\n    \/\/ Only migrate published records.\r\n    $query->condition('n.status', 1);\r\n\r\n    return $query;\r\n  }\r\n\r\n}<\/pre>\n

Then, use the\u00a0mysite_news_node<\/em> source plugin instead of\u00a0d7_node<\/em>.<\/p>\n

source:\r\n  plugin: mysite_news_node\r\n  node_type: news_item\r\n<\/pre>\n

I would encourage you to have a look at the code in \/core\/modules\/node\/src\/Plugin\/migrate\/source\/d7\/Node.php<\/em> to see what happens in the query() method you’re extending, as well as what’s going on in prepareRows() and fields() in particular.<\/p>\n","protected":false},"excerpt":{"rendered":"

I’m not going into much detail here but hopefully this helps someone. If you need to migrate only published nodes you can\u00a0extend the d7_node plugin and add a condition to the query. First, create a file in your module like\u00a0\/modules\/custom\/mysite_migrate\/src\/Plugin\/migrate\/source\/MysiteNewsNode.php that extends the d7_node plugin:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[79],"tags":[83,300,72,322],"_links":{"self":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/2155"}],"collection":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/comments?post=2155"}],"version-history":[{"count":4,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/2155\/revisions"}],"predecessor-version":[{"id":2163,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/2155\/revisions\/2163"}],"wp:attachment":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/media?parent=2155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/categories?post=2155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/tags?post=2155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}