Hi to all,

Based on migrate_example_baseball module, i am building my own migration. Example: Two content type 'Author' and 'Picture'. Picture is a node reference content type for content type 'Author' . Currently i am having 10 author json file and 10 picture json file, and i am writing my own class file using 'DynamicMigration'. If i don't have picture json file then how the Chickens and eggs: using stubs will created.

If picture source json is not available then how to create stubs in picture content type and dynamic tracking. Please help me...

regards,
tssarun.

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

I'm sorry, it's not clear to me what your specific question is. Let me see if I can explain how this would work, assuming your Author content type contains a node reference field named field_picture. Your picture migration class should define a createStub() method, that creates a stub picture node and returns its ID in an array. Then, your author migration class would have a mapping like:

// 'picture_id' is whatever field references the picture in the JSON source
$this->addFieldMapping('field_picture', 'picture_id')
     ->sourceMigration('picture migration machine name');

However, I'm not seeing why you would need to deal with stubs in this use case - if you simply run the picture migration, then the author migration, it should just work without stubs, you only need stubs when there's a chicken-and-egg problem. Unless... do the pictures have a reference back to the authors? In that case it does make sense - so, with my example, you'd also have in the picture migration:

$this->addFieldMapping('field_author', 'author_id')
     ->sourceMigration('author migration machine name');

So, with createStub defined in the picture migration class, you would run the author migration first, which would cause stubs to be created for the referenced pictures, then when you run the picture migration it should fill in the stubs.

Does this address your question?

tssarun’s picture

Hello Mikeryan,

Thankx for your immediate reply.

Your reply:
'So, with createStub defined in the picture migration class, you would run the author migration first, which would cause stubs to be created for the referenced pictures, then when you run the picture migration it should fill in the stubs.'
----

According to my example, i am having 10 author json file and 10 picture file. For each file i am creating a new process using
Migration::registerMigration('GameBaseball',pathinfo($file, PATHINFO_FILENAME), array('source_file' => $path . '/' . $file));
(Example from migrate_example_baseball)

so 10 mapping tables are created for 'author' content type and 10 mapping table created for 'picture' content type. My issue is, if one of the author (present in first author json file[1/10]) having a picture reference which is available in 8th file of the picture json file[8/10].

Now if i start and completing full author content type migration(all the 10 files are inserted) and after two days i am inserting picture content type json files.

then how stub will created with a 'needs_update' column in (migrate_map_picture_8)

Please help me...

tssarun’s picture

Status: Postponed (maintainer needs more info) » Active

Any support on this...

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

How precisely are the authors and pictures related? If I understand your original post correctly, in Drupal you have an Author content type, which contains a node_reference field that references nodes of type Picture. So, presumably in your author JSON there is a reference to the related picture - in your Author migration you would map that reference to the node reference field, with a sourceMigration() pointing to your picture migration. You run the picture migrations first, then the author migrations, and it all works out.

Now, if I understand comment #2 correctly, the pictures may come in at some point days after the authors? Thus, the original author JSON did not originally have a reference to the picture, but now it does? In that case, you would need to rerun the migration with --update to pick up the changes. Still no stubs involved or necessary.

tssarun’s picture

Thankyou mikeryan,
I got the answer from the following post. https://drupal.org/node/1986758

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.