You are here

log_clear.module in Util 6.3

Same filename and directory in other branches
  1. 6.2 contribs/log_clear/log_clear.module

Adds a clearing function to "Recent log" report. Requires 'access site reports' permission.

File

contribs/log_clear/log_clear.module
View source
<?php

/**
 * @file
 * Adds a clearing function to "Recent log" report.
 * Requires 'access site reports' permission.
 */

/**
 * Implementation of hook_help().
 */
function log_clear_help($path, $args) {
  switch ($path) {
    case 'admin/reports/dblog':
      return '<p>' . t('Within the "Filter log messages" field set there is a button that you may use to clear selected entries.') . '</p>';
  }
}

/**
 * Implementation of hook_form_alter().
 */
function log_clear_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'dblog_filter_form':
      drupal_add_css(drupal_get_path('module', 'log_clear') . '/log_clear.css');
      $form['filters']['buttons']['clear'] = array(
        '#type' => 'submit',
        '#value' => t('Clear'),
        '#submit' => array(
          'log_clear_submit',
        ),
      );
      break;
  }
}

/**
 * Handle log_clear button clicks.
 */
function log_clear_submit($form, &$form_state) {
  $filter = dblog_build_filter_query();
  $sql = 'DELETE FROM {watchdog}' . ($filter['where'] ? ' WHERE ' . str_replace('w.', '', $filter['where']) : '');
  if (db_query($sql, $filter['args']) === FALSE) {
    drupal_set_message(t('Log_clear failed.'));
  }
  else {
    $count = db_affected_rows();
    drupal_set_message(t('Deleted !count rows.', array(
      '!count' => $count,
    )));

    // Clear the filter.
    unset($_SESSION['dblog_overview_filter']);
  }
}

Functions

Namesort descending Description
log_clear_form_alter Implementation of hook_form_alter().
log_clear_help Implementation of hook_help().
log_clear_submit Handle log_clear button clicks.