You are here

function dba_settings_form in Database Administration 5

1 string reference to 'dba_settings_form'
dba_menu in ./dba.module

File

./dba.module, line 198
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_settings_form() {
  if (!user_access('dba administer database')) {
    drupal_access_denied();
    module_invoke_all('exit');
    exit;
  }

  // Backups
  $form['backup'] = array(
    '#type' => 'fieldset',
    '#title' => t('Database backups'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['backup']['dba_default_filename'] = array(
    '#type' => 'textfield',
    '#title' => t('Default backup filename'),
    '#description' => t('Default filename to use when backing up multiple tables. If backing up only one table, the filename will default to the name of the table. You will have an opportunity to modify this filename when you actually perform the backup. If automatically backing up tables, the name will be prepended with the current date and time.'),
    '#default_value' => variable_get('dba_default_filename', 'backup.sql'),
    '#size' => 30,
    '#maxlength' => 64,
  );
  $period = drupal_map_assoc(array(
    0,
    21600,
    32400,
    43200,
    86400,
    172800,
    259200,
    604800,
    1209600,
    2419200,
    4838400,
    9676800,
  ), 'format_interval');
  $period[0] = t('disabled');
  $form['backup']['dba_auto_backup_interval'] = array(
    '#type' => 'select',
    '#title' => t('Automatically backup database every'),
    '#default_value' => variable_get('dba_auto_backup_interval', 0),
    '#options' => $period,
    '#description' => t('Select how often you wish to have your database automatically backed up. Requires crontab.'),
  );
  $backup_interval = variable_get('dba_auto_backup_interval', 0);
  $backup_path = variable_get('dba_auto_backup_path', file_directory_temp());
  $backup_exclude = variable_get('dba_auto_backup_exclude_tables', DBA_BACKUP_EXCLUDE);
  if ($backup_interval) {
    $attributes = array(
      'enabled' => 'enabled',
    );
  }
  else {
    $attributes = array(
      'disabled' => 'disabled',
    );
  }
  $form['backup']['dba_auto_backup_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Automatic backup path'),
    '#default_value' => $backup_path,
    '#size' => 30,
    '#maxlength' => 255,
    '#description' => t('If automatic backups are enabled, you must specify a directory where you would like to store the backup files.  The path must be absolute and for security reasons should not be accesible to the web.'),
    '#attributes' => $attributes,
  );
  if (function_exists('bzcompress')) {
    $form['backup']['dba_auto_backup_bzip2'] = array(
      '#type' => 'checkbox',
      '#title' => t('Compress automatic backups'),
      '#return_value' => 1,
      '#default_value' => variable_get('dba_auto_backup_bzip2', 0),
      '#description' => t('Enable this option to compress automatic backups with <a href="http://sources.redhat.com/bzip2/">bzip2</a>.'),
      '#attributes' => $attributes,
    );
  }
  else {
    if (function_exists('gzencode')) {
      $form['backup']['dba_auto_backup_gzip'] = array(
        '#type' => 'checkbox',
        '#title' => t('Compress automatic backups'),
        '#return_value' => 1,
        '#default_value' => variable_get('dba_auto_backup_gzip', 0),
        '#description' => t('Enable this option to compress automatic backups with <a href="http://www.gzip.org/zlib/">zlib</a>.'),
        '#attributes' => $attributes,
      );
    }
  }
  $form['backup']['dba_auto_backup_mail'] = array(
    '#type' => 'checkbox',
    '#title' => t('Mail backup to administrator'),
    '#return_value' => 1,
    '#default_value' => variable_get('dba_auto_backup_mail', 0),
    '#description' => t("Enable this option to have a copy of the database backup files mailed to your administrator's email address."),
    '#attributes' => $attributes,
  );
  $form['backup']['dba_auto_backup_exclude_tables'] = array(
    '#type' => 'textfield',
    '#title' => t('Automatic backup excluded tables'),
    '#default_value' => $backup_exclude,
    '#description' => t("If automatic backups are enabled, you can specify a space-separated list of table names where you only want the table definition (schema) backed up, but not the actual data.  This is useful for tables that can be rebuilt (such as the tables related to search indexing) or the watchdog table, which holds log events but no actual site content.  Only saving the schema and not the data for these tables can greatly reduce the size of the backups, without losing real content."),
    '#attributes' => $attributes,
  );

  // MySQL
  if (_is_mysql()) {
    $form['mysql_options'] = array(
      '#type' => 'fieldset',
      '#title' => t('MySQL options'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['mysql_options']['dba_default_check_type'] = array(
      '#type' => 'radios',
      '#title' => t('Default check type'),
      '#description' => t('MySQL databases support many types of database integrity checks. Select your preferred default type from the list above. Medium is the MySQL recommended default type.'),
      '#default_value' => variable_get('dba_default_check_type', 'MEDIUM'),
      '#options' => array(
        'QUICK' => t('Quick'),
        'FAST' => t('Fast'),
        'CHANGED' => t('Changed'),
        'MEDIUM' => t('Medium'),
        'EXTENDED' => t('Extended'),
      ),
    );
    $form['mysql_options']['dba_repair'] = array(
      '#type' => 'radios',
      '#title' => t('Repair option'),
      '#description' => t('By default, the dba module will only display a repair button if a table has been determined to need a repair. Alternatively, you can make the module always display a repair button, or never display a repair button.'),
      '#default_value' => variable_get('dba_repair', 0),
      '#options' => array(
        '0' => t('Automatic'),
        '1' => t('Always'),
        '2' => t('Never'),
      ),
    );
  }

  // Add a validation callback to make sure the backup path is writable.
  $setting_valid = array(
    'dba_settings_validate' => array(),
  );
  $form['#validate'] = isset($form['#validate']) ? array_merge($form['#validate'], $setting_valid) : $setting_valid;
  return system_settings_form($form);
}