function MigrateStub::doCreateStub

Same name in other branches
  1. 8.9.x core/modules/migrate/src/MigrateStub.php \Drupal\migrate\MigrateStub::doCreateStub()
  2. 10 core/modules/migrate/src/MigrateStub.php \Drupal\migrate\MigrateStub::doCreateStub()
  3. 11.x core/modules/migrate/src/MigrateStub.php \Drupal\migrate\MigrateStub::doCreateStub()

Creates a stub.

Parameters

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration to use to create the stub.

array $source_ids: The source ids to map to the stub.

array $default_values: (optional) An array of values to include in the stub.

Return value

array|bool An array of destination ids for the stub.

Throws

\Drupal\migrate\MigrateException

1 call to MigrateStub::doCreateStub()
MigrateStub::createStub in core/modules/migrate/src/MigrateStub.php
Creates a stub.

File

core/modules/migrate/src/MigrateStub.php, line 106

Class

MigrateStub
Provides the migrate stubbing service.

Namespace

Drupal\migrate

Code

protected function doCreateStub(MigrationInterface $migration, array $source_ids, array $default_values = []) {
    $destination = $migration->getDestinationPlugin(TRUE);
    $process = $migration->getProcess();
    $id_map = $migration->getIdMap();
    $migrate_executable = new MigrateExecutable($migration);
    $row = new Row($source_ids + $migration->getSourceConfiguration(), $migration->getSourcePlugin()
        ->getIds(), TRUE);
    $migrate_executable->processRow($row, $process);
    foreach ($default_values as $key => $value) {
        $row->setDestinationProperty($key, $value);
    }
    $destination_ids = [];
    try {
        $destination_ids = $destination->import($row);
    } catch (\Exception $e) {
        $id_map->saveMessage($row->getSourceIdValues(), $e->getMessage());
    }
    if ($destination_ids) {
        $id_map->saveIdMapping($row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
        return $destination_ids;
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.