You are here

prod_check.drush.inc in Production check & Production monitor 6

Same filename and directory in other branches
  1. 7 prod_check.drush.inc

File

prod_check.drush.inc
View source
<?php

/**
 * Implementation of hook_drush_command().
 */
function prod_check_drush_command() {
  $items = array();
  $items['prod-check'] = array(
    'callback' => 'drush_prod_check_status',
    'description' => 'Display the Production Check status page.',
    'aliases' => array(
      'pchk',
    ),
  );
  $items['prod-check-prodmode'] = array(
    'callback' => 'drush_prod_check_prod_mode',
    'description' => 'Switch the site to production mode.',
    'options' => array(
      'config' => 'Ask for additional options before switching to production mode.',
    ),
    'aliases' => array(
      'pchk-pmode',
    ),
  );
  return $items;
}

/**
 * Status page callback
 */
function drush_prod_check_status() {

  // Map error codes to shell colours.
  $severity = array(
    PROD_CHECK_REQUIREMENT_INFO => '1',
    PROD_CHECK_REQUIREMENT_OK => '1;32',
    PROD_CHECK_REQUIREMENT_WARNING => '1;33',
    PROD_CHECK_REQUIREMENT_ERROR => '1;31',
  );
  $error = 0;
  $functions = _prod_check_functions();

  // Not needed here.
  unset($functions['prod_mon']);
  unset($functions['perf_data']);
  foreach ($functions as $set => $data) {
    $rows[] = array(
      '',
    );
    $rows[] = array(
      "\33[1m" . dt($data['title']) . "\33[0m",
    );
    foreach ($data['functions'] as $function => $title) {
      $result = call_user_func($function);
      $func = ltrim($function, '_');
      if (is_array($result) && !empty($result)) {
        $rows[] = array(
          $result[$func]['title'],
          "\33[" . $severity[$result[$func]['severity']] . 'm' . strip_tags($result[$func]['value']) . "\33[0m",
        );
        if ($error < $result[$func]['severity']) {
          $error = $result[$func]['severity'];
        }
      }
    }
  }
  drush_print("\33[1m" . dt('Production Check status') . "\33[0m", 1);
  drush_print_table($rows);
  if ($error > 0) {

    // Would be cool if we could prefix the admin path with http://<host>/ so it
    // will become a clickable link in some terminals. Any ideas?
    drush_print("\33[1m" . dt('Some errors were reported!') . "\33[0m " . dt('Check the full status page on') . " \33[1m" . 'admin/reports/prod-check' . "\33[0m " . dt('for details.'));
  }
}

/**
 * Switch to production mode.
 */
function drush_prod_check_prod_mode() {
  $options = array();

  // Ask extra input when the --config option is used.
  if (drush_get_option('config', FALSE)) {
    $options['site_mail'] = drush_prompt(dt('Site e-mail address'));
    if (module_exists('webform')) {
      $options['webform_default_from_address'] = drush_prompt(dt('Webform default from e-mail address'));
    }
    if (module_exists('googleanalytics')) {
      $options['googleanalytics_account'] = drush_prompt(dt('Google Analytics Web Property ID'));
    }
    $options['block_cache'] = drush_confirm(dt('Enable Block cache'));
    if (module_exists('dblog')) {
      $options['dblog'] = drush_confirm(dt('Disable Database logging'));
    }
    $options['nagios'] = drush_confirm(dt('Enable Nagios monitoring contrib module'));
  }

  // Adjust settings.
  module_load_include('inc', 'prod_check', 'includes/prod_check.admin');
  $variables = prod_check_prod_mode_settings($options);
  drush_print(dt('The following settings have been changed: !variables.', array(
    '!variables' => implode(', ', array_keys($variables)),
  )));

  // Enable / disable modules.
  $modules = prod_check_prod_mode_modules($options);
  if (!empty($modules['disable'])) {
    drush_print(dt('The following modules have been disabled: !modules.', array(
      '!modules' => implode(', ', $modules['disable']),
    )));
  }
  if (!empty($modules['enable'])) {
    drush_print(dt('The following modules have been enabled: !modules.', array(
      '!modules' => implode(', ', $modules['enable']),
    )));
  }
}

Functions

Namesort descending Description
drush_prod_check_prod_mode Switch to production mode.
drush_prod_check_status Status page callback
prod_check_drush_command Implementation of hook_drush_command().