0

I'm currently migrating my website to D8 and I'm having some issues updating my NEW nodes to match with my live D7 site.

I get a few of these for each content type. I think it's from creating "test page" and the node ID is taken.

I get a few of these warnings:

 [error]  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'e0891884-4da7-45c9-a1b5-808c8f821cfa' for key 'node_field__uuid__value': UPDATE {node} SET vid=:db_update_placeholder_0, type=:db_update_placeholder_1, uuid=:db_update_placeholder_2, langcode=:db_update_placeholder_3
WHERE nid = :db_condition_placeholder_0; Array
(
 [:db_update_placeholder_0] => 61287
 [:db_update_placeholder_1] => festival
 [:db_update_placeholder_2] => e0891884-4da7-45c9-a1b5-808c8f821cfa
 [:db_update_placeholder_3] => und
 [:db_condition_placeholder_0] => 3943
)

I tried drush migrate-import upgrade_d7_node_festival --update , but that didn't work. Is there a way to overwrite my test nodes when migrating? Do I have to go and delete all the table nodes in my DB then rerun the migration?

Thank!

0

sadly there is no "vanilla" way in migrate / migrate_tools / migrate_plus, to achieve this, at least that i know of.

I think the best solution is to create a custom plugin and append it to your yml file at the uuid field.

I should probably look something like this. Disclaimer: The following snippet is derived from https://www.drupal.org/project/migrate_plus/issues/3060320 and modified to suit your case specifically. It is not tested though.

<?php

namespace Drupal\your_module\Plugin\migrate\process;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Skips processing the current row when a same entity already exists.
 *
 * Examples:
 *
 * @code
 * process:
 *   name:
 *     plugin: skip_on_duplicate_entity_exists
 * @endcode
 *
 * @MigrateProcessPlugin(
 *   id = "skip_on_duplicate_entity_exists"
 * )
 */
class SkipOnDuplicateEntityExists extends ProcessPluginBase implements ContainerFactoryPluginInterface {

  /**
   * The entity storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * EntityExists constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->storage = $storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      // Use configuration instead of "node" for a mode generic solution
      $container->get('entity_type.manager')->getStorage('node')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $entityQuery = $this->storage->getQuery();

    $existingEntities = $entityQuery
      ->condition('uuid', $value)
      ->execute();

    /* The result is either an entity id string,
    or an array of entity id strings.
    If either one is not empty, there's a duplicate. */
    if (!empty($existingEntities)) {
      throw new MigrateSkipRowException();
    }

    return $value;
  }

}

You can find more on custom migrate plugins here https://www.drupal.org/docs/8/api/migrate-api/migrate-process/writing-a-process-plugin.

Let me know it it helped, or if you need any further assistance / clarification.

  • Thanks for helping! I think I have to go into my D8 Database and remove ALL of my content nodes then re-migrate them in because I created some "test/lorem ipsum" pages that took over the node ID that my D7 site is using. – Tenza Jan 11 at 17:44
  • HI M.Anagnostopoulos, I have a test page using UUID 7785 in my new D8 site, but my D7 site UUID 7785 actually has real content in it. So when importing new content from D7 to D8, I get the error. Do you know if there's a way to overwrite the UUID? Or in PHPMyAdmin, is there a way I can find the UUID in the DB to manually remove it? – Tenza Jan 11 at 19:28
  • @Tenza 7785 does not look like a uuid, it looks like a nid.. uuids look like the one in your original post (e0891884-4da7-45c9-a1b5-808c8f821cfa). In Any case, you can find both in the 'node' table in your database and even edit them on the spot (just double click the value you want to change) Not sure i understand your question correctly though.. let me know if i misunderstood. Kind Regards – M.Anagnostopoulos Jan 12 at 14:08
  • I went into my 'node' table and removed my test pages and the i didnt get the errors any more. But just one. I'll just manually create the missing page. Thanks for your help! – Tenza Jan 12 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.