Skip to content
Snippets Groups Projects

Issue #2698425: Do not reimport existing entities

Issue #2698425 by kalpaitch, das-peter, jts86, andreyks, andypost, timmillwood, Karsa, robert-os, RumyanaRuseva, lammensj, e0ipso, morsok, r.nabiullin, Yaron Tal, plopesc, jamedina97, diegodalr3, robpowell, saramato, larowlan, eelkeblok, Manuel Garcia, vijaycs85, keesje, yannisc, chr.fritsch, ao2, youfei.sun, agentrickard, neclimdul, SocialNicheGuru, getu-lar, bircher: Do not reimport existing entities

Closes #2698425

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
178 178 $values[$entity_type->getKey('langcode')] = $data['_meta']['default_langcode'];
179 179 }
180 180
181 // Load the entity by UUID and check if it exists.
182 $existing = $this->entityTypeManager->getStorage($entity_type->id())->loadByProperties(['uuid' => $values['uuid']]);
  • 178 178 $values[$entity_type->getKey('langcode')] = $data['_meta']['default_langcode'];
    179 179 }
    180 180
    181 // Load the entity by UUID and check if it exists.
    182 $existing = $this->entityTypeManager->getStorage($entity_type->id())->loadByProperties(['uuid' => $values['uuid']]);
    181 183 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    182 $entity = $this->entityTypeManager->getStorage($entity_type->id())->create($values);
    184 if (!empty($existing)) {
    185 $entity = reset($existing);
    186 if (!$update_existing) {
    187 // Do not override the existing entity.
    188 return $entity;
    189 }
    • Should we not do something about when $update_existing is true?

    • When $update_existing is true the code below will be executed which will take care of updating the entity.

    • Found a bug here, because there is a use case when dependencies won't reset, then next call will won't fill from data depends, then it will cause NULL loaded entity, so if we return then we must check the same logic as we do in the end of this function:

      if ($is_root) {
        $this->dependencies = NULL;
      }

      So the code should like something like this:

      if (!$update_existing) {
        if ($is_root) {
          $this->dependencies = NULL;
        }
        // Do not override the existing entity.
        return $entity;
      }
    • Please register or sign in to reply
  • Justin Toupin added 1 commit

    added 1 commit

    • c42f7c38 - Pass update_existing flag to setFieldValues and nested entities. Set needsSave where necessary.

    Compare with previous version

  • 189 208 if ($this->languageManager->getLanguage($langcode)) {
    190 209 $translation = $entity->addTranslation($langcode, $entity->toArray());
    191 210 foreach ($translation_data as $field_name => $values) {
    192 $this->setFieldValues($translation, $field_name, $values);
    211 $this->setFieldValues($translation, $field_name, $values, $update_existing);
  • 178 178 $values[$entity_type->getKey('langcode')] = $data['_meta']['default_langcode'];
    179 179 }
    180 180
    181 // Load the entity by UUID and check if it exists.
    182 $existing = $this->entityTypeManager->getStorage($entity_type->id())->loadByProperties(['uuid' => $values['uuid']]);
    181 183 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    182 $entity = $this->entityTypeManager->getStorage($entity_type->id())->create($values);
    184 if (!empty($existing)) {
    185 $entity = reset($existing);
    186 // @todo Use instanceof EntityNeedSaveInterface once
    187 // https://www.drupal.org/project/entity_reference_revisions/issues/3336752
    188 // is fixed.
    189 if (method_exists($entity, 'setNeedsSave')) {
    190 $entity->setNeedsSave(TRUE);
  • Justin Toupin added 1 commit

    added 1 commit

    • 5c486fa9 - Only set setNeedsSave() if is false.

    Compare with previous version

  • Fran Macía added 1 commit

    added 1 commit

    • a4ab874a - Use translations if already exists

    Compare with previous version

  • Pieter Frenssen
    Pieter Frenssen @pfrenssen started a thread on commit a4ab874a
  • 207 207 if (!empty($data['translations'])) {
    208 208 foreach ($data['translations'] as $langcode => $translation_data) {
    209 209 if ($this->languageManager->getLanguage($langcode)) {
    210 $translation = $entity->addTranslation($langcode, $entity->toArray());
    210 $translation = $entity->hasTranslation($langcode)
    211 ? $entity->getTranslation($langcode)
    212 : $entity->addTranslation($langcode, $entity->toArray());
  • Pieter Frenssen added 7 commits

    added 7 commits

    • a4ab874a...9efd1d54 - 5 commits from branch project:2.0.x
    • 730d7659 - Merge remote-tracking branch 'origin/2.0.x' into 2698425-do-not-reimport
    • a7e85efd - Do a more robust check for entities using the Entity Reference Revision module.

    Compare with previous version

  • 17 17 use Drupal\Core\TypedData\PrimitiveInterface;
    18 18 use Drupal\Core\TypedData\TypedDataInterface;
    19 19 use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
    20 use Drupal\entity_reference_revisions\EntityNeedsSaveInterface;
  • sorlov added 9 commits

    added 9 commits

    Compare with previous version

  • Please register or sign in to reply
    Loading