Score:0

How to filter idlist in command line when importing data via migration

ng flag

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

Score:1
fr flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.