When want to create copy of node, and this node uses entity translation, I get this error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-64-de' for key 'PRIMARY': INSERT INTO {entity_translation} (entity_type, entity_id, language, source, uid, status, translate, created, changed) VALUES ( ..... )in EntityTranslationDefaultHandler->saveTranslations() (Zeile 274 von /srv/inostudio/kunden/5316.002_Selecta/online/sites/all/modules/_i18n/entity_translation/includes/translation.handler.inc).
in saveTranslations() in translation.handler.inc the entity_id gets not replaced with the new (correct) entity id; I assume because the += array concatenation, does not replace already set array-fields.
manally setting the entity id to the new id, makes the whole thing work:
$translation['entity_id'] = $this->entityId;
I guess this still needs elaboration, to actually become a patch...
Comment | File | Size | Author |
---|---|---|---|
#12 | et-1230858-11.patch | 1.78 KB | plach |
#11 | entity-1277776-11.patch | 375.34 KB | plach |
#9 | clone_node_with_entity_translations-1230858-9.patch | 1.29 KB | tarmstrong |
#4 | clone_node_with_entity_translations.patch | 1.25 KB | tarmstrong |
Comments
Comment #1
plachIf you can provide a patch I'll be glad to review it :)
Comment #2
tarmstrong CreditAttribution: tarmstrong commentedComment #3
tarmstrong CreditAttribution: tarmstrong commentedJust confirming this bug, with steps to reproduce.
Components:
1. Drupal core 7.x git branch
2. Entity translation 7.x-1.0-alpha1 (current HEAD)
3. Node clone git branch 7.x-1.x
Steps:
1. Add translatable field to Article content type
2. Make an article
3. Translate the field
4. Attempt to clone the node.
The node clone settings are the "save and then open for editing" option.
Result:
Same error as valderama.
Comment #4
tarmstrong CreditAttribution: tarmstrong commentedOk, found the problem. In EntityTranslationDefaultHandler::saveTranslations(), I found the following code. The goal is to make sure the translation has default values. But it also fails to update the entity_id with the new entity ID (in the case of cloning a node).
In simpler terms, node_save() causes the entity translations to be cloned, but fails to set the correct ID on them.
I've fixed the problem by making some values override the existing value with array_merge() instead of the "+=" array operator.
Comment #5
tarmstrong CreditAttribution: tarmstrong commentedComment #6
tarmstrong CreditAttribution: tarmstrong commentedJust adding the montreal tag to celebrate the DrupalCamp Montreal code sprint!
Comment #7
plachNice catch! Just some minor remarks:
Comments should start with a capital letter and end with a dot.
See above.
This looks like the correct solution but the user id should ony default to the current user so I'd keep only entity type and entity in the override array.
Comment #8
plachComment #9
tarmstrong CreditAttribution: tarmstrong commentedThanks, updated the patch with your suggestions.
Comment #10
tarmstrong CreditAttribution: tarmstrong commentedComment #11
plachSorry for being a PITA, but while looking at your code I thought parts of it might be moved outside the for iteration as a microptimization. To avoid the need to reroll the patch here is one. Would you confirm it still fixes the issue?
Comment #12
plachwrong one :)
Comment #13
tarmstrong CreditAttribution: tarmstrong commentedHaha, I was wondering why your micro-optimization had anything to do with entity_get_info()...
Looks good. I think this code is much clearer for the reader anyways, so it's not just a micro-optimization. Tested and still works.
Comment #14
plachCommitted, thanks!
Comment #16
petednz CreditAttribution: petednz commentedhi - happy to be told to open a new ticket but am getting the error described above i think
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-5926-en' for key 'PRIMARY': INSERT INTO {entity_translation} (entity_type, entity_id, language, source, uid, status, translate, created, changed) 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, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 5926 [:db_insert_placeholder_2] => en [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => 9 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 1334323249 [:db_insert_placeholder_8] => 1334330752 ) inEntityTranslationDefaultHandler->saveTranslations() (line 271 of/var/www/www/sites/all/modules/entity_translation/includes/translation.handler.inc).
but then I am using alpha1
do i take it the committed patch is only on the dev version?
any plans for an updated release?
Comment #17
Pls CreditAttribution: Pls commentedWould love to see this patch on new release, as I came up with this issue when using node_export module for D7. Thanks for the patchs guys!
Comment #18
plachThis is part of alpha 2.
Comment #19
Pls CreditAttribution: Pls commentedplach, thanks. I totally missed that, anyway thanks for awesome patch!