MigrateImportEvent example

class MigrateImportEventTest extends UnitTestCase {

  /** * Tests getMigration method. * * @covers ::__construct * @covers ::getMigration */
  public function testGetMigration() {
    $migration = $this->prophesize('\Drupal\migrate\Plugin\MigrationInterface')->reveal();
    $message_service = $this->prophesize('\Drupal\migrate\MigrateMessageInterface')->reveal();
    $event = new MigrateImportEvent($migration$message_service);
    $this->assertSame($migration$event->getMigration());
  }

  /** * Tests logging a message. * * @covers ::__construct * @covers ::logMessage */
  public function testLogMessage() {
    $migration = $this->prophesize('\Drupal\migrate\Plugin\MigrationInterface');
    

  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(new MigrateImportEvent($this->migration, $this->message), MigrateEvents::PRE_IMPORT);

    // 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',
          [
            '@id' => $this->migration->id(),
            
Home | Imprint | This part of the site doesn't use cookies.