I ran into a problem, where my custom entity has a predefined entity id and the import didn't work.
I have a varchar primary key as the entity ID (its a GUID). In MigrateDestinationEntityAPI's import function there is a condition that expects serial data type, what is wrong.
@line 230: "If a destination id exists, the entity is obviously not new.".
I removed that condition as "getSystemOfRecord() == Migration::DESTINATION" at line 199 checks if its an update anyway.
The import started working but I got back wrong feedback on the number of created and failed items.
Condition on line 244 was checking if a numeric entity id was returned. I changed it to check if the entity id was not empty. All seems to be working fine with my custom entities.

Comments

usernameisalreadytaken’s picture

Status: Active » Needs review
StatusFileSize
new837 bytes

Patch attached

andypost’s picture

id could be string value so checking for number is wrong

SebCorbin’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new419 bytes

YES! I approve this! But not the part where you unset $entity->is_new, that would not be required with the actual problem.
You could work with the prepare() method if you want to set your own id.

Patch rerolled without this bit, and marked as reviewed as per #2 and myself.

usernameisalreadytaken’s picture

Thanks for having a look,
Your change is not correct though:
It is required by the actual problem as the ID already exists because it was generated by the Source system.
So why would you unset the is_new flag based on an existing ID if its not an incremental?
Again:
"If a destination id exists, the entity is obviously not new" < this assumption is wrong.
I think my first patch is the correct solution for custom entities.

SebCorbin’s picture

For custom ones, maybe. But I migrate BEAN which are using the EntityAPIController and use that property is_new to determine if the entity has to be created or updated. When is_new is unset, boom, SQL query error due to duplicate primary key.

SebCorbin’s picture

For the record, how to migrate beans, see #2141211: Bean Migrate example
(this patch is not required)