Verified Commit 68c1000f authored by Dave Long's avatar Dave Long
Browse files

Issue #3052115 by huzooka, HitchShock, floydm, ranjith_kumar_k_u, Sam152,...

Issue #3052115 by huzooka, HitchShock, floydm, ranjith_kumar_k_u, Sam152, edysmp, codebymikey, herved, Wim Leers, quietone, hchonov, Berdir, DamienMcKenna, rclemings, donquixote, benjifisher, fengtan, jwilson3: Mark an entity as 'syncing' during a migration update
parent 0448b4bc
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\migrate\Plugin\migrate\destination;

use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\DependencyTrait;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
@@ -215,6 +216,9 @@ public function rollback(array $destination_identifier) {
    // Delete the specified entity from Drupal if it exists.
    $entity = $this->storage->load(reset($destination_identifier));
    if ($entity) {
      if ($entity instanceof ContentEntityInterface) {
        $entity->setSyncing(TRUE);
      }
      $entity->delete();
    }
  }
+2 −0
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ public function validateEntity(FieldableEntityInterface $entity) {
   *   An array containing the entity ID.
   */
  protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
    $entity->setSyncing(TRUE);
    $entity->save();
    return [$entity->id()];
  }
@@ -380,6 +381,7 @@ public function rollback(array $destination_identifier) {
              $translation = $entity->getTranslation($langcode);
              if (!$translation->isDefaultTranslation()) {
                $entity->removeTranslation($langcode);
                $entity->setSyncing(TRUE);
                $entity->save();
              }
            }
+1 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ protected function getEntity(Row $row, array $old_destination_id_values) {
   * {@inheritdoc}
   */
  protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
    $entity->setSyncing(TRUE);
    $entity->save();
    return [$entity->getRevisionId()];
  }
+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Row;
use Prophecy\Argument;

/**
 * Tests base entity migration destination functionality.
@@ -44,6 +45,9 @@ public function testImport() {
    // Assert that save is called.
    $entity->save()
      ->shouldBeCalledTimes(1);
    // Syncing should be set once.
    $entity->setSyncing(Argument::exact(TRUE))
      ->shouldBeCalledTimes(1);
    // Set an id for the entity
    $entity->id()
      ->willReturn(5);
+4 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;

/**
 * Tests entity revision destination.
@@ -178,6 +179,9 @@ public function testSave() {
    $entity = $this->prophesize('\Drupal\Core\Entity\ContentEntityInterface');
    $entity->save()
      ->shouldBeCalled();
    // Syncing should be set once.
    $entity->setSyncing(Argument::exact(TRUE))
      ->shouldBeCalledTimes(1);
    $entity->getRevisionId()
      ->shouldBeCalled()
      ->willReturn(1234);
Loading