You are here

function drush_drupalmoduleupgrader_dmu_analyze in Drupal 7 to 8/9 Module Upgrader 8

Analyzes what needs changing in a module to port it to Drupal 8.

Parameters

string $module: The machine name of the module to analyze.

File

./drupalmoduleupgrader.drush.inc, line 279
Declarations for Drush.

Code

function drush_drupalmoduleupgrader_dmu_analyze($module) {
  $target = _dmu_build_target($module);
  $total_issues = 0;
  $report = new Report();
  $analyzers = \Drupal::service('plugin.manager.drupalmoduleupgrader.analyzer');
  foreach (_dmu_plugin_list('analyzer') as $id) {
    drush_log(\Drupal::translation()
      ->translate('Executing plugin: @plugin_id', [
      '@plugin_id' => $id,
    ]), 'notice');
    $issues = $analyzers
      ->createInstance($id)
      ->analyze($target);
    if ($issues) {
      if (!is_array($issues)) {
        $issues = [
          $issues,
        ];
      }
      foreach ($issues as $issue) {
        $report
          ->addIssue($issue);
      }
      $total_issues += count($issues);
    }
  }
  if ($total_issues) {
    $render = [
      '#theme' => 'dmu_report',
      '#report' => $report,
      '#group_by' => 'category',
    ];
    $destination = drush_get_option('output', $target
      ->getPath('upgrade-info.html'));
    $output = \Drupal::service('renderer')
      ->renderRoot($render);
    file_put_contents($destination, $output);
    drush_log(\Drupal::translation()
      ->translate('Generated a report at @path', [
      '@path' => $destination,
    ]), 'success');
  }
  else {
    drush_log(\Drupal::translation()
      ->translate('Wow...no issues found! You get a cookie :)', 'success'));
  }
}