Index: dba.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/dba/dba.module,v retrieving revision 1.54 diff -u -r1.54 dba.module --- dba.module 24 Jun 2007 03:41:12 -0000 1.54 +++ dba.module 29 Jul 2007 09:05:26 -0000 @@ -335,17 +335,24 @@ } } -function dba_auto_backup() { - $path = variable_get('dba_auto_backup_path', file_directory_temp()); - // See what tables (if any) the admin wants us to only backup - // the schema, not the actual data. we need it as an array, so we - // lookup the setting as a string, then split() it into an array. - $exclude_tables_str = variable_get('dba_auto_backup_exclude_tables', DBA_BACKUP_EXCLUDE); - $exclude_tables = split('[ ,]', $exclude_tables_str); +function dba_auto_backup($args = array()) { + // Merge in configured defaults. + $defaults = array( + 'path' => variable_get('dba_auto_backup_path', file_directory_temp()), + 'filename' => format_date(time(), 'custom', 'Y-md-Hi_') . variable_get('dba_default_filename', 'backup.sql'), + // See what tables (if any) the admin wants us to only backup + // the schema, not the actual data. We need it as an array, so we + // lookup the setting as a string, then split() it into an array. + 'exclude' => split('[ ,]', variable_get('dba_auto_backup_exclude_tables', DBA_BACKUP_EXCLUDE)), + 'compress' => (variable_get('dba_auto_backup_bzip2', 0) ? 'bzip2' : (variable_get('dba_auto_backup_gzip', 0) ? 'gzip' : FALSE)), + 'mail' => variable_get('dba_auto_backup_mail', 0) + ); + $args = array_merge($defaults, $args); + // Make sure we have permission to save our backup file. - if (file_check_directory($path, FILE_CREATE_DIRECTORY)) { + if (file_check_directory($args['path'], FILE_CREATE_DIRECTORY)) { $database = dba_get_database(); - $filename = format_date(time(), 'custom', 'Y-md-Hi_') . variable_get('dba_default_filename', 'backup.sql'); + $filename = $args['filename']; $backup = "-- Drupal dba.module database dump\n"; $backup .= "--\n"; @@ -354,34 +361,30 @@ $tables = dba_get_tables(); foreach ($tables as $table) { - $backup .= dba_backup_table($table, TRUE, FALSE, in_array($table, $exclude_tables) ? FALSE : TRUE); + $backup .= dba_backup_table($table, TRUE, FALSE, in_array($table, $args['exclude']) ? FALSE : TRUE); } - // Optionally bzip2 compress auto-backup file. - if (variable_get('dba_auto_backup_bzip2', 0)) { - $backup = bzcompress($backup, 9); - $filename = $filename .'.bz2'; - } - // Otherwise, optionally gzip compress auto-backup file. - else if (variable_get('dba_auto_backup_gzip', 0)) { - if (version_compare(phpversion(), '4.2', '>=')) { + // Optionally compress auto-backup file. + switch ($args['compress']) { + case 'bzip2': + $backup = bzcompress($backup, 9); + $filename .= '.bz2'; + break; + case 'gzip': $backup = gzencode($backup, 9, FORCE_GZIP); - } - else { - $backup = gzencode($backup, FORCE_GZIP); - } - $filename = $filename .'.gz'; + $filename .= '.gz'; + break; } - if ($fp = fopen($path ."/$filename", 'wb')) { + if ($fp = fopen($args['path'] ."/$filename", 'wb')) { fwrite($fp, $backup); fclose($fp); variable_set('dba_auto_backup_last', time()); // If enabled, email a copy of the backup to the site administrator. - if (variable_get('dba_auto_backup_mail', 0)) { + if ($args['mail']) { $attachment = new stdClass(); - $attachment->path = $path ."/$filename"; + $attachment->path = $args['path'] ."/$filename"; $attachment->filename = $filename; dba_mail_backup($attachment); } @@ -1465,9 +1468,11 @@ /** * Drop table and all contents from current database. */ -function dba_drop_table($table) { +function dba_drop_table($table, $verbose = TRUE) { $query = "DROP TABLE $table;"; - drupal_set_message(check_plain($query)); + if ($verbose) { + drupal_set_message(check_plain($query)); + } return db_query($query); }