0

I want to skip some rows in my migration, so that rows will imported on the 2nd attempt. for this am returning false in the prepare row function.

public function prepareRow($row) {
if($parent) {
      return TRUE;
    }
    else {
      return FALSE;
    }
}

but this ignore that rows and then I am unable to import the data again. Is there any option to skip some rows so that I can import them on 2nd attempt?

2

Migrate doesn't work with attempts, so it always performs one migration (that you can update with the latest content).

Considering the fact you need some parent do be defined first, it might be easier to apply some sorting, so the parent is always created before the child (and you would not need several attempts). If you are migrating from a Drupal (7) site you can use the menu_links table for this. See the section about book hierarchies here: Migrating Book module nodes for a similar situation.

If you are not migrating from Drupal, but some other system you might want to look for a similar table.

As an alternative, you might be able to use the handleSourceMigration() function to see if the old parent id is already migrated (function returns NULL otherwise) and skip rows based on that, then re-run the migration. But I have never used this method and it might not work.

  • is it not possible to skip some rows and does not make the import process to be completed. then it will import other nodes if we re-run the migration? – Ahmad Dec 3 '15 at 14:53
  • I have never tried it like that. I believe the module was designed to migrate all content at once as there no real good use-case for migrating in small portions. – Neograph734 Dec 3 '15 at 15:35
  • 1
    there is the --limit option to limit the number of items migrated and --idlist to specify certain ids to be migrated. – UltraBob Jan 13 '16 at 6:00
1

You don't specify why you want to skip some rows, but one likely scenario is that you are wanting to test if some row that this row relies on has been created before creating this row. In this case, the easiest option when it is possible is to order your query so that you ensure the initial requirees are created before the requirers.

I have also done this by restricting the where clause in my query to make sure I only get the items I want (perhaps the parents from your variable name) in one migration, and then create another migration with a query that gets the rest.

The other option is to create a stub for the required row, that will act as a placeholder until the migration has the actual data. This allows you to create the reference and associate properly first, and add the actual data later. This is documented in the migrate module documentation on using stubs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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