Same name and namespace in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/process/MakeUniqueEntityField.php \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField::exists()
  2. 9 core/modules/migrate/src/Plugin/migrate/process/MakeUniqueEntityField.php \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField::exists()

This is a query checking the existence of some value.

Parameters

mixed $value: The value to check.

Return value

bool TRUE if the value exists.

Overrides MakeUniqueBase::exists

File

core/modules/migrate/src/Plugin/migrate/process/MakeUniqueEntityField.php, line 123

Class

MakeUniqueEntityField

Namespace

Drupal\migrate\Plugin\migrate\process

Code

protected function exists($value) {

  // Plugins are cached so for every run we need a new query object.
  $query = $this->entityTypeManager
    ->getStorage($this->configuration['entity_type'])
    ->getQuery()
    ->accessCheck(FALSE)
    ->condition($this->configuration['field'], $value);
  if (!empty($this->configuration['migrated'])) {

    // Check if each entity is in the ID map.
    $idMap = $this->migration
      ->getIdMap();
    foreach ($query
      ->execute() as $id) {
      $dest_id_values[$this->configuration['field']] = $id;
      if ($idMap
        ->lookupSourceId($dest_id_values)) {
        return TRUE;
      }
    }
    return FALSE;
  }
  else {

    // Just check if any such entity exists.
    return $query
      ->count()
      ->execute();
  }
}