You are here

protected function MigrateExecutable::trackEntities in GatherContent 8.5

Tracks the entity changes, to show in a table after the migration run.

1 call to MigrateExecutable::trackEntities()
MigrateExecutable::onPostImport in src/MigrateExecutable.php

File

src/MigrateExecutable.php, line 174

Class

MigrateExecutable
Defines a migrate executable class.

Namespace

Drupal\gathercontent

Code

protected function trackEntities(array $row, string $plugin, string $templateName, $migrationId, string $langcode) {
  $tracked = $this->session
    ->get('gathercontent_tracked_entities', []);
  $tracked[$row['sourceid1']] = [
    'id' => $row['destid1'],
    'entity_type' => $plugin,
    'status' => $this->latestGcStatus,
    'template_name' => $templateName,
  ];
  $this->session
    ->set('gathercontent_tracked_entities', $tracked);
  $connection = \Drupal::service('database');
  $result = $connection
    ->select('gathercontent_entity_mapping')
    ->fields('gathercontent_entity_mapping', [
    'entity_id',
    'entity_type',
  ])
    ->condition('entity_id', $row['destid1'])
    ->condition('entity_type', $plugin)
    ->condition('langcode', $langcode)
    ->execute()
    ->fetchAll();
  if (!empty($result)) {
    return;
  }
  $connection
    ->insert('gathercontent_entity_mapping')
    ->fields([
    'entity_id' => $row['destid1'],
    'entity_type' => $plugin,
    'gc_id' => $row['sourceid1'],
    'migration_id' => $migrationId,
    'langcode' => $langcode,
  ])
    ->execute();
}