function dblog_clear_submit in Util 6.2
Same name and namespace in other branches
- 6.3 contribs/dblog_ext/dblog_clear/dblog_clear.module \dblog_clear_submit()
1 string reference to 'dblog_clear_submit'
- dblog_clear_form_alter in contribs/
dblog_ext/ dblog_clear/ dblog_clear.module - Implementation of hook_form_alter().
File
- contribs/
dblog_ext/ dblog_clear/ dblog_clear.module, line 37
Code
function dblog_clear_submit() {
// works with or without dblog_ext
$filter = module_exists('dblog_ext') ? dblog_ext_build_filter_query() : dblog_build_filter_query();
if ($filter) {
$where = $filter['where'];
$args = $filter['args'];
// support filtering by user
if (strpos($where, 'u.name') === false) {
$where = str_replace('w.', '', $where);
}
else {
$query = 'SELECT w.wid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid';
$query .= ' WHERE ' . $where;
$result = db_query($query, $args);
$wids = array();
while ($row = db_fetch_array($result)) {
$wids[] = $row['wid'];
}
$args = array();
// clear $args
if (empty($wids)) {
unset($where);
}
else {
$where = "wid IN ('" . implode("', '", $wids) . "')";
}
}
}
$query = 'DELETE FROM {watchdog}';
if ($where) {
$query .= ' WHERE ' . $where;
}
if (db_query($query, $args) === FALSE) {
$msg = t('Failed to clear logs.');
drupal_set_message($msg, 'error');
$msg .= ' ' . t('Performed SQL query: @query; with arguments: @args', array(
'@query' => $query,
'@args' => implode(', ', $args),
));
watchdog('dblog_clear', $msg, NULL, WATCHDOG_ERROR);
}
else {
$count = db_affected_rows();
drupal_set_message(t('Deleted @count rows.', array(
'@count' => $count,
)));
// clear the filter
unset($_SESSION['dblog_overview_filter']);
}
}