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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1890022-3-migrate_entity_string_id.patch | 419 bytes | SebCorbin |
| #1 | migrate_extras-entity_api_id_fix-1890022.patch | 837 bytes | usernameisalreadytaken |
Comments
Comment #1
usernameisalreadytaken commentedPatch attached
Comment #2
andypostid could be string value so checking for number is wrong
Comment #3
SebCorbin commentedYES! 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.
Comment #4
usernameisalreadytaken commentedThanks 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.
Comment #5
SebCorbin commentedFor 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.
Comment #6
SebCorbin commentedFor the record, how to migrate beans, see #2141211: Bean Migrate example
(this patch is not required)