Index: modules/dba/dba.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/dba/dba.module,v retrieving revision 1.46 diff -u -p -r1.46 dba.module --- modules/dba/dba.module 20 Jan 2007 04:11:50 -0000 1.46 +++ modules/dba/dba.module 9 Mar 2007 02:43:54 -0000 @@ -18,14 +18,8 @@ function dba_perm() { function dba_help($section = '') { switch ($section) { - case 'admin/modules/dba': - case 'admin/modules#description': - $output = t('Directly administer your Drupal database.'); - break; case 'admin/help#dba': - $output .= 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.
-'); + $output .= 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.'); break; } return $output; @@ -36,20 +30,28 @@ function dba_menu($may_cache) { $access = user_access('dba view database') || user_access('dba administer database'); if ($may_cache) { // provide menus to dbas with view permissions - $items[] = array('path' => 'admin/database', 'title' => t('database'), + $items[] = array('path' => 'admin/database', 'title' => t('Database'), 'callback' => 'dba_admin_overview', 'access' => $access); // tabs - $items[] = array('path' => 'admin/database/table', 'title' => t('tables'), + $items[] = array('path' => 'admin/database/table', 'title' => t('Tables'), 'callback' => 'dba_admin_overview', 'type' => MENU_DEFAULT_LOCAL_TASK); $items[] = array('path' => 'admin/database/query', - 'title' => t('query'), 'callback' => 'dba_query', + 'title' => t('Query'), 'callback' => 'dba_query', 'access' => user_access('dba administer database'), 'type' => MENU_LOCAL_TASK, 'weight' => 8); $items[] = array('path' => 'admin/database/script', - 'title' => t('run script'), 'callback' => 'dba_run_script', + 'title' => t('Run script'), 'callback' => 'dba_run_script', 'access' => user_access('dba administer database'), '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' => user_access('dba administer database'), + ); } else if (strstr(drupal_get_path_alias($_GET['q']), 'admin/database')) { // you can only view or describe one table at a time @@ -57,53 +59,53 @@ function dba_menu($may_cache) { if (!empty($tables)) { // regular subtabs $items[] = array('path' => "admin/database/table/$tables/view", - 'title' => t('view'), 'callback' => 'dba_admin_tables_view', + 'title' => t('View'), 'callback' => 'dba_admin_tables_view', 'access' => $access, 'type' => MENU_LOCAL_TASK, 'weight' => 0); $items[] = array('path' => "admin/database/table/$tables/describe", - 'title' => t('describe'), 'callback' => 'dba_admin_tables_describe', + 'title' => t('Describe'), 'callback' => 'dba_admin_tables_describe', 'access' => $access, 'type' => MENU_LOCAL_TASK, 'weight' => 2); if (_is_mysql()) { $items[] = array('path' => "admin/database/table/$tables/check", - 'title' => t('check'), 'callback' => 'dba_admin_tables_check', + 'title' => t('Check'), 'callback' => 'dba_admin_tables_check', 'access' => $access, 'type' => MENU_LOCAL_TASK, 'weight' => 4); $items[] = array('path' => "admin/database/table/$tables/optimize", - 'title' => t('optimize'), 'callback' => 'dba_admin_tables_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/database/table/$tables/backup", - 'title' => t('backup'), 'callback' => 'dba_admin_tables_backup', + 'title' => t('Backup'), 'callback' => 'dba_admin_tables_backup', 'access' => user_access('dba administer database'), 'type' => MENU_LOCAL_TASK, 'weight' => 8); $items[] = array('path' => "admin/database/table/$tables/empty", - 'title' => t('empty'), 'callback' => 'dba_admin_tables_empty', + 'title' => t('Empty'), 'callback' => 'dba_admin_tables_empty', 'access' => user_access('dba administer database'), 'type' => MENU_LOCAL_TASK, 'weight' => 8); $items[] = array('path' => "admin/database/table/$tables/drop", - 'title' => t('drop'), 'callback' => 'dba_admin_tables_drop', + 'title' => t('Drop'), 'callback' => 'dba_admin_tables_drop', 'access' => user_access('dba administer database'), 'type' => MENU_LOCAL_TASK, 'weight' => 10); } // administrative callbacks $items[] = array('path' => "admin/database/backup", - 'title' => t('backup'), 'callback' => 'dba_admin_tables_backup', + 'title' => t('Backup'), 'callback' => 'dba_admin_tables_backup', 'access' => user_access('dba administer database'), 'weight' => 15, 'type' => arg(2) == 'backup' ? MENU_LOCAL_TASK : MENU_CALLBACK); $items[] = array('path' => "admin/database/drop", - 'title' => t('drop'), 'callback' => 'dba_admin_tables_drop', + 'title' => t('Drop'), 'callback' => 'dba_admin_tables_drop', 'access' => user_access('dba administer database'), 'weight' => 15, 'type' => arg(2) == 'drop' ? MENU_LOCAL_TASK : MENU_CALLBACK); $items[] = array('path' => "admin/database/empty", - 'title' => t('empty'), 'callback' => 'dba_admin_tables_empty', + 'title' => t('Empty'), 'callback' => 'dba_admin_tables_empty', 'access' => user_access('dba administer database'), 'weight' => 15, 'type' => arg(2) == 'empty' ? MENU_LOCAL_TASK : MENU_CALLBACK); if (_is_mysql()) { $items[] = array('path' => "admin/database/check", - 'title' => t('check'), 'callback' => 'dba_admin_tables_check', + 'title' => t('Check'), 'callback' => 'dba_admin_tables_check', 'access' => user_access('dba administer database'), 'weight' => 15, 'type' => arg(2) == 'check' ? MENU_LOCAL_TASK : MENU_CALLBACK); $items[] = array('path' => "admin/database/optimize", - 'title' => t('optimize'), 'callback' => 'dba_admin_tables_optimize', + 'title' => t('Optimize'), 'callback' => 'dba_admin_tables_optimize', 'access' => user_access('dba administer database'), 'weight' => 15, 'type' => arg(2) == 'optimize' ? MENU_LOCAL_TASK : MENU_CALLBACK); } @@ -111,7 +113,7 @@ function dba_menu($may_cache) { return $items; } -function dba_settings() { +function dba_settings_form() { if ( !user_access('dba administer database') ) { drupal_access_denied(); module_invoke_all('exit'); @@ -207,7 +209,8 @@ function dba_settings() { // 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; + + return system_settings_form($form); } function dba_settings_validate($form_id, $form_values, $form) { @@ -373,7 +376,7 @@ function dba_admin_tables_verify_op($op) $tables = dba_get_active_tables($edit, 0); unset($_SESSION['dba_tables']); if (empty($tables)) { - drupal_set_message(t('You must select the tables to %op.', array('%op' => _dba_ops($op))), 'error'); + drupal_set_message(t('You must select the tables to !op.', array('!op' => _dba_ops($op))), 'error'); drupal_goto('admin/database'); } $edit['tables'] = $tables; @@ -384,27 +387,27 @@ function dba_admin_tables_verify_op($op) // dba module specific functions function dba_admin_overview() { - return dba_database_overview_form(); + return drupal_get_form('dba_database_overview_form'); } function theme_dba_database_overview_form($form) { $output = ''; $rows = array(); $database = dba_get_database(); - drupal_set_title(t('View database %database', array('%database' => theme('placeholder', $database)))); + drupal_set_title(t('View database %database', array('%database' => $database))); // it'd be great to use the pager and tablesort, but doesn't appear possible - $header = array('', t('tables'), t('rows')); + $header = array('', t('Tables'), t('Rows')); $tables = dba_get_tables(); foreach ($tables as $table) { $count = dba_get_row_count($table); - $checkbox = form_render($form[$table]); + $checkbox = drupal_render($form[$table]); $rows[] = array($checkbox, l($table, "admin/database/table/$table/view"), $count); } $output .= dba_select_all_js(); $output .= theme('table', $header, $rows); $output .= dba_select_all_js(); - $output .= form_render($form); + $output .= drupal_render($form); drupal_set_html_head(checkoff_head()); return $output; } @@ -427,14 +430,14 @@ function dba_database_overview_form() { $form['empty'] = array('#type' => 'submit', '#value' => t('Empty')); $form['drop'] = array('#type' => 'submit', '#value' => t('Drop')); } - return drupal_get_form('dba_database_overview_form', $form); + return $form; } function dba_database_overview_form_submit($form_id, $form_values) { $op = isset($_POST['op']) ? $_POST['op'] : ''; $tables = dba_get_active_tables($form_values, 0); if (empty($tables)) { - drupal_set_message(t('You must select the table(s) to %op.', array('%op' => $op)), 'error'); + drupal_set_message(t('You must select the table(s) to !op.', array('!op' => $op)), 'error'); return; } $_SESSION['dba_tables'] = $tables; @@ -470,7 +473,6 @@ function dba_select_all_js() { function dba_delete_row($table, $key, $keyid) { $rows = array(); $keyid = str_replace('__2F_', '/', $keyid); - $display = theme('placeholder', $table); $result = db_query("SELECT * FROM %s WHERE %s = '%s'", $table, $key, $keyid); $row = db_fetch_array($result); $rows[] = (array)($row); @@ -480,9 +482,9 @@ function dba_delete_row($table, $key, $k $form['key'] = array('#type' => 'hidden', '#value' => $key); $form['keyid'] = array('#type' => 'hidden', '#value' => $keyid); $output .= confirm_form('dba_delete_row_form', $form, - t('Are you sure you want to delete this row from the "%table" table?', array('%table' => $display)), + t('Are you sure you want to delete this row from the "%table" table?', array('%table' => $table)), "admin/database/table/$table/view", - t('By clicking "Delete row" you will permanently remove this row from the %table table. This action cannot be undone.', array('%table' => $display)), + t('By clicking "Delete row" you will permanently remove this row from the %table table. This action cannot be undone.', array('%table' => $table)), t('Delete row'), t('Cancel')); return $output; @@ -491,7 +493,6 @@ function dba_delete_row($table, $key, $k function dba_edit_row($table, $key, $keyid) { $rows = array(); $keyid = str_replace('__2F_', '/', $keyid); - $display = theme('placeholder', $table); $result = db_query("SELECT * FROM %s WHERE %s = '%s'", $table, $key, $keyid); $row = db_fetch_array($result); $header = array_keys($row); @@ -525,9 +526,9 @@ function dba_edit_row($table, $key, $key $form['key'] = array('#type' => 'hidden', '#value' => $key); $form['keyid'] = array('#type' => 'hidden', '#value' => $keyid); $output .= confirm_form('dba_edit_row_form', $form, - t('Edit row from the "%table" table', array('%table' => $display)), + t('Edit row from the "%table" table', array('%table' => $table)), "admin/database/table/$table/view", - t('By clicking "Edit row" you will save any changes you make to this row of the %table table. This action cannot be undone.', array('%table' => $display)), + t('By clicking "Edit row" you will save any changes you make to this row of the %table table. This action cannot be undone.', array('%table' => $table)), t('Edit row'), t('Cancel')); return $output; @@ -544,12 +545,12 @@ function theme_dba_edit_row_form($form) $row[] = $keyid; } else { - $row[] = form_render($form[$name]); + $row[] = drupal_render($form[$name]); } } $rows[] = $row; $output = theme('table', $header, $rows); - $output .= form_render($form); + $output .= drupal_render($form); return $output; } @@ -598,7 +599,7 @@ function dba_table_overview($table) { $tables = dba_get_active_tables($edit); $quantity = sizeof(explode(',', $tables)); if ($quantity == 1) { - drupal_set_title(t('View table \'%table\'', array('%table' => "$table"))); + drupal_set_title(t('View table %table', array('%table' => $table))); if (user_access('dba administer database')) { $primary = dba_get_primary_key($table); @@ -678,7 +679,7 @@ function dba_table_describe($table) { $tables = dba_get_active_tables($edit); $quantity = sizeof(explode(',', $tables)); if ($quantity == 1) { - drupal_set_title(t('Describe table \'%table\'', array('%table' => "$table"))); + drupal_set_title(t('Describe table %table', array('%table' => $table))); $result = dba_describe_table($table); while ($row = db_fetch_array($result)) { if (!$header) { @@ -788,15 +789,15 @@ function dba_run_script() { } } fclose ($fp); - drupal_set_message(t('Succesfully ran %query from script "%filename".', array('%query' => format_plural($count, '1 query', '%count queries'), '%filename' => $file->filename))); + drupal_set_message(t('Succesfully ran !query from script %filename.', array('!query' => format_plural($count, '1 query', '@count queries'), '%filename' => $file->filename))); } else { - drupal_set_message(t('Unable to open script "%filename".', array('%filename' => $file->filename)), 'error'); + drupal_set_message(t('Unable to open script %filename.', array('%filename' => $file->filename)), 'error'); } file_delete($file->filepath); } else { - drupal_set_message(t('Script "%filename" does not exist.', array('%filename' => $file->filename)), 'error'); + drupal_set_message(t('Script %filename does not exist.', array('%filename' => $file->filename)), 'error'); } // cleanup session unset($_SESSION['file_uploads'][$file->source]); @@ -979,35 +980,35 @@ function dba_verify($edit, $action) { $form = array(); $table_list = theme('placeholder', str_replace(',', ', ', $tables)); $table_id = format_plural($quantity, t('table'), t('tables')); - $substitutions = array('%tables' => $table_list, '%table' => $table_id, '%this' => format_plural($quantity, t('this'), t('these')), '%itself' => format_plural($quantity, t('itself'), t('themselves')), '%its' => format_plural($quantity, t('its'), t('their'))); + $substitutions = array('!tables' => $table_list, '!table' => $table_id, '!this' => format_plural($quantity, t('this'), t('these')), '!itself' => format_plural($quantity, t('itself'), t('themselves')), '!its' => format_plural($quantity, t('its'), t('their'))); $form['tables'] = array('#type' => 'hidden', '#value' => $tables); switch ($action) { case 'backup': $filename = ($quantity == 1 ? $tables .'.sql' : variable_get('dba_default_filename', 'backup.sql')); - $form['file_name'] = array('#type' => 'textfield', '#title' => t('Backup filename'), '#default_value' => $filename, '#size' => 40, '#maxlength' => 255, '#description' => t("Please specify the filename you wish to give your database backup. Once you click 'Backup %table' below your web browser will allow you to save the database backup to your local computer.", array('%table' => format_plural($quantity, 'table', 'tables')))); + $form['file_name'] = array('#type' => 'textfield', '#title' => t('Backup filename'), '#default_value' => $filename, '#size' => 40, '#maxlength' => 255, '#description' => t("Please specify the filename you wish to give your database backup. Once you click 'Backup !table' below your web browser will allow you to save the database backup to your local computer.", array('!table' => format_plural($quantity, 'table', 'tables')))); $form['add_drop_table'] = array('#type' => 'checkbox', '#title' => t('Add DROP TABLE'), '#default_value' => 0, '#description' => t('Check this box if you wish to add DROP TABLE IF EXISTS before each table schema. This will allow you to quickly restore from a backup without having to manually drop all tables first.')); $output = confirm_form('dba_verify_backup_form', $form, - t('Backup %table to local computer?', array('%table' => $table_id)), + t('Backup !table to local computer?', array('!table' => $table_id)), 'admin/database', - t('By clicking "Backup %table" you will be prompted to save the following %table to your local computer: %tables', array('%tables' => $display, '%table' => $table_id)), - t('Backup %table', array('%table' => $table_id)), + t('By clicking "Backup !table" you will be prompted to save the following !table to your local computer: !tables', array('!tables' => $display, '!table' => $table_id)), + t('Backup !table', array('!table' => $table_id)), t('Cancel')); break; case 'empty': $output = confirm_form('dba_verify_empty_form', $form, - t('Are you sure you want to delete all rows from the "%tables" %table?', $substitutions), + t('Are you sure you want to delete all rows from the "!tables" !table?', $substitutions), 'admin/database', - t('By clicking "Empty %table" you will completely remove all data from %this %table, though the %table %itself will not be dropped. This action cannot be undone.', $substitutions), - t('Empty %table', array('%table' => $table_id)), + t('By clicking "Empty !table" you will completely remove all data from !this !table, though the !table !itself will not be dropped. This action cannot be undone.', $substitutions), + t('Empty !table', array('!table' => $table_id)), t('Cancel')); break; case 'drop': $output = confirm_form('dba_verify_drop_form', $form, - t('Are you sure you want to drop the "%tables" %table?', $substitutions), + t('Are you sure you want to drop the "!tables" !table?', $substitutions), 'admin/database', - t('By clicking "Drop %table" you will be completely removing %this %table and all %its data from the database. This action cannot be undone.', $substitutions), - t('Drop %table', array('%table' => $table_id)), + t('By clicking "Drop !table" you will be completely removing !this !table and all !its data from the database. This action cannot be undone.', $substitutions), + t('Drop !table', array('!table' => $table_id)), t('Cancel')); break; } @@ -1036,7 +1037,7 @@ function dba_verify_backup_form_submit($ } $quantity = sizeof($tables); $display = implode(', ', $tables); - drupal_set_message(t("Saved %tables to %filename.", array('%filename' => theme('placeholder', $file_name), '%tables' => theme('placeholder', $display)))); + drupal_set_message(t("Saved %tables to %filename.", array('%filename' => $file_name, '%tables' => $display))); exit(0); } } @@ -1351,7 +1352,7 @@ class mime_mail { $mail->headers = 'Errors-To: [EMAIL='. $mail->from. ']'. $mail->from. '[/EMAIL]'; $admin = user_load(array('uid' => 1)); $mail->to = $admin->mail; - $mail->subject = t('Database backup from %site: %file', array('%site' => variable_get('site_name', 'drupal'), '%file' => $attachment->filename)); + $mail->subject = t('Database backup from !site: !file', array('!site' => variable_get('site_name', 'drupal'), '!file' => $attachment->filename)); $mail->body = t('Database backup attached'); $mail->add_attachment("$attach", $attachment->filename, "Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAgEASABIAAD/7QT+UGhvdG9zaG"); Index: modules/dba/dba.info =================================================================== RCS file: modules/dba/dba.info diff -N modules/dba/dba.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/dba/dba.info 9 Mar 2007 02:43:54 -0000 @@ -0,0 +1,4 @@ +; $Id$ +name = Database Administration +description = "Directly administer your Drupal database." +version = "$Name$"