You are here

function prod_check_dbstatus in Production check & Production monitor 7

Same name and namespace in other branches
  1. 6 includes/prod_check.admin.inc \prod_check_dbstatus()

Database status page.

1 string reference to 'prod_check_dbstatus'
prod_check_menu in ./prod_check.module
Implementation of hook_menu()

File

includes/prod_check.admin.inc, line 759

Code

function prod_check_dbstatus() {

  // Get active connection.
  $pdo = Database::getConnection();

  // Get database driver.
  $db_type = $pdo
    ->getAttribute(PDO::ATTR_DRIVER_NAME);
  $details = array(
    'status' => array(),
    'tables' => array(),
    'databases' => array(),
  );
  $add_js = FALSE;
  $title = '';
  $db = $db_type;
  switch ($db_type) {
    case 'pgsql':

      // Set title & version.
      $server = db_query('SELECT version()')
        ->fetchField();
      $title = t('Running @version', array(
        '@version' => $server,
      ));

      // Get detailed status.
      $details = _prod_check_dbstatus_pgsql($details);
      break;
    case 'mysql':
      $db = 'MySQL';

      // Get detailed status.
      $details = _prod_check_dbstatus_mysql($details);

    // NO break here!
    default:

      // Set title & version.
      $server = $pdo
        ->getAttribute(PDO::ATTR_SERVER_VERSION);
      $title = t('Running @db @version', array(
        '@db' => $db,
        '@version' => $server,
      ));
      break;
  }

  // Get basic status.
  $status = '';
  try {
    $status = $pdo
      ->getAttribute(PDO::ATTR_SERVER_INFO);
    if (is_array($status)) {
      $status = implode("<br />\n", $status);
    }
    else {
      $status = str_replace('  ', "<br />\n", $status);
    }
  } catch (Exception $e) {
  }

  // Get additional status.
  $additional = '';
  $attributes = array(
    'AUTOCOMMIT' => 'Auto commit',
    'PREFETCH' => 'Prefetch',
    'TIMEOUT' => 'Timeout',
    'ERRMODE' => 'Error mode',
    'CLIENT_VERSION' => 'Client version',
    'CONNECTION_STATUS' => 'Connection status',
    'CASE' => 'Case',
    'CURSOR_NAME' => 'Cursor name',
    'CURSOR' => 'Cursor',
    'ORACLE_NULLS' => 'Oracle nulls',
    'PERSISTENT' => 'Persistent',
    'STATEMENT_CLASS' => 'Statement class',
    'FETCH_CATALOG_NAMES' => 'Fatch catalog names',
    'FETCH_TABLE_NAMES' => 'Fetch table names',
    'STRINGIFY_FETCHES' => 'Stringify fetches',
    'MAX_COLUMN_LEN' => 'Max column length',
    'DEFAULT_FETCH_MODE' => 'Default fetch mode',
    'EMULATE_PREPARES' => 'Emulate prepares',
  );
  foreach ($attributes as $constant => $name) {
    try {
      $result = $pdo
        ->getAttribute(constant("PDO::ATTR_{$constant}"));
      if (is_bool($result)) {
        $result = $result ? 'TRUE' : 'FALSE';
      }
      elseif (is_array($result) || is_object($result)) {
        $add_js = TRUE;
        include_once DRUPAL_ROOT . '/includes/utility.inc';
        $class = strtolower(str_replace('_', '-', $constant));
        $link = l(t('Show details'), 'admin/reports/status/database', array(
          'attributes' => array(
            'class' => array(
              'show-more',
            ),
            'data-details' => $class,
          ),
        ));

        // Seemed a bit overkill to create a css file only for this display:none
        // thingy.
        $result = $link . '<pre class="' . $class . '" style="display:none;">' . drupal_var_export($result) . '</pre>';
      }
      $additional .= $name . ': ' . $result . "<br />\n";
    } catch (Exception $e) {
    }
  }
  $status = "{$additional}<br />\n{$status}";
  if ($add_js) {
    $base = drupal_get_path('module', 'prod_check');
    drupal_add_js($base . '/js/prod-check-database.js');
  }
  return theme('prod_check_dbstatus', array(
    'title' => $title,
    'status' => $status,
    'details' => $details,
  ));
}