You are here

function dba_menu in Database Administration 5

Same name and namespace in other branches
  1. 7 dba.module \dba_menu()

File

./dba.module, line 29
Allows administrators direct access to their Drupal database. Written by Jeremy Andrews <jeremy@kerneltrap.org>, June 2004. PostgreSQL functionality provided by AAM <aam@ugpl.de> Major security audit, porting, and maintenance by Derek…

Code

function dba_menu($may_cache) {
  $items = array();
  $admin_access = user_access('dba administer database');
  $access = user_access('dba view database') || $admin_access;
  if ($may_cache) {

    // Provide menus to dbas with view permissions.
    $items[] = array(
      'path' => 'admin/build/database',
      'title' => t('Database'),
      'description' => t("View and edit your site's database directly."),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'dba_database_overview_form',
      'access' => $access,
    );

    // Tabs.
    $items[] = array(
      'path' => 'admin/build/database/table',
      'title' => t('Tables'),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'dba_database_overview_form',
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/database/query',
      'title' => t('Query database'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'dba_query_form',
      ),
      'access' => $admin_access,
      'type' => MENU_LOCAL_TASK,
      'weight' => 8,
    );
    $items[] = array(
      'path' => 'admin/build/database/script',
      'title' => t('Run script'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'dba_run_script',
      ),
      'access' => $admin_access,
      'type' => MENU_LOCAL_TASK,
      'weight' => 10,
    );
    $items[] = array(
      'path' => 'admin/settings/dba',
      'title' => t('Database administration'),
      'description' => t('Control automatic backups and other settings.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'dba_settings_form',
      ),
      'access' => $admin_access,
    );
  }
  elseif (strstr(drupal_get_path_alias($_GET['q']), 'admin/build/database')) {
    $tables = dba_get_active_tables(0);
    if (!empty($tables) && count($tables) == 1) {

      // You can only view or describe one table at a time.
      $table = reset($tables);

      // Regular subtabs.
      $items[] = array(
        'path' => "admin/build/database/table/{$table}/view",
        'title' => t('View'),
        'callback' => 'dba_admin_tables_view',
        'access' => $access,
        'type' => MENU_LOCAL_TASK,
        'weight' => 0,
      );
      $items[] = array(
        'path' => "admin/build/database/table/{$table}/describe",
        'title' => t('Describe'),
        'callback' => 'dba_admin_tables_describe',
        'access' => $access,
        'type' => MENU_LOCAL_TASK,
        'weight' => 2,
      );
      if (_is_mysql()) {
        $items[] = array(
          'path' => "admin/build/database/table/{$table}/check",
          'title' => t('Check'),
          'callback' => 'dba_admin_tables_check',
          'access' => $access,
          'type' => MENU_LOCAL_TASK,
          'weight' => 4,
        );
        $items[] = array(
          'path' => "admin/build/database/table/{$table}/optimize",
          'title' => t('Optimize'),
          'callback' => 'dba_admin_tables_optimize',
          'access' => $access,
          'type' => MENU_LOCAL_TASK,
          'weight' => 4,
        );
      }

      // Subtabs for dbas with administer permissions.
      $items[] = array(
        'path' => "admin/build/database/table/{$table}/backup",
        'title' => t('Backup'),
        'callback' => 'dba_admin_tables_verify_op',
        'callback arguments' => array(
          'backup',
        ),
        'access' => $admin_access,
        'type' => MENU_LOCAL_TASK,
        'weight' => 8,
      );
      $items[] = array(
        'path' => "admin/build/database/table/{$table}/empty",
        'title' => t('Empty'),
        'callback' => 'dba_admin_tables_verify_op',
        'callback arguments' => array(
          'empty',
        ),
        'access' => $admin_access,
        'type' => MENU_LOCAL_TASK,
        'weight' => 8,
      );
      $items[] = array(
        'path' => "admin/build/database/table/{$table}/drop",
        'title' => t('Drop'),
        'callback' => 'dba_admin_tables_verify_op',
        'callback arguments' => array(
          'drop',
        ),
        'access' => $admin_access,
        'type' => MENU_LOCAL_TASK,
        'weight' => 10,
      );
    }

    // Administrative callbacks.
    $items[] = array(
      'path' => "admin/build/database/backup",
      'title' => t('Backup'),
      'callback' => 'dba_admin_tables_verify_op',
      'callback arguments' => array(
        'backup',
      ),
      'access' => $admin_access,
      'weight' => 15,
      'type' => arg(3) == 'backup' ? MENU_LOCAL_TASK : MENU_CALLBACK,
    );
    $items[] = array(
      'path' => "admin/build/database/empty",
      'title' => t('Empty'),
      'callback' => 'dba_admin_tables_verify_op',
      'callback arguments' => array(
        'empty',
      ),
      'access' => $admin_access,
      'weight' => 15,
      'type' => arg(3) == 'empty' ? MENU_LOCAL_TASK : MENU_CALLBACK,
    );
    $items[] = array(
      'path' => "admin/build/database/drop",
      'title' => t('Drop'),
      'callback' => 'dba_admin_tables_verify_op',
      'callback arguments' => array(
        'drop',
      ),
      'access' => $admin_access,
      'weight' => 15,
      'type' => arg(3) == 'drop' ? MENU_LOCAL_TASK : MENU_CALLBACK,
    );
    if (_is_mysql()) {
      $items[] = array(
        'path' => "admin/build/database/check",
        'title' => t('Check'),
        'callback' => 'dba_admin_tables_check',
        'access' => $admin_access,
        'weight' => 15,
        'type' => arg(3) == 'check' ? MENU_LOCAL_TASK : MENU_CALLBACK,
      );
      $items[] = array(
        'path' => "admin/build/database/optimize",
        'title' => t('Optimize'),
        'callback' => 'dba_admin_tables_optimize',
        'access' => $admin_access,
        'weight' => 15,
        'type' => arg(3) == 'optimize' ? MENU_LOCAL_TASK : MENU_CALLBACK,
      );
    }
  }
  return $items;
}