Download & Extend

Implements migrate handler

Project:Entity reference
Version:7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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.

Comments

#1

AttachmentSizeStatusTest resultOperations
entityreference_migrate.patch1.1 KBIdleFAILED: [[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 details

#2

Status:active» fixed

Thanks for reminding me of this. Committed.

#3

Status:fixed» needs work

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 ?

AttachmentSizeStatusTest resultOperations
1261086.3.patch3.08 KBIdleFAILED: [[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 details

#4

Status:needs work» fixed

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

#5

Status:fixed» closed (fixed)

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

#6

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.

#7

Status:closed (fixed)» needs review

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

AttachmentSizeStatusTest resultOperations
entityreference_1261086.patch1.89 KBIdlePASSED: [[SimpleTest]]: [MySQL] 66 pass(es).View details

#8

fixed one other issue with empty values.

AttachmentSizeStatusTest resultOperations
entityreference_1261086.patch1.94 KBIdlePASSED: [[SimpleTest]]: [MySQL] 66 pass(es).View details

#9

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...

#10

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?

#11

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?

#12

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

#13

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

#14

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...

#15

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.

#16

Status:needs work» needs review

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

AttachmentSizeStatusTest resultOperations
handle_default_values-1261086-16.patch1.05 KBIdleFAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/entityreference/entityreference.module.View details

#17

@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.

#18

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

#19

> but there's no patch there yet.

Now there is ;)

#20

Status:needs review» needs work

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

#21

Status:needs work» fixed

Target type is now gone for good.

#22

Status:fixed» closed (fixed)

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