You are here

public function Migration::checkRequirements in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/Migration.php \Drupal\migrate\Plugin\Migration::checkRequirements()
  2. 9 core/modules/migrate/src/Plugin/Migration.php \Drupal\migrate\Plugin\Migration::checkRequirements()

Checks if requirements for this plugin are OK.

Throws

\Drupal\migrate\Exception\RequirementsException Thrown when requirements are not met.

Overrides RequirementsInterface::checkRequirements

File

core/modules/migrate/src/Plugin/Migration.php, line 507

Class

Migration
Defines the Migration plugin.

Namespace

Drupal\migrate\Plugin

Code

public function checkRequirements() {

  // Check whether the current migration source and destination plugin
  // requirements are met or not.
  if ($this
    ->getSourcePlugin() instanceof RequirementsInterface) {
    $this
      ->getSourcePlugin()
      ->checkRequirements();
  }
  if ($this
    ->getDestinationPlugin() instanceof RequirementsInterface) {
    $this
      ->getDestinationPlugin()
      ->checkRequirements();
  }
  if (empty($this->requirements)) {

    // There are no requirements to check.
    return;
  }

  /** @var \Drupal\migrate\Plugin\MigrationInterface[] $required_migrations */
  $required_migrations = $this
    ->getMigrationPluginManager()
    ->createInstances($this->requirements);
  $missing_migrations = array_diff($this->requirements, array_keys($required_migrations));

  // Check if the dependencies are in good shape.
  foreach ($required_migrations as $migration_id => $required_migration) {
    if (!$required_migration
      ->allRowsProcessed()) {
      $missing_migrations[] = $migration_id;
    }
  }
  if ($missing_migrations) {
    throw new RequirementsException('Missing migrations ' . implode(', ', $missing_migrations) . '.', [
      'requirements' => $missing_migrations,
    ]);
  }
}