You are here

class MigrateHelper in Panopoly Core 8.2

Service with some helper functions for working with migrate.

Hierarchy

Expanded class hierarchy of MigrateHelper

1 file declares its use of MigrateHelper
MigrateHelperTest.php in tests/src/Unit/MigrateHelperTest.php
1 string reference to 'MigrateHelper'
panopoly_core.services.yml in ./panopoly_core.services.yml
panopoly_core.services.yml
1 service uses MigrateHelper
panopoly_core.migrate_helper in ./panopoly_core.services.yml
Drupal\panopoly_core\MigrateHelper

File

src/MigrateHelper.php, line 13

Namespace

Drupal\panopoly_core
View source
class MigrateHelper {

  /**
   * The migration plugin manager.
   *
   * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
   */
  protected $migrationManager;

  /**
   * The migrate message object.
   *
   * @var \Drupal\migrate\MigrateMessageInterface
   */
  protected $migrateMessage;

  /**
   * Constructs the migration helper server.
   *
   * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_manager
   *   The migration manager.
   */
  public function __construct(MigrationPluginManagerInterface $migration_manager) {
    $this->migrationManager = $migration_manager;
  }

  /**
   * Gets the migrate message object.
   *
   * @return \Drupal\migrate\MigrateMessageInterface
   *   The migrate message object.
   */
  protected function getMessageObject() {
    if (!$this->migrateMessage) {
      $this->migrateMessage = new MigrateMessage();
    }
    return $this->migrateMessage;
  }

  /**
   * Create a new migrate executable.
   *
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   *   The migration.
   *
   * @return \Drupal\migrate\MigrateExecutableInterface
   *   The migrate executable.
   */
  protected function createExecutable(MigrationInterface $migration) {
    return new MigrateExecutable($migration, $this
      ->getMessageObject());
  }

  /**
   * Imports the given migrations in order.
   *
   * @param string[] $migration_ids
   *   List of migration ids to import.
   */
  public function import(array $migration_ids) {
    $migrations = $this->migrationManager
      ->createInstances($migration_ids);
    foreach ($migrations as $migration) {
      $executable = $this
        ->createExecutable($migration);
      $executable
        ->import();
    }
  }

  /**
   * Rolls back the given migrations in reverse order.
   *
   * @param array $migration_ids
   *   List of migration ids to rollback.
   */
  public function rollback(array $migration_ids) {

    // Do the migrations in reverse (half-ass dependency checking).
    $migration_ids = array_reverse($migration_ids);
    $migrations = $this->migrationManager
      ->createInstances($migration_ids);
    foreach ($migrations as $migration) {
      $executable = $this
        ->createExecutable($migration);
      $executable
        ->rollback();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateHelper::$migrateMessage protected property The migrate message object.
MigrateHelper::$migrationManager protected property The migration plugin manager.
MigrateHelper::createExecutable protected function Create a new migrate executable.
MigrateHelper::getMessageObject protected function Gets the migrate message object.
MigrateHelper::import public function Imports the given migrations in order.
MigrateHelper::rollback public function Rolls back the given migrations in reverse order.
MigrateHelper::__construct public function Constructs the migration helper server.