You are here

dba.module in Database Administration 7

Same filename and directory in other branches
  1. 5 dba.module

Directly administer your Drupal website.

File

dba.module
View source
<?php

/**
 * @file
 * Directly administer your Drupal website.
 */

/**
 * Implements hook_help().
 */
function dba_help($path, $arg) {
  switch ($path) {
    case 'admin/help#dba':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The dba module allows site administrators a method for direct database administration. This is a dangerous module, in that it gives unlimited access and control over the active database. With this module, it is possible to corrupt or delete an entire drupal database. Use at your own risk.') . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Viewing database tables') . '</dt>';
      $output .= '</dl>';
      return $output;
  }
}

/**
 * Implements hook_permission().
 */
function dba_permission() {
  return array(
    'administer database' => array(
      'title' => t('Manage database tables and data'),
      'description' => drupal_placeholder(t('Warning: This permission has security implications allowing a user to edit any data in any table in this and possibly other databases on this server.')),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function dba_menu() {
  $items = array();
  $items['admin/config/development/dba'] = array(
    'title' => 'Database administration',
    'description' => 'Configure the database administration module.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_admin_settings',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.admin.inc',
  );
  $items['admin/structure/dba'] = array(
    'title' => 'Database administration',
    'description' => "View and edit your site's database directly.",
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_table_overview',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.admin.inc',
  );
  $items['admin/structure/dba/view'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_view_tables',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.admin.inc',
  );
  $items['admin/structure/dba/export'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_export_tables',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.admin.inc',
  );
  $items['admin/structure/dba/empty'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_empty_tables',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.admin.inc',
  );
  $items['admin/structure/dba/describe'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_describe_tables',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.admin.inc',
  );
  $items['admin/reports/databasereport'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => t('View database report'),
    'description' => t('View reports about your database, helpful when tuning for better performance'),
    'page callback' => 'dba_report_page',
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.report.inc',
  );
  $items['admin/reports/databasestats'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => t('View database statistics report'),
    'description' => t('Generate database statistics by comparing two snapshots of global counters'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'dba_statpack_page',
    ),
    'access arguments' => array(
      'administer database',
    ),
    'file' => 'dba.statpack.inc',
  );
  return $items;
}

/**
 * Helper function to invoke driver specific functionality.
 */
function dba_invoke_driver_specific($function, $arg, $file = '') {
  static $drivers;
  $driver = db_driver();
  if (!isset($drivers[$driver][$file])) {
    $drivers[$driver][$file] = TRUE;
    if (!empty($file)) {
      $filename = "{$driver}.{$file}.inc";
    }
    else {
      $filename = "{$driver}.inc";
    }
    $driver_inc = DRUPAL_ROOT . '/' . drupal_get_path('module', 'dba') . "/database/{$filename}";
    if (file_exists($driver_inc)) {
      require_once $driver_inc;
    }
    else {
      drupal_set_message(t('Incomplete implementation for %driver database driver, %function is not defined in %file.', array(
        '%driver' => $driver,
        '%function' => $function . '()',
        '%file' => "dba/database/{$driver}.inc",
      )), 'error');
      $drivers[$driver] = FALSE;
    }
  }
  if (!empty($file)) {
    $function = "dba_{$driver}_{$file}_{$function}";
  }
  else {
    $function = "dba_{$driver}_{$function}";
  }
  if (function_exists($function)) {
    return $function($arg);
  }
  else {
    drupal_set_message(t('Incomplete implementation for %driver database driver, %function is not defined in %file.', array(
      '%driver' => $driver,
      '%function' => $function . '()',
      '%file' => "dba/database/{$driver}.inc",
    )), 'error');
  }
}

Functions

Namesort descending Description
dba_help Implements hook_help().
dba_invoke_driver_specific Helper function to invoke driver specific functionality.
dba_menu Implements hook_menu().
dba_permission Implements hook_permission().