0

I know I'm really missing something here. I have a custom migration source plugin that requires a query() to be returned.

If I pass an --idlist=123 parameter with the import this query still runs on all of the nodes as there is no way to limit it dynamically. What am I missing?

The migration is supposed to query the legacy D7 db for content types (event) and then I need to update each result's fields in my prepareRow(). This works except that the query is always returning all events. I think I'm misunderstanding the need/purpose for the query() function.

enter image description here

1 Answer 1

2

This is a known issue during migration. There are open issues in Drupal.org but they are not closed yet. But for now we have a work around to solve this issue.

public function query() {
    // Hack for getting idlist to filter in command line
    $idlist = NULL;
    foreach ($_SERVER['argv'] as $arg) {
      if (strpos($arg, '--idlist') === 0) {
        list(, $idlist) = explode('=', $arg);
        $idlist = explode(',', $idlist);
        break;
      }
    }
$query = $this->select('node', 'n')
  ->fields('n')
  ->orderBy('nid', 'ASC');

if ($idlist) {
  $query->condition('n.nid', $idlist, 'IN');
}

return $query;
}

Then use it like this:

drush migrate:import example_node_articles --update --idlist=1234
 [notice] Processed 1 item (0 created, 1 updated, 0 failed, 0 ignored) - done with 'example_node_articles'

Source : https://www.drupal.org/project/migrate_tools/issues/3107400#comment-13428024

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.