duplicates-PDO.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. diff --git a/corresponding_entity_references.crud.inc b/corresponding_entity_references.crud.inc
  2. index 3736e98..4ad5e83 100644
  3. --- a/corresponding_entity_references.crud.inc
  4. +++ b/corresponding_entity_references.crud.inc
  5. @@ -52,19 +52,17 @@ function corresponding_entity_references_insert($home_entity, $keys) {
  6. // referenced.
  7. $exists = FALSE;
  8. foreach ($referenced_entity->{$keys['away_field']}[LANGUAGE_NONE] as $key => $value) {
  9. - if ($value[$ids['away']] == $home_entity->$ids['home']) {
  10. + if ($value['target_id'] == $home_entity->$ids['home']) {
  11. $exists = TRUE;
  12. break;
  13. }
  14. }
  15. if (!$exists) {
  16. - $referenced_entity->{$keys['away_field']}[LANGUAGE_NONE][] = array($ids['home'] => $home_entity->$ids['home']);
  17. + $referenced_entity->{$keys['away_field']}[LANGUAGE_NONE][] = array('target_id' => $home_entity->$ids['home']);
  18. }
  19. }
  20. -
  21. _corresponding_entity_references_update($keys['away_entity_type'], $referenced_entity);
  22. -
  23. }
  24. }
  25. }
  26. @@ -114,14 +112,7 @@ function corresponding_entity_references_update($home_entity, $keys, $process_un
  27. }
  28. }
  29. -
  30. - // If we are processing unchanged references, remove all new references
  31. - // from the old references.
  32. - if ($process_unchanged) {
  33. - $old = array_diff($old, $new);
  34. - }
  35. -
  36. - // Determine the nodereference values after the update.
  37. + // Determine the entityreference values after the update.
  38. if (isset($home_entity->$keys['home_field']) && is_array($home_entity->$keys['home_field'])) {
  39. foreach ($home_entity->$keys['home_field'] as $lang => $fields) {
  40. foreach ($fields as $reference) {
  41. @@ -132,8 +123,12 @@ function corresponding_entity_references_update($home_entity, $keys, $process_un
  42. }
  43. }
  44. + if ($old == $new){
  45. + return;
  46. + }
  47. +
  48. // Handle removed references.
  49. - if ( !empty($old) ) {
  50. + if (!empty($old) ) {
  51. foreach ($old as $data) {
  52. if ($removed = array_diff($old, $new)) {
  53. foreach ($removed as $id) {
  54. @@ -174,10 +169,9 @@ function corresponding_entity_references_update($home_entity, $keys, $process_un
  55. if ($referenced_entity->bundle_type == $keys['away_bundle'] && $id != $home_entity->$ids['home']) {
  56. // Detect whether the reference already exists.
  57. $exists = FALSE;
  58. -
  59. +
  60. if (isset($referenced_entity->{$keys['away_field']}[$referenced_entity->language]) && !empty($referenced_entity->{$keys['away_field']}[LANGUAGE_NONE])) {
  61. foreach ($referenced_entity->{$keys['away_field']}[LANGUAGE_NONE] as $data) {
  62. -
  63. if ($data['target_id'] == $home_entity->$ids['home']) {
  64. $exists = TRUE;
  65. break;
  66. @@ -271,7 +265,6 @@ function corresponding_entity_references_delete($home_entity, $keys, $process_un
  67. $referenced_entity->bundle_type = _corresponding_entity_references_entity_get_bundle($referenced_entity, $keys['away_entity_type']);
  68. if ($referenced_entity->bundle_type == $keys['away_bundle']) {
  69. // Iterate through the away entity's references.
  70. -
  71. foreach ($referenced_entity->{$keys['away_field']}[$lang] as $key => $value) {
  72. // Remove references to the deleted node.
  73. if ($value['target_id'] && $value['target_id'] == $home_entity->$ids['home']) {
  74. @@ -293,6 +286,7 @@ function corresponding_entity_references_delete($home_entity, $keys, $process_un
  75. * @param $node the referenced node to be updated.
  76. */
  77. function _corresponding_entity_references_update($entity_type, $entity) {
  78. + field_attach_presave($entity_type, $entity);
  79. field_attach_update($entity_type, $entity);
  80. }