checkRequirements example

/** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (in_array('translation', $base_plugin_definition['migration_tags']) && !$this->includeTranslations) {
      // Refuse to generate anything.       return $this->derivatives;
    }

    $node_types = static::getSourcePlugin('d7_node_type');
    try {
      $node_types->checkRequirements();
    }
    catch (RequirementsException $e) {
      // If the d7_node_type requirements failed, that means we do not have a       // Drupal source database configured - there is nothing to generate.       return $this->derivatives;
    }

    try {
      foreach ($node_types as $row) {
        $node_type = $row->getSourceProperty('type');
        $values = $base_plugin_definition;

        

        'idMap' => [
          'plugin' => 'null',
        ],
        'destination' => [
          'plugin' => 'null',
        ],
      ];
      try {
        $profile_migration = $this->migrationPluginManager->createStubMigration($definition);
        // Ensure that Profile is enabled in the source DB.         $profile_migration->checkRequirements();
        foreach ($profile_migration->getSourcePlugin() as $row) {
          $name = $row->getSourceProperty('name');
          $this->process[$name] = $name;
        }
      }
      catch (RequirementsException $e) {
        // The checkRequirements() call will fail when the profile module does         // not exist on the source site.       }
    }
    return parent::getProcess();
  }
public function filterPluginDefinitionsByContexts(array $contexts, array $definitions) {
    $checked_requirements = [];
    return array_filter($definitionsfunction D$plugin_definition) use ($contexts, &$checked_requirements) {
      $context_definitions = $this->getContextDefinitions($plugin_definition);
      if ($context_definitions) {
        // Generate a unique key for the current context definitions. This will         // allow calling checkRequirements() once for all plugins that have the         // same context definitions.         $context_definitions_key = hash('sha256', serialize($context_definitions));
        if (!isset($checked_requirements[$context_definitions_key])) {
          // Check the set of contexts against the requirements.           $checked_requirements[$context_definitions_key] = $this->checkRequirements($contexts$context_definitions);
        }
        return $checked_requirements[$context_definitions_key];
      }
      // If this plugin doesn't need any context, it is available to use.       return TRUE;
    });
  }

  /** * Returns the context definitions associated with a plugin definition. * * @param array|\Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface $plugin_definition * The plugin definition. * * @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface[]|null * The context definitions, or NULL if the plugin definition does not * support contexts. */
      // have been successfully executed.       // @see Drupal\migrate_drupal\Plugin\MigrationWithFollowUpInterface       if (!empty(array_intersect($migration->getMigrationTags()$this->getFollowUpMigrationTags()))) {
        continue;
      }

      try {
        // @todo https://drupal.org/node/2681867 We should be able to validate         // the entire migration at this point.         $source_plugin = $migration->getSourcePlugin();
        if ($source_plugin instanceof RequirementsInterface) {
          $source_plugin->checkRequirements();
        }
        $destination_plugin = $migration->getDestinationPlugin();
        if ($destination_plugin instanceof RequirementsInterface) {
          $destination_plugin->checkRequirements();
        }
        $migrations[] = $migration;
      }
      catch (RequirementsException $e) {
        // Migrations which are not applicable given the source and destination         // site configurations (e.g., what modules are enabled) will be silently         // ignored.
if (!empty($disabled_source_modules)) {
      $this->sourceDatabase->update('system')
        ->condition('name', $disabled_source_modules, 'IN')
        ->fields(['status' => 0])
        ->execute();
    }

    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage($exception_message);
    $this->getMigration($migration_plugin_id)
      ->getSourcePlugin()
      ->checkRequirements();
  }

  /** * Test cases for ::testCheckCommentTypeRequirements(). */
  public function providerTestCheckCommentTypeRequirements() {
    return [
      'D6 comment is disabled on source' => [
        'Disabled source modules' => ['comment'],
        'RequirementsException message' => 'The module comment is not enabled in the source site.',
        'migration' => 'd6_comment_type',
      ],

  public function testRequiresModule() {
    $this->fail('Running test with missing required module.');
  }

  /** * Public access for checkRequirements() to avoid reflection. */
  public function publicCheckRequirements() {
    return parent::checkRequirements();
  }

}
    // connection does not throw any errors.     $migration_plugins = $this->container->get('plugin.manager.migration')->createInstances([]);
    // Any database-based source plugins should fail a requirements test in the     // absence of a source database connection (e.g., a connection with the     // 'migrate' key).     $source_plugins = array_map(function D$migration_plugin) {
      return $migration_plugin->getSourcePlugin();
    }$migration_plugins);
    foreach ($source_plugins as $id => $source_plugin) {
      if ($source_plugin instanceof RequirementsInterface) {
        try {
          $source_plugin->checkRequirements();
        }
        catch (RequirementsException $e) {
          unset($source_plugins[$id]);
        }
      }
    }

    // Without a connection defined, no database-based plugins should be     // returned.     foreach ($source_plugins as $id => $source_plugin) {
      $this->assertNotInstanceOf(SqlBase::class$source_plugin);
    }
$container->get('migrate_drupal.field_discovery')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {

    $vocabulary_source_plugin = static::getSourcePlugin('d7_taxonomy_vocabulary');
    try {
      $vocabulary_source_plugin->checkRequirements();
    }
    catch (RequirementsException $e) {
      // If the d7_taxonomy_vocabulary requirements failed, that means we do not       // have a Drupal source database configured - there is nothing to       // generate.       return $this->derivatives;
    }

    try {
      foreach ($vocabulary_source_plugin as $row) {
        $bundle = $row->getSourceProperty('machine_name');
        

  protected function getSourcePlugin($core) {
    $definition = $this->getFieldInstanceStubMigrationDefinition($core);
    $source_plugin = $this->migrationPluginManager
      ->createStubMigration($definition)
      ->getSourcePlugin();
    if ($source_plugin instanceof RequirementsInterface) {
      try {
        $source_plugin->checkRequirements();
      }
      catch (RequirementsException $e) {
        // If checkRequirements() failed, the source database did not support         // fields (i.e., Field is not installed in D7). Therefore, $fields will         // be empty and below we'll return an empty array. The migration will         // proceed without adding fields.         $this->logger->notice('Field discovery failed for Drupal core version @core. Did this site have the Field module installed? Error: @message', [
          '@core' => $core,
          '@message' => $e->getMessage(),
        ]);
        return [];
      }

  public function getIds() {
    $ids['type']['type'] = 'string';
    return $ids;
  }

  /** * {@inheritdoc} */
  public function checkRequirements() {
    parent::checkRequirements();
    if (!$this->moduleExists('node')) {
      // Drupal 6 and Drupal 7 comment configuration migrations migrate comment       // types and comment fields for node comments only.       throw new RequirementsException('The node module is not enabled in the source site.', [
        'source_module_additional' => 'node',
      ]);
    }
  }

}
public function testException() {
    $destination = new Config(
      ['config_name' => 'test'],
      'test',
      [],
      $this->prophesize(MigrationInterface::class)->reveal(),
      $this->prophesize(ConfigFactoryInterface::class)->reveal(),
      $this->prophesize(LanguageManagerInterface::class)->reveal()
    );
    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage("Destination plugin 'test' did not meet the requirements");
    $destination->checkRequirements();
  }

}
$app->render('welcome.php');

    if (!UPDATE_IS_MANUAL) {
        $app->redirect($app->urlFor('checks'));

        return;
    }
})->via('GET', 'POST')->name('welcome');

// Check file & directory permissions $app->map('/checks', function D) use ($container) {
    $container->get('controller.requirements')->checkRequirements();
})->via('GET', 'POST')->name('checks');

$app->map('/plugin-checks', function D) use ($app$container) {
    /** @var PluginCheck $pluginCheck */
    $pluginCheck = $container->get('plugin.check');
    $plugins = $pluginCheck->checkPlugins();

    $app->render('plugins.php', ['plugins' => $plugins]);
})->via('GET', 'POST')->name('plugin-checks');

$app->map('/dbmigration', function D) use ($app) {
    
$this->sourceDatabase->schema()->dropTable('i18n_variable');
  }

  /** * Tests exception in thrown when the i18n_variable table does not exist. */
  public function testCheckRequirements() {
    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage("Source database table 'i18n_variable' does not exist");
    $this->getMigration('d6_system_maintenance_translation')
      ->getSourcePlugin()
      ->checkRequirements();
  }

}

  public function testRequiresModule() {
    $this->fail('Running test with missing required module.');
  }

  /** * Public access for checkRequirements() to avoid reflection. */
  public function publicCheckRequirements() {
    return parent::checkRequirements();
  }

}
$container = TestKernel::setContainerWithKernel();
    $container->set('typed_data_manager', $type_data_manager);
    \Drupal::setContainer($container);
  }

  /** * @covers ::checkRequirements * * @dataProvider providerTestCheckRequirements */
  public function testCheckRequirements($contexts$requirements$expected) {
    $this->assertSame($expected$this->contextHandler->checkRequirements($contexts$requirements));
  }

  /** * Provides data for testCheckRequirements(). */
  public function providerTestCheckRequirements() {
    $requirement_optional = new ContextDefinition();
    $requirement_optional->setRequired(FALSE);

    $requirement_any = new ContextDefinition();
    $requirement_any->setRequired(TRUE);

    
Home | Imprint | This part of the site doesn't use cookies.