function drush_core_watchdog_delete

8.0.x watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)
6.x watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)
7.x watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)
3.x watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)
4.x watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)
5.x watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)
master watchdog.drush.inc drush_core_watchdog_delete($arg = NULL)

Command callback.

Parameters

$arg: The id of the message to delete or 'all'.

File

commands/core/watchdog.drush.inc, line 276

Code

function drush_core_watchdog_delete($arg = NULL) {
  if ($arg == 'all') {
    drush_print(dt('All watchdog messages will be deleted.'));
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_user_abort();
    }
    drush_db_delete('watchdog');
    drush_log(dt('All watchdog messages have been deleted.'), 'ok');
  }
  else if (is_numeric($arg)) {
    drush_print(dt('Watchdog message #!wid will be deleted.', array('!wid' => $arg)));
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_user_abort();
    }
    $affected_rows = drush_db_delete('watchdog', 'wid=:wid', array(':wid' => $arg));
    if ($affected_rows == 1) {
      drush_log(dt('Watchdog message #!wid has been deleted.', array('!wid' => $arg)), 'ok');
    }
    else {
      return drush_set_error(dt('Watchdog message #!wid does not exist.', array('!wid' => $arg)));
    }
  }
  else {
    $type = drush_get_option('type');
    $severity = drush_get_option('severity');
    if ((is_null($arg)) && (is_null($type)) && (is_null($severity))) {
      return drush_set_error(dt('No options provided.'));
    }
    $where = core_watchdog_query($type, $severity, $arg, 'OR');
    if ($where === FALSE) {
      // Drush set error was already called by core_watchdog_query
      return FALSE;
    }
    drush_print(dt('All messages with !where will be deleted.', array('!where' => preg_replace("/message LIKE %$arg%/", "message body containing '$arg'", strtr($where['where'], $where['args'])))));
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_user_abort();
    }
    $affected_rows = drush_db_delete('watchdog', $where['where'], $where['args']);
    drush_log(dt('!affected_rows watchdog messages have been deleted.', array('!affected_rows' => $affected_rows)), 'ok');
  }
}