Damz already coded the migrate handler for entityreference. It really should be implemented in the module. (tested and approved locally, it works)

Patch by Damien attached for reference.

Files: 
CommentFileSizeAuthor
#16 handle_default_values-1261086-16.patch1.05 KBmikeryan
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/entityreference/entityreference.module.
[ View ]
#8 entityreference_1261086.patch1.94 KBdrewish
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]
#7 entityreference_1261086.patch1.89 KBdrewish
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]
#3 1261086.3.patch3.08 KBHaza
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1261086.3.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
#1 entityreference_migrate.patch1.1 KBHaza
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreference_migrate.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

Comments

Haza’s picture

StatusFileSize
new1.1 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreference_migrate.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
Damien Tournoud’s picture

Status:Active» Fixed

Thanks for reminding me of this. Committed.

Haza’s picture

Status:Fixed» Needs work
StatusFileSize
new3.08 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1261086.3.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

It seems that, even if migrate implement the hook_hook_info(), it doesn't trigger the class (during an import) unless I add the file in the .info of the module.

Attached here an other patch that implements the migrate plugin in an other way.

What do you think about that ?

Damien Tournoud’s picture

Status:Needs work» Fixed

I simply added the missing reference to the file in the .info. Please reopen if this is not fixed.

Status:Fixed» Closed (fixed)

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

drewish’s picture

Shouldn't we be allowing the type to be passed in as an argument? I'm getting the following error trying to use this:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_webform_project_submission_target_type' cannot be null: INSERT INTO                      [error]
{field_data_field_webform_project_submission} (entity_type, entity_id, revision_id, bundle, delta, language, field_webform_project_submission_target_id,
field_webform_project_submission_target_type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3,
:db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array
(
    [:db_insert_placeholder_0] => webform_submission_entity
    [:db_insert_placeholder_1] => 794482
    [:db_insert_placeholder_2] => 794482
    [:db_insert_placeholder_3] => grant_application
    [:db_insert_placeholder_4] => 0
    [:db_insert_placeholder_5] => und
    [:db_insert_placeholder_6] => 766775
    [:db_insert_placeholder_7] =>
)
(modules/field/modules/field_sql_storage/field_sql_storage.module:448)

but the problem might be in the code we're using to make webform_submissions fieldable.

drewish’s picture

Status:Closed (fixed)» Needs review
StatusFileSize
new1.89 KB
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

Here's what I had to use to get this going… did some cleanup along the way.

drewish’s picture

StatusFileSize
new1.94 KB
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

fixed one other issue with empty values.

mikeryan’s picture

Status:Needs review» Reviewed & tested by the community

Well, I was all set to submit my own patch adding a target_type argument, you beat me to it! Your patch works for me...

Damien Tournoud’s picture

Status:Reviewed & tested by the community» Needs work

There is only one type per field, so this argument should not be required at all. Can anyone explain the rationale here?

mikeryan’s picture

If the target_type is not specified, you get the error in comment #6. But, if the target_type is common to all instances of a given field, then we should be able to just pull it from the field info, right?

Damien Tournoud’s picture

'target_type' is added by entityreference_field_presave(). Why doesn't that work in the context of Migrate?

mikeryan’s picture

Hmm, a good question, migrate calls node_save() so the presave hooks should be getting called... Guess some more debugging is in order.

mikeryan’s picture

OK, my problem is that the field is defined via features, with a default value of:

<?php
     
'default_value' => array(
       
0 => array(
         
'target_id' => '82',
        ),
      ),
?>

Features does not save a target_type. Because default values aren't fetched until after hook_field_presave(), it doesn't get fixed up. I'm not sure what the workflow is when creating features - whether there's something entityreference can declare differently to get it picked up, for example - but a quick and easy fix is to just rename entityreference_field_presave() to entityreference_field_insert().

That solves my problem, anyway, I can't speak for drewish...

drewish’s picture

I'm also using fields exported as features. I didn't have time to circle back and sort this out, I just left my patch applied.

mikeryan’s picture

Status:Needs work» Needs review
StatusFileSize
new1.05 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/entityreference/entityreference.module.
[ View ]

Here's a patch to replace the presave hook with insert and update hooks, to make sure target_type gets set in all scenarios.

amitaibu’s picture

@mikeryan, I think it's related -- #1319040: Remove "target_type" column from db, I think we should remove the target_type completely, as in the end ER references only a single target_type.

mikeryan’s picture

So much the better, but there's no patch there yet. This will tide us over unless/until the target_type is removed.

amitaibu’s picture

> but there's no patch there yet.

Now there is ;)

Status:Needs review» Needs work

The last submitted patch, handle_default_values-1261086-16.patch, failed testing.

Damien Tournoud’s picture

Status:Needs work» Fixed

Target type is now gone for good.

Status:Fixed» Closed (fixed)

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