summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/dblog/dblog.admin.inc32
-rw-r--r--modules/dblog/dblog.test32
2 files changed, 64 insertions, 0 deletions
diff --git a/modules/dblog/dblog.admin.inc b/modules/dblog/dblog.admin.inc
index a3ea500fc..0f575b305 100644
--- a/modules/dblog/dblog.admin.inc
+++ b/modules/dblog/dblog.admin.inc
@@ -52,6 +52,7 @@ function dblog_overview() {
);
$output = drupal_get_form('dblog_filter_form');
+ $output .= drupal_get_form('dblog_clear_log_form');
$header = array(
' ',
@@ -328,3 +329,34 @@ function dblog_filter_form_submit($form, &$form_state) {
}
return 'admin/reports/dblog';
}
+
+/**
+ * Return form for dblog clear button.
+ *
+ * @ingroup forms
+ * @see dblog_clear_log_submit()
+ */
+function dblog_clear_log_form() {
+ $form['dblog_clear'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Clear log messages'),
+ '#description' => t('This will permanently remove the log messages from the database.'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['dblog_clear']['clear'] = array(
+ '#type' => 'submit',
+ '#value' => t('Clear log messages'),
+ '#submit' => array('dblog_clear_log_submit'),
+ );
+
+ return $form;
+}
+
+/**
+ * Submit callback: clear database with log messages.
+ */
+function dblog_clear_log_submit(&$form_state, $form) {
+ db_delete('watchdog')->execute();
+ drupal_set_message(t('Database log cleared.'));
+}
diff --git a/modules/dblog/dblog.test b/modules/dblog/dblog.test
index 49e5138f7..902417387 100644
--- a/modules/dblog/dblog.test
+++ b/modules/dblog/dblog.test
@@ -354,4 +354,36 @@ class DBLogTestCase extends DrupalWebTestCase {
}
return $content;
}
+
+ /**
+ * Login an admin user, create dblog event, and test clearing dblog functionality through the admin interface.
+ */
+ protected function testDBLogAddAndClear() {
+ global $base_root;
+ // Get a count of how many watchdog entries there are.
+ $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
+ $log = array(
+ 'type' => 'custom',
+ 'message' => 'Log entry added to test the doClearTest clear down.',
+ 'variables' => array(),
+ 'severity' => WATCHDOG_NOTICE,
+ 'link' => NULL,
+ 'user' => $this->big_user,
+ 'request_uri' => $base_root . request_uri(),
+ 'referer' => $_SERVER['HTTP_REFERER'],
+ 'ip' => ip_address(),
+ 'timestamp' => REQUEST_TIME,
+ );
+ // Add a watchdog entry.
+ dblog_watchdog($log);
+ // Make sure the table count has actually incremented.
+ $this->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), t('dblog_watchdog() added an entry to the dblog %count', array('%count' => $count)));
+ // Login the admin user.
+ $this->drupalLogin($this->big_user);
+ // Now post to clear the db table.
+ $this->drupalPost('admin/reports/dblog', array(), t('Clear log messages'));
+ // Count rows in watchdog that previously related to the deleted user.
+ $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
+ $this->assertEqual($count, 0, t('DBLog contains %count records after a clear.', array('%count' => $count)));
+ }
}