Index: modules/dba/dba.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/dba/dba.module,v retrieving revision 1.40 diff -u -p -r1.40 dba.module --- modules/dba/dba.module 26 May 2006 05:23:54 -0000 1.40 +++ modules/dba/dba.module 18 Nov 2006 04:28:35 -0000 @@ -93,61 +93,116 @@ function dba_menu($may_cache) { } function dba_settings() { + if ( !user_access('dba administer database') ) { + drupal_access_denied(); + module_invoke_all('exit'); + exit; + } // Backups - $form['backup'] = array('#type' => 'fieldset', '#title' => t('Database backups')); - $form['backup']['dba_default_filename'] = array('#type' => 'textfield', '#title' => t('Default backup filename'), '#default_value' => variable_get('dba_default_filename', 'backup.sql'), '#size' => 45, '#maxlength' => 255, '#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. If manually backing up tables, 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.')); + $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.')); - - // the variable table doesn't get updated until after we already need to - // refer to it, so we pull variables from the $edit array. - $edit = $_POST['edit']; - $backup_interval = isset($edit['dba_auto_backup_interval']) ? - $edit['dba_auto_backup_interval'] : - variable_get('dba_auto_backup_interval', 0); - $backup_path = isset($edit['dba_auto_backup_path']) ? - $edit['dba_auto_backup_path'] : - variable_get('dba_auto_backup_path', file_directory_temp()); - $backup_exclude = isset($edit['dba_auto_backup_exclude_tables']) ? - $edit['dba_auto_backup_exclude_tables'] : - variable_get('dba_auto_backup_exclude_tables', DBA_BACKUP_EXCLUDE); + $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) { - if (!file_check_directory($backup_path)) { - form_set_error('dba_auto_backup_path', t('The automatic backup path does not exist, or is not writeable. Automatic backups will not begin until you fix this error.')); - } - else if ($test = tempnam($backup_path, 'dba.')) { - file_delete($test); - } - else { - form_set_error('dba_auto_backup_path', t('The automatic backup path exists, but is not writeable. Automatic backups will not begin until you fix this error.')); - } $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); + $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 bzip2.'), '#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 zlib.'), '#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); - + $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'] = array('#type' => 'fieldset', '#title' => t('MySQL options')); - $form['mysql']['dba_default_check_type'] = array('#type' => 'radios', '#title' => t('Default check 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')), '#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.')); - $form['mysql']['dba_repair'] = array('#type' => 'radios', '#title' => t('Repair option'), '#default_value' => variable_get('dba_repair', 0), '#options' => array('0' => t('Automatic'), '1' => t('Always'), '2' => t('Never')), '#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.')); + 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' => ('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 $form; } +function dba_settings_validate($form_id, $form_values, $form) { + if (!file_check_directory($form_values['dba_auto_backup_path'])) { + form_set_error('dba_auto_backup_path', t('The automatic backup path does not exist, or is not writeable. Automatic backups will not begin until you fix this error.')); + } + elseif ($test = tempnam($form_values['dba_auto_backup_path'], 'dba.')) { + file_delete($test); + } + else { + form_set_error('dba_auto_backup_path', t('The automatic backup path exists, but is not writeable. Automatic backups will not begin until you fix this error.')); + } +} + function dba_cron() { if ($interval = variable_get('dba_auto_backup_interval', 0)) { // see if it's time for another auto-backup