You are here

public function MigrateExecutable::onPostImport in GatherContent 8.5

File

src/MigrateExecutable.php, line 113

Class

MigrateExecutable
Defines a migrate executable class.

Namespace

Drupal\gathercontent

Code

public function onPostImport(MigrateImportEvent $event) {
  parent::onPostImport($event);
  $rows = [];
  $migration = $event
    ->getMigration();
  $destinationConfiguration = $migration
    ->getDestinationConfiguration();
  $plugin = explode(':', $destinationConfiguration['plugin']);
  $sourceConfiguration = $migration
    ->getSourceConfiguration();
  $pluginDefinition = $migration
    ->getPluginDefinition();
  foreach ($this->idlist as $item) {
    $rows[] = $event
      ->getMigration()
      ->getIdMap()
      ->getRowBySource($item);
  }
  if (empty($rows)) {
    return;
  }
  foreach ($rows as $row) {
    if (empty($row) || empty($row['destid1'])) {
      continue;
    }
    if (!empty($this->importOptions[$row['sourceid1']])) {

      /** @var \Drupal\gathercontent\Import\ImportOptions $options */
      $options = $this->importOptions[$row['sourceid1']];
      $parentMenuItem = $options
        ->getParentMenuItem();
      if (!empty($parentMenuItem) && $parentMenuItem != '0') {

        // TODO: Use the entity type from the mapping, not the node!

        /** @var \Drupal\node\NodeInterface $entity */
        $entity = Node::load($row['destid1']);

        // TODO: Rewrite menu creator to support none node entities too.
        if ($entity) {
          MenuCreator::createMenu($entity, $parentMenuItem);
        }
      }
      $newGcStatus = $options
        ->getNewStatus();
      if ($newGcStatus && is_int($newGcStatus)) {
        $status = $this->client
          ->projectStatusGet($sourceConfiguration['projectId'], $newGcStatus);

        // Update only if status exists.
        if ($status !== NULL) {

          // Update status on GC.
          $this->client
            ->itemChooseStatusPost($row['sourceid1'], $newGcStatus);
          $this->latestGcStatus = $status;
        }
      }
    }
    $this
      ->trackEntities($row, $plugin[1], $sourceConfiguration['templateName'], $migration
      ->id(), $pluginDefinition['langcode']);
  }
}