function drush_views_analyze

8.0.x views.d8.drush.inc drush_views_analyze()
7.x views.d8.drush.inc drush_views_analyze()

Drush views analyze command.

File

commands/core/views.d8.drush.inc, line 310
Drush integration for views.

Code

function drush_views_analyze() {
  $messages = NULL;
  $messages_count = 0;

  $format = drush_get_option('format', FALSE);

  $views = Drupal::entityManager()->getStorage('view')->loadMultiple();

  if (!empty($views)) {
    $analyzer = Drupal::service('views.analyzer');
    foreach ($views as $view_name => $view) {
      $view = $view->getExecutable();

      if ($messages = $analyzer->getMessages($view)) {
        if ($format) {
          $output = drush_format($messages, $format);
          drush_print($output);
          return $output;
        }
        else {
          drush_print($view_name);
          foreach ($messages as $message) {
            $messages_count++;
            drush_print($message['type'] . ': ' . $message['message'], 2);
          }
        }
      }
    }

    drush_log(dt('A total of @total views were analyzed and @messages problems were found.', array('@total' => count($views), '@messages' => $messages_count)), LogLevel::OK);
    return $messages;
  }
  else {
    return drush_set_error(dt('There are no views to analyze'));
  }
}