function core_watchdog_query

8.0.x watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')
6.x watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')
7.x watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')
3.x watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')
4.x watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')
5.x watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')
master watchdog.drush.inc core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND')

Build a WHERE snippet based on given parameters.

Parameters

$type: String. Valid watchdog type.

$severity: Int or String for a valid watchdog severity message.

$filter: String. Value to filter watchdog messages by.

$criteria: ('AND', 'OR'). Criteria for the WHERE snippet.

Return value

False or array with structure ('where' => string, 'args' => array())

2 calls to core_watchdog_query()
drush_core_watchdog_delete in commands/core/watchdog.drush.inc
Command callback.
drush_core_watchdog_show_many in commands/core/watchdog.drush.inc
Print a table of watchdog messages.

File

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

Code

function core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND') {
  $args = array();
  $conditions = array();
  if ($type) {
    $types = core_watchdog_message_types();
    if (array_search($type, $types) === FALSE) {
      $msg = "Unknown message type: !type.\nValid types are: !types.";
      return drush_set_error(dt($msg, array('!type' => $type, '!types' => implode(', ', $types))));
    }
    $conditions[] = "type = :type";
    $args[':type'] = $type;
  }
  if (!is_null($severity)) {
    drush_include_engine('drupal', 'environment');
    $severities = core_watchdog_severity_levels();
    if (isset($severities[$severity])) {
      $level = $severity;
    }
    elseif (($key = array_search($severity, $severities)) !== FALSE) {
      $level = $key;
    }
    else {
      $level = FALSE;
    }
    if ($level === FALSE) {
      foreach ($severities as $key => $value) {
        $levels[] = "$value($key)";
      }
      $msg = "Unknown severity level: !severity.\nValid severity levels are: !levels.";
      return drush_set_error(dt($msg, array('!severity' => $severity, '!levels' => implode(', ', $levels))));
    }
    $conditions[] = 'severity = :severity';
    $args[':severity'] = $level;
  }
  if ($filter) {
    $conditions[] = "message LIKE :filter";
    $args[':filter'] = '%' . $filter . '%';
  }

  $where = implode(" $criteria ", $conditions);

  return array(
    'where' => $where,
    'args' => $args,
  );
}