public function MigrateExecutable::import in Migrate Manifest 8
Same name and namespace in other branches
- 8.2 src/MigrateExecutable.php \Drupal\migrate_manifest\MigrateExecutable::import()
- 3.x src/MigrateExecutable.php \Drupal\migrate_manifest\MigrateExecutable::import()
Performs an import operation - migrate items from source to destination.
Overrides MigrateExecutable::import
File
- src/
MigrateExecutable.php, line 22
Class
Namespace
Drupal\migrate_manifestCode
public function import() {
// Only begin the import operation if the migration is currently idle.
if ($this->migration
->getStatus() !== MigrationInterface::STATUS_IDLE) {
$this->message
->display($this
->t('Migration @id is busy with another operation: @status', [
'@id' => $this->migration
->id(),
'@status' => $this
->t($this->migration
->getStatusLabel()),
]), 'error');
return MigrationInterface::RESULT_FAILED;
}
$this
->getEventDispatcher()
->dispatch(MigrateEvents::PRE_IMPORT, new MigrateImportEvent($this->migration, $this->message));
// Knock off migration if the requirements haven't been met.
try {
$this->migration
->checkRequirements();
} catch (RequirementsException $e) {
$this->message
->display($this
->t('Migration @id did not meet the requirements. @message @requirements', [
'@id' => $this->migration
->id(),
'@message' => $e
->getMessage(),
'@requirements' => $e
->getRequirementsString(),
]), 'error');
return MigrationInterface::RESULT_FAILED;
}
$this->migration
->setStatus(MigrationInterface::STATUS_IMPORTING);
$return = MigrationInterface::RESULT_COMPLETED;
$source = $this
->getSource();
$destination = $this->migration
->getDestinationPlugin();
try {
foreach ($source as $row) {
$this
->importRow($row, $destination);
// Check for memory exhaustion.
if (($return = $this
->checkStatus()) != MigrationInterface::RESULT_COMPLETED) {
break;
}
// If anyone has requested we stop, return the requested result.
if ($this->migration
->getStatus() == MigrationInterface::STATUS_STOPPING) {
$return = $this->migration
->getInterruptionResult();
$this->migration
->clearInterruptionResult();
break;
}
}
} catch (\Exception $e) {
$this->message
->display($this
->t('Migration failed with source plugin exception: @e', [
'@e' => $e
->getMessage(),
]), 'error');
$this->migration
->setStatus(MigrationInterface::STATUS_IDLE);
return MigrationInterface::RESULT_FAILED;
}
$this
->getEventDispatcher()
->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration, $this->message));
$this->migration
->setStatus(MigrationInterface::STATUS_IDLE);
return $return;
}