Drupal with PostgresSQL cloning an entity created using ECK.
<?php
replicate_entity_by_id('daas_site', 1);
?>WD daas_site: PDOException: SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "eck_daas_site_pkey" [error]
DETAIL: Key (id)=(1) already exists.: INSERT INTO eck_daas_site
Here is a small diff that fixes this:
diff --git a/sites/all/modules/contrib/replicate/replicate.module b/sites/all/modules/contrib/replicate/replicate.module
index 53c6c25..a4563df 100755
--- a/sites/all/modules/contrib/replicate/replicate.module
+++ b/sites/all/modules/contrib/replicate/replicate.module
@@ -102,6 +102,9 @@ function replicate_clone_entity($entity_type, $entity) {
drupal_alter('replicate_entity', $clone, $entity_type, $entity);
}
+ $entity_info = entity_get_info($entity_type);
+ unset($clone->{$entity_info['entity keys']['id']});
+
return $clone;
}
Also, in the mean time a work around (currently untested) would be to add the same unsetting of the clone's id in HOOK_replicate_entity_alter()
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | pdoexception-2536714-5.patch | 2.4 KB | vbouchet |
| #2 | replicate-PDO_exception-2536714-2.patch | 1.49 KB | jgalletta |
| #1 | 2536714-PDOException-unique-violation.patch | 552 bytes | thursday_bw |
Comments
Comment #1
thursday_bw commentedAdding the previously mentioned in line diff as a patch file.
Comment #2
jgalletta commentedI can't believe we don't use this code to clean entities, that's simpler than our current code...
I made a new patch using your code, I moved the 2 lines just before sending entities to other modules, as cleaning the entity id is something we want to do for all entities.
I also removed the implemented hooks that become useless with the new code.
Comment #3
jgalletta commentedComment #4
thursday_bw commentedjgalletta,
Awesome stuff, thank your for following up on this.
Comment #5
vbouchetThis is great as custom entities which are properly defined and list their "entity keys" will be automatically prepared for replication.
I edited the hook_replicate_entity_ENTITY_TYPE() documentation as it is not supposed to be required to implement the hook to prepare custom entities anymore. (Feel free to use the previous patch if you think it still makes sense to describe it.
Comment #7
jgalletta commented