Drush: commands/core/watchdog.drush.inc Source File

  1. 7.x doxygen/html/watchdog_8drush_8inc_source.html
  2. master doxygen/html/watchdog_8drush_8inc_source.html
1 <?php
2 
3 /**
4  * Implementation of hook_drush_help().
5  */
6 function watchdog_drush_help($section) {
7  switch ($section) {
8  case 'meta:watchdog:title':
9  return dt('Watchdog commands');
10  case 'meta:watchdog:summary':
11  return dt('Interact with Drupal\'s db logging system.');
12  case 'drush:watchdog-list':
13  return dt('Show available message types and severity levels. A prompt will ask for a choice to show watchdog messages.');
14  case 'drush:watchdog-show':
15  return dt('Show watchdog messages. Arguments and options can be combined to configure which messages to show.');
16  case 'drush:watchdog-delete':
17  return dt('Delete watchdog messages. Arguments or options must be provided to specify which messages to delete.');
18  }
19 }
20 
21 /**
22  * Implementation of hook_drush_command().
23  */
24 function watchdog_drush_command() {
25  $items['watchdog-list'] = array(
26  'description' => 'Show available message types and severity levels. A prompt will ask for a choice to show watchdog messages.',
27  'drupal dependencies' => array('dblog'),
28  'outputformat' => array(
29  'default' => 'table',
30  'pipe-format' => 'var_export',
31  'field-labels' => array('wid' => 'ID', 'type' => 'Type', 'message' => 'Message', 'severity' => 'Severity', 'location' => 'Location', 'hostname' => 'Hostname', 'date' => 'Date', 'username' => 'Username'),
32  'fields-default' => array('wid', 'date', 'type', 'severity', 'message'),
33  'column-widths' => array('type' => 8, 'severity' => 8),
34  'output-data-type' => 'format-table',
35  ),
36  'aliases' => array('wd-list'),
37  );
38  $items['watchdog-show'] = array(
39  'description' => 'Show watchdog messages.',
40  'drupal dependencies' => array('dblog'),
41  'arguments' => array(
42  'wid' => 'Optional id of a watchdog message to show in detail. If not provided, a listing of most recent 10 messages will be displayed. Alternatively if a string is provided, watchdog messages will be filtered by it.',
43  ),
44  'options' => array(
45  'count' => 'The number of messages to show. Defaults to 10.',
46  'severity' => 'Restrict to messages of a given severity level.',
47  'type' => 'Restrict to messages of a given type.',
48  'tail' => 'Continuously show new watchdog messages until interrupted.',
49  'sleep-delay' => 'To be used in conjunction with --tail. This is the number of seconds to wait between each poll to the database. Delay is 1 second by default.',
50  'extended' => 'Return extended information about each message.',
51  ),
52  'examples' => array(
53  'drush watchdog-show' => 'Show a listing of most recent 10 messages.',
54  'drush watchdog-show 64' => 'Show in detail message with id 64.',
55  'drush watchdog-show "cron run succesful"' => 'Show a listing of most recent 10 messages containing the string "cron run succesful".',
56  'drush watchdog-show --count=46' => 'Show a listing of most recent 46 messages.',
57  'drush watchdog-show --severity=notice' => 'Show a listing of most recent 10 messages with a severity of notice.',
58  'drush watchdog-show --type=php' => 'Show a listing of most recent 10 messages of type php.',
59  'drush watchdog-show --tail --extended' => 'Show a listing of most recent 10 messages with extended information about each one and continue showing messages as they are registered in the watchdog.',
60  'drush watchdog-show --tail --sleep-delay=2' => 'Do a tail of the watchdog with a delay of two seconds between each poll to the database.',
61  ),
62  'outputformat' => array(
63  'default' => 'table',
64  'pipe-format' => 'var_export',
65  'field-labels' => array('wid' => 'ID', 'type' => 'Type', 'message' => 'Message', 'severity' => 'Severity', 'location' => 'Location', 'hostname' => 'Hostname', 'date' => 'Date', 'username' => 'Username'),
66  'fields-default' => array('wid', 'date', 'type', 'severity', 'message'),
67  'column-widths' => array('type' => 8, 'severity' => 8),
68  'output-data-type' => 'format-table',
69  ),
70  'aliases' => array('wd-show', 'ws'),
71  );
72  $items['watchdog-delete'] = array(
73  'description' => 'Delete watchdog messages.',
74  'drupal dependencies' => array('dblog'),
75  'options' => array(
76  'severity' => 'Delete messages of a given severity level.',
77  'type' => 'Delete messages of a given type.',
78  ),
79  'examples' => array(
80  'drush watchdog-delete all' => 'Delete all messages.',
81  'drush watchdog-delete 64' => 'Delete messages with id 64.',
82  'drush watchdog-delete "cron run succesful"' => 'Delete messages containing the string "cron run succesful".',
83  'drush watchdog-delete --severity=notice' => 'Delete all messages with a severity of notice.',
84  'drush watchdog-delete --type=cron' => 'Delete all messages of type cron.',
85  ),
86  'aliases' => array('wd-del', 'wd-delete'),
87  );
88  return $items;
89 }
90 
91 /**
92  * Command callback.
93  */
94 function drush_core_watchdog_list() {
95  drush_include_engine('drupal', 'environment');
96 
97  $options['-- types --'] = dt('== message types ==');
99  foreach ($types as $key => $type) {
100  $options[$key] = $type;
101  }
102  $options['-- levels --'] = dt('== severity levels ==');
103  $severities = drush_watchdog_severity_levels();
104  foreach ($severities as $key => $value) {
105  $options[$key] = "$value($key)";
106  }
107  $option = drush_choice($options, dt('Select a message type or severity level.'));
108  if ($option === FALSE) {
109  return drush_user_abort();
110  }
111  if (isset($types[$option])) {
112  drush_set_option('type', $types[$option]);
113  }
114  else {
115  drush_set_option('severity', $option - $ntypes);
116  }
118 }
119 
120 /**
121  * Command callback.
122  */
123 function drush_core_watchdog_show($arg = NULL) {
124  drush_include_engine('drupal', 'environment');
125 
126  if (is_numeric($arg)) {
127  return drush_core_watchdog_show_one($arg);
128  }
129  else {
130  return drush_core_watchdog_show_many($arg);
131  }
132 }
133 
134 /**
135  * Print a watchdog message.
136  *
137  * @param $wid
138  * The id of the message to show.
139  */
140 function drush_core_watchdog_show_one($wid) {
141  drush_set_default_outputformat('key-value-list', array('fields-default' => array('wid', 'type', 'message', 'severity', 'date'),));
142  $rsc = drush_db_select('watchdog', '*', 'wid = :wid', array(':wid' => $wid), 0, 1);
143  $result = drush_db_fetch_object($rsc);
144  if (!$result) {
145  return drush_set_error(dt('Watchdog message #!wid not found.', array('!wid' => $wid)));
146  }
147  $result = core_watchdog_format_result($result, TRUE);
148  return array($result->wid => (array)$result);
149 }
150 
151 /**
152  * Print a table of watchdog messages.
153  *
154  * @param $filter
155  * String to filter the message's text by.
156  */
157 function drush_core_watchdog_show_many($filter = NULL) {
158  $count = drush_get_option('count', 10);
159  $type = drush_get_option('type');
160  $severity = drush_get_option('severity');
161  $tail = drush_get_option('tail', FALSE);
162  $extended = drush_get_option('extended', FALSE);
163 
164  $where = core_watchdog_query($type, $severity, $filter);
165  if ($where === FALSE) {
166  return drush_log(dt('Aborting.'));
167  }
168  $rsc = drush_db_select('watchdog', '*', $where['where'], $where['args'], 0, $count, 'wid', 'DESC');
169  if ($rsc === FALSE) {
170  return drush_log(dt('Aborting.'));
171  }
172  $table = array();
173  while ($result = drush_db_fetch_object($rsc)) {
174  $row = core_watchdog_format_result($result, $extended);
175  $table[$row->wid] = (array)$row;
176  }
177  if (empty($table) && !$tail) {
178  drush_log(dt('No log messages available.'), 'ok');
179  return array();
180  }
181  else {
182  drush_log(dt('Most recent !count watchdog log messages:', array('!count' => $count)));
183  }
184  if ($tail) {
185  $field_list = array('wid' => 'ID', 'date' => 'Date', 'severity' => 'Severity', 'type' => 'Type', 'message' => 'Message');
186  $table = array_reverse($table);
187  $table_rows = drush_rows_of_key_value_to_array_table($table, $field_list, array());
188  $tbl = drush_print_table($table_rows, TRUE);
189  // Reuse the table object to display each line generated while in tail mode.
190  // To make it possible some hacking is done on the object:
191  // remove the header and reset the rows on each iteration.
192  $tbl->_headers = NULL;
193  // Obtain the last wid. If the table has no rows, start at 0.
194  if (count($table_rows) > 1) {
195  $last = array_pop($table_rows);
196  $last_wid = $last[0];
197  }
198  else {
199  $last_wid = 0;
200  }
201  // Adapt the where snippet.
202  if ($where['where'] != '') {
203  $where['where'] .= ' AND ';
204  }
205  $where['where'] .= 'wid > :wid';
206  // sleep-delay
207  $sleep_delay = drush_get_option('sleep-delay', 1);
208  while (TRUE) {
209  $where['args'][':wid'] = $last_wid;
210  $table = array();
211  // Reset table rows.
212  $tbl->_data = array();
213  $rsc = drush_db_select('watchdog', '*', $where['where'], $where['args'], NULL, NULL, 'wid', 'ASC');
214  while ($result = drush_db_fetch_object($rsc)) {
215  $row = core_watchdog_format_result($result, $extended);
216  $table[] = array($row->wid, $row->date, $row->severity, $row->type, $row->message);
217  #$tbl->addRow(array($row->wid, $row->date, $row->severity, $row->type, $row->message));
218  $last_wid = $row->wid;
219  }
220  $tbl->addData($table);
221  print $tbl->_buildTable();
222  sleep($sleep_delay);
223  }
224  }
225  return $table;
226 }
227 
228 /**
229  * Format a watchdog database row.
230  *
231  * @param $result
232  * Array. A database result object.
233  * @param $extended
234  * Boolean. Return extended message details.
235  * @return
236  * Array. The result object with some attributes themed.
237  */
238 function core_watchdog_format_result($result, $extended = FALSE) {
239  // Severity.
240  $severities = drush_watchdog_severity_levels();
241  $result->severity = $severities[$result->severity];
242 
243  // Date.
244  $result->date = format_date($result->timestamp, 'custom', 'd/M H:i');
245  unset($result->timestamp);
246 
247  // Message.
248  $variables = $result->variables;
249  if (is_string($variables)) {
250  $variables = unserialize($variables);
251  }
252  if (is_array($variables)) {
253  $result->message = strtr($result->message, $variables);
254  }
255  unset($result->variables);
256  $message_length = 188;
257 
258  // Print all the data available
259  if ($extended) {
260  // Possible empty values.
261  if (empty($result->link)) {
262  unset($result->link);
263  }
264  if (empty($result->referer)) {
265  unset($result->referer);
266  }
267  // Username.
268  if ($account = user_load($result->uid)) {
269  $result->username = $account->name;
270  }
271  else {
272  $result->username = dt('Anonymous');
273  }
274  unset($result->uid);
275  $message_length = PHP_INT_MAX;
276  }
277 
278  $result->message = truncate_utf8(strip_tags(decode_entities($result->message)), $message_length, FALSE, FALSE);
279 
280  return $result;
281 }
282 
283 /**
284  * Command callback.
285  *
286  * @param $arg
287  * The id of the message to delete or 'all'.
288  */
289 function drush_core_watchdog_delete($arg = NULL) {
290  drush_include_engine('drupal', 'environment');
291 
292  if ($arg == 'all') {
293  drush_print(dt('All watchdog messages will be deleted.'));
294  if (!drush_confirm(dt('Do you really want to continue?'))) {
295  return drush_user_abort();
296  }
297  drush_db_delete('watchdog');
298  drush_log(dt('All watchdog messages have been deleted.'), 'ok');
299  }
300  else if (is_numeric($arg)) {
301  drush_print(dt('Watchdog message #!wid will be deleted.', array('!wid' => $arg)));
302  if(!drush_confirm(dt('Do you really want to continue?'))) {
303  return drush_user_abort();
304  }
305  $affected_rows = drush_db_delete('watchdog', 'wid=:wid', array(':wid' => $arg));
306  if ($affected_rows == 1) {
307  drush_log(dt('Watchdog message #!wid has been deleted.', array('!wid' => $arg)), 'ok');
308  }
309  else {
310  return drush_set_error(dt('Watchdog message #!wid does not exist.', array('!wid' => $arg)));
311  }
312  }
313  else {
314  $type = drush_get_option('type');
315  $severity = drush_get_option('severity');
316  if ((!isset($arg))&&(!isset($type))&&(!isset($severity))) {
317  return drush_set_error(dt('No options provided.'));
318  }
319  $where = core_watchdog_query($type, $severity, $arg, 'OR');
320  if ($where === FALSE) {
321  // Drush set error was already called by core_watchdog_query
322  return FALSE;
323  }
324  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'])))));
325  if(!drush_confirm(dt('Do you really want to continue?'))) {
326  return drush_user_abort();
327  }
328  $affected_rows = drush_db_delete('watchdog', $where['where'], $where['args']);
329  drush_log(dt('!affected_rows watchdog messages have been deleted.', array('!affected_rows' => $affected_rows)), 'ok');
330  }
331 }
332 
333 /**
334  * Build a WHERE snippet based on given parameters.
335  *
336  * @param $type
337  * String. Valid watchdog type.
338  * @param $severity
339  * Int or String for a valid watchdog severity message.
340  * @param $filter
341  * String. Value to filter watchdog messages by.
342  * @param $criteria
343  * ('AND', 'OR'). Criteria for the WHERE snippet.
344  * @return
345  * False or array with structure ('where' => string, 'args' => array())
346  */
347 function core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = 'AND') {
348  $args = array();
349  $conditions = array();
350  if ($type) {
351  $types = drush_watchdog_message_types();
352  if (array_search($type, $types) === FALSE) {
353  $msg = "Unrecognized message type: !type.\nRecognized types are: !types.";
354  return drush_set_error('WATCHDOG_UNRECOGNIZED_TYPE', dt($msg, array('!type' => $type, '!types' => implode(', ', $types))));
355  }
356  $conditions[] = "type = :type";
357  $args[':type'] = $type;
358  }
359  if (isset($severity)) {
360  $severities = drush_watchdog_severity_levels();
361  if (isset($severities[$severity])) {
362  $level = $severity;
363  }
364  elseif (($key = array_search($severity, $severities)) !== FALSE) {
365  $level = $key;
366  }
367  else {
368  $level = FALSE;
369  }
370  if ($level === FALSE) {
371  foreach ($severities as $key => $value) {
372  $levels[] = "$value($key)";
373  }
374  $msg = "Unknown severity level: !severity.\nValid severity levels are: !levels.";
375  return drush_set_error(dt($msg, array('!severity' => $severity, '!levels' => implode(', ', $levels))));
376  }
377  $conditions[] = 'severity = :severity';
378  $args[':severity'] = $level;
379  }
380  if ($filter) {
381  $conditions[] = "message LIKE :filter";
382  $args[':filter'] = '%'.$filter.'%';
383  }
384 
385  $where = implode(" $criteria ", $conditions);
386 
387  return array('where' => $where, 'args' => $args);
388 }

File

doxygen/html/watchdog_8drush_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: commands/core/watchdog.drush.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_afac61274991793aa7e9133a8f4f291e.html">commands</a></li><li class="navelem"><a class="el" href="dir_5762b63965e3a68a35f77c23b4dd4668.html">core</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">watchdog.drush.inc</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Implementation of hook_drush_help().</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="keyword">function</span> watchdog_drush_help($section) {</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;  <span class="keywordflow">switch</span> ($section)  {</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;meta:watchdog:title&#39;</span>:</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Watchdog commands&#39;</span>);</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;meta:watchdog:summary&#39;</span>:</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Interact with Drupal\&#39;s db logging system.&#39;</span>);</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;drush:watchdog-list&#39;</span>:</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Show available message types and severity levels. A prompt will ask for a choice to show watchdog messages.&#39;</span>);</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;drush:watchdog-show&#39;</span>:</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Show watchdog messages. Arguments and options can be combined to configure which messages to show.&#39;</span>);</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;drush:watchdog-delete&#39;</span>:</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Delete watchdog messages. Arguments or options must be provided to specify which messages to delete.&#39;</span>);</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;  }</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;}</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> * Implementation of hook_drush_command().</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">function</span> watchdog_drush_command() {</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  $items[<span class="stringliteral">&#39;watchdog-list&#39;</span>] = array(</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Show available message types and severity levels. A prompt will ask for a choice to show watchdog messages.&#39;</span>,</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    <span class="stringliteral">&#39;drupal dependencies&#39;</span> =&gt; array(<span class="stringliteral">&#39;dblog&#39;</span>),</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    <span class="stringliteral">&#39;outputformat&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;      <span class="stringliteral">&#39;default&#39;</span> =&gt; <span class="stringliteral">&#39;table&#39;</span>,</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;      <span class="stringliteral">&#39;pipe-format&#39;</span> =&gt; <span class="stringliteral">&#39;var_export&#39;</span>,</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;      <span class="stringliteral">&#39;field-labels&#39;</span> =&gt; array(<span class="stringliteral">&#39;wid&#39;</span> =&gt; <span class="stringliteral">&#39;ID&#39;</span>, <span class="stringliteral">&#39;type&#39;</span> =&gt; <span class="stringliteral">&#39;Type&#39;</span>, <span class="stringliteral">&#39;message&#39;</span> =&gt; <span class="stringliteral">&#39;Message&#39;</span>, <span class="stringliteral">&#39;severity&#39;</span> =&gt; <span class="stringliteral">&#39;Severity&#39;</span>, <span class="stringliteral">&#39;location&#39;</span> =&gt; <span class="stringliteral">&#39;Location&#39;</span>, <span class="stringliteral">&#39;hostname&#39;</span> =&gt; <span class="stringliteral">&#39;Hostname&#39;</span>, <span class="stringliteral">&#39;date&#39;</span> =&gt; <span class="stringliteral">&#39;Date&#39;</span>, <span class="stringliteral">&#39;username&#39;</span> =&gt; <span class="stringliteral">&#39;Username&#39;</span>),</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;      <span class="stringliteral">&#39;fields-default&#39;</span> =&gt; array(<span class="stringliteral">&#39;wid&#39;</span>, <span class="stringliteral">&#39;date&#39;</span>, <span class="stringliteral">&#39;type&#39;</span>, <span class="stringliteral">&#39;severity&#39;</span>, <span class="stringliteral">&#39;message&#39;</span>),</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;      <span class="stringliteral">&#39;column-widths&#39;</span> =&gt; array(<span class="stringliteral">&#39;type&#39;</span> =&gt; 8, <span class="stringliteral">&#39;severity&#39;</span> =&gt; 8),</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;      <span class="stringliteral">&#39;output-data-type&#39;</span> =&gt; <span class="stringliteral">&#39;format-table&#39;</span>,</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    ),</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;wd-list&#39;</span>),</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;  );</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;  $items[<span class="stringliteral">&#39;watchdog-show&#39;</span>] = array(</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Show watchdog messages.&#39;</span>,</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="stringliteral">&#39;drupal dependencies&#39;</span> =&gt; array(<span class="stringliteral">&#39;dblog&#39;</span>),</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="stringliteral">&#39;arguments&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;      <span class="stringliteral">&#39;wid&#39;</span> =&gt; <span class="stringliteral">&#39;Optional id of a watchdog message to show in detail. If not provided, a listing of most recent 10 messages will be displayed. Alternatively if a string is provided, watchdog messages will be filtered by it.&#39;</span>,</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    ),</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="stringliteral">&#39;options&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;      <span class="stringliteral">&#39;count&#39;</span> =&gt; <span class="stringliteral">&#39;The number of messages to show. Defaults to 10.&#39;</span>,</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;      <span class="stringliteral">&#39;severity&#39;</span> =&gt; <span class="stringliteral">&#39;Restrict to messages of a given severity level.&#39;</span>,</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;      <span class="stringliteral">&#39;type&#39;</span> =&gt; <span class="stringliteral">&#39;Restrict to messages of a given type.&#39;</span>,</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;      <span class="stringliteral">&#39;tail&#39;</span> =&gt; <span class="stringliteral">&#39;Continuously show new watchdog messages until interrupted.&#39;</span>,</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;      <span class="stringliteral">&#39;sleep-delay&#39;</span> =&gt; <span class="stringliteral">&#39;To be used in conjunction with --tail. This is the number of seconds to wait between each poll to the database. Delay is 1 second by default.&#39;</span>,</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;      <span class="stringliteral">&#39;extended&#39;</span> =&gt; <span class="stringliteral">&#39;Return extended information about each message.&#39;</span>,</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    ),</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show&#39;</span> =&gt; <span class="stringliteral">&#39;Show a listing of most recent 10 messages.&#39;</span>,</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show 64&#39;</span> =&gt; <span class="stringliteral">&#39;Show in detail message with id 64.&#39;</span>,</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show &quot;cron run succesful&quot;&#39;</span> =&gt; <span class="stringliteral">&#39;Show a listing of most recent 10 messages containing the string &quot;cron run succesful&quot;.&#39;</span>,</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show --count=46&#39;</span> =&gt; <span class="stringliteral">&#39;Show a listing of most recent 46 messages.&#39;</span>,</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show --severity=notice&#39;</span> =&gt; <span class="stringliteral">&#39;Show a listing of most recent 10 messages with a severity of notice.&#39;</span>,</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show --type=php&#39;</span> =&gt; <span class="stringliteral">&#39;Show a listing of most recent 10 messages of type php.&#39;</span>,</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show --tail --extended&#39;</span> =&gt; <span class="stringliteral">&#39;Show a listing of most recent 10 messages with extended information about each one and continue showing messages as they are registered in the watchdog.&#39;</span>,</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      <span class="stringliteral">&#39;drush watchdog-show --tail --sleep-delay=2&#39;</span> =&gt; <span class="stringliteral">&#39;Do a tail of the watchdog with a delay of two seconds between each poll to the database.&#39;</span>,</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    ),</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    <span class="stringliteral">&#39;outputformat&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;      <span class="stringliteral">&#39;default&#39;</span> =&gt; <span class="stringliteral">&#39;table&#39;</span>,</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;      <span class="stringliteral">&#39;pipe-format&#39;</span> =&gt; <span class="stringliteral">&#39;var_export&#39;</span>,</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;      <span class="stringliteral">&#39;field-labels&#39;</span> =&gt; array(<span class="stringliteral">&#39;wid&#39;</span> =&gt; <span class="stringliteral">&#39;ID&#39;</span>, <span class="stringliteral">&#39;type&#39;</span> =&gt; <span class="stringliteral">&#39;Type&#39;</span>, <span class="stringliteral">&#39;message&#39;</span> =&gt; <span class="stringliteral">&#39;Message&#39;</span>, <span class="stringliteral">&#39;severity&#39;</span> =&gt; <span class="stringliteral">&#39;Severity&#39;</span>, <span class="stringliteral">&#39;location&#39;</span> =&gt; <span class="stringliteral">&#39;Location&#39;</span>, <span class="stringliteral">&#39;hostname&#39;</span> =&gt; <span class="stringliteral">&#39;Hostname&#39;</span>, <span class="stringliteral">&#39;date&#39;</span> =&gt; <span class="stringliteral">&#39;Date&#39;</span>, <span class="stringliteral">&#39;username&#39;</span> =&gt; <span class="stringliteral">&#39;Username&#39;</span>),</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;      <span class="stringliteral">&#39;fields-default&#39;</span> =&gt; array(<span class="stringliteral">&#39;wid&#39;</span>, <span class="stringliteral">&#39;date&#39;</span>, <span class="stringliteral">&#39;type&#39;</span>, <span class="stringliteral">&#39;severity&#39;</span>, <span class="stringliteral">&#39;message&#39;</span>),</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;      <span class="stringliteral">&#39;column-widths&#39;</span> =&gt; array(<span class="stringliteral">&#39;type&#39;</span> =&gt; 8, <span class="stringliteral">&#39;severity&#39;</span> =&gt; 8),</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;      <span class="stringliteral">&#39;output-data-type&#39;</span> =&gt; <span class="stringliteral">&#39;format-table&#39;</span>,</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    ),</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;wd-show&#39;</span>, <span class="stringliteral">&#39;ws&#39;</span>),</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;  );</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;  $items[<span class="stringliteral">&#39;watchdog-delete&#39;</span>] = array(</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Delete watchdog messages.&#39;</span>,</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <span class="stringliteral">&#39;drupal dependencies&#39;</span> =&gt; array(<span class="stringliteral">&#39;dblog&#39;</span>),</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="stringliteral">&#39;options&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;      <span class="stringliteral">&#39;severity&#39;</span> =&gt; <span class="stringliteral">&#39;Delete messages of a given severity level.&#39;</span>,</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;      <span class="stringliteral">&#39;type&#39;</span> =&gt; <span class="stringliteral">&#39;Delete messages of a given type.&#39;</span>,</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    ),</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;      <span class="stringliteral">&#39;drush watchdog-delete all&#39;</span> =&gt; <span class="stringliteral">&#39;Delete all messages.&#39;</span>,</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;      <span class="stringliteral">&#39;drush watchdog-delete 64&#39;</span> =&gt; <span class="stringliteral">&#39;Delete messages with id 64.&#39;</span>,</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;      <span class="stringliteral">&#39;drush watchdog-delete &quot;cron run succesful&quot;&#39;</span> =&gt; <span class="stringliteral">&#39;Delete messages containing the string &quot;cron run succesful&quot;.&#39;</span>,</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;      <span class="stringliteral">&#39;drush watchdog-delete --severity=notice&#39;</span> =&gt; <span class="stringliteral">&#39;Delete all messages with a severity of notice.&#39;</span>,</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;      <span class="stringliteral">&#39;drush watchdog-delete --type=cron&#39;</span> =&gt; <span class="stringliteral">&#39;Delete all messages of type cron.&#39;</span>,</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    ),</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;wd-del&#39;</span>, <span class="stringliteral">&#39;wd-delete&#39;</span>),</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;  );</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;  <span class="keywordflow">return</span> $items;</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;}</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;<span class="comment"> * Command callback.</span></div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;<span class="keyword">function</span> drush_core_watchdog_list() {</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;  <a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">drush_include_engine</a>(<span class="stringliteral">&#39;drupal&#39;</span>, <span class="stringliteral">&#39;environment&#39;</span>);</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  $options[<span class="stringliteral">&#39;-- types --&#39;</span>] = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;== message types ==&#39;</span>);</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  $types = <a class="code" href="commands_2core_2drupal_2environment_8inc.html#ab162dcfd1b7a906f4097dc5e3d0ce5b5">drush_watchdog_message_types</a>();</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  <span class="keywordflow">foreach</span> ($types as $key =&gt; $type) {</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    $options[$key] = $type;</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;  }</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;  $options[<span class="stringliteral">&#39;-- levels --&#39;</span>] = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;== severity levels ==&#39;</span>);</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;  $severities = <a class="code" href="commands_2core_2drupal_2environment_8inc.html#ae44a69423e59e63b8acd6dadc602081d">drush_watchdog_severity_levels</a>();</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;  <span class="keywordflow">foreach</span> ($severities as $key =&gt; $value) {</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    $options[$key] = <span class="stringliteral">&quot;$value($key)&quot;</span>;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  }</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  $option = <a class="code" href="group__userinput.html#ga7e823bcd58051b17e6e5601340f0c784">drush_choice</a>($options, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Select a message type or severity level.&#39;</span>));</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;  <span class="keywordflow">if</span> ($option === FALSE) {</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>();</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;  }</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  <span class="keywordflow">if</span> (isset($types[$option])) {</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    <a class="code" href="context_8inc.html#aa4b55e2f6174c8b6efaa8f23a0f9e0af">drush_set_option</a>(<span class="stringliteral">&#39;type&#39;</span>, $types[$option]);</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;  }</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    <a class="code" href="context_8inc.html#aa4b55e2f6174c8b6efaa8f23a0f9e0af">drush_set_option</a>(<span class="stringliteral">&#39;severity&#39;</span>, $option - $ntypes);</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;  }</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;  <span class="keywordflow">return</span> drush_core_watchdog_show_many();</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;}</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;<span class="comment"> * Command callback.</span></div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;<span class="keyword">function</span> drush_core_watchdog_show($arg = NULL) {</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;  <a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">drush_include_engine</a>(<span class="stringliteral">&#39;drupal&#39;</span>, <span class="stringliteral">&#39;environment&#39;</span>);</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  <span class="keywordflow">if</span> (is_numeric($arg)) {</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    <span class="keywordflow">return</span> drush_core_watchdog_show_one($arg);</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;  }</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <span class="keywordflow">return</span> drush_core_watchdog_show_many($arg);</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;  }</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;}</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;<span class="comment"> * Print a watchdog message.</span></div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;<span class="comment"> * @param $wid</span></div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;<span class="comment"> *    The id of the message to show.</span></div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="keyword">function</span> drush_core_watchdog_show_one($wid) {</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;  <a class="code" href="outputformat_8drush_8inc.html#a46f0ffb5f8bf676a5dfec452b083a9f2">drush_set_default_outputformat</a>(<span class="stringliteral">&#39;key-value-list&#39;</span>, array(<span class="stringliteral">&#39;fields-default&#39;</span> =&gt; array(<span class="stringliteral">&#39;wid&#39;</span>, <span class="stringliteral">&#39;type&#39;</span>, <span class="stringliteral">&#39;message&#39;</span>, <span class="stringliteral">&#39;severity&#39;</span>, <span class="stringliteral">&#39;date&#39;</span>),));</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;  $rsc = <a class="code" href="group__dbfunctions.html#gaaf67a267a19ac63f7eb05721b2170f89">drush_db_select</a>(<span class="stringliteral">&#39;watchdog&#39;</span>, <span class="charliteral">&#39;*&#39;</span>, <span class="stringliteral">&#39;wid = :wid&#39;</span>, array(<span class="stringliteral">&#39;:wid&#39;</span> =&gt; $wid), 0, 1);</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;  $result = <a class="code" href="group__dbfunctions.html#ga4cd1e1df83196d9a69084246703c9057">drush_db_fetch_object</a>($rsc);</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;  <span class="keywordflow">if</span> (!$result) {</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Watchdog message #!wid not found.&#39;</span>, array(<span class="stringliteral">&#39;!wid&#39;</span> =&gt; $wid)));</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  }</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;  $result = core_watchdog_format_result($result, TRUE);</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;  <span class="keywordflow">return</span> array($result-&gt;wid =&gt; (array)$result);</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;}</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;<span class="comment"> * Print a table of watchdog messages.</span></div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;<span class="comment"> * @param $filter</span></div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="comment"> *   String to filter the message&#39;s text by.</span></div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;<span class="keyword">function</span> drush_core_watchdog_show_many($filter = NULL) {</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  $count = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;count&#39;</span>, 10);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;  $type = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;type&#39;</span>);</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;  $severity = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;severity&#39;</span>);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;  $tail = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;tail&#39;</span>, FALSE);</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;  $extended = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;extended&#39;</span>, FALSE);</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;  $where = core_watchdog_query($type, $severity, $filter);</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;  <span class="keywordflow">if</span> ($where === FALSE) {</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Aborting.&#39;</span>));</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;  }</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;  $rsc = <a class="code" href="group__dbfunctions.html#gaaf67a267a19ac63f7eb05721b2170f89">drush_db_select</a>(<span class="stringliteral">&#39;watchdog&#39;</span>, <span class="charliteral">&#39;*&#39;</span>, $where[<span class="stringliteral">&#39;where&#39;</span>], $where[<span class="stringliteral">&#39;args&#39;</span>], 0, $count, <span class="stringliteral">&#39;wid&#39;</span>, <span class="stringliteral">&#39;DESC&#39;</span>);</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;  <span class="keywordflow">if</span> ($rsc === FALSE) {</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Aborting.&#39;</span>));</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;  }</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;  $table = array();</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;  <span class="keywordflow">while</span> ($result = <a class="code" href="group__dbfunctions.html#ga4cd1e1df83196d9a69084246703c9057">drush_db_fetch_object</a>($rsc)) {</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    $row = core_watchdog_format_result($result, $extended);</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    $table[$row-&gt;wid] = (array)$row;</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;  }</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;  <span class="keywordflow">if</span> (empty($table) &amp;&amp; !$tail) {</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;No log messages available.&#39;</span>), <span class="stringliteral">&#39;ok&#39;</span>);</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    <span class="keywordflow">return</span> array();</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;  }</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Most recent !count watchdog log messages:&#39;</span>, array(<span class="stringliteral">&#39;!count&#39;</span> =&gt; $count)));</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;  }</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;  <span class="keywordflow">if</span> ($tail) {</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    $field_list = array(<span class="stringliteral">&#39;wid&#39;</span> =&gt; <span class="stringliteral">&#39;ID&#39;</span>, <span class="stringliteral">&#39;date&#39;</span> =&gt; <span class="stringliteral">&#39;Date&#39;</span>, <span class="stringliteral">&#39;severity&#39;</span> =&gt; <span class="stringliteral">&#39;Severity&#39;</span>, <span class="stringliteral">&#39;type&#39;</span> =&gt; <span class="stringliteral">&#39;Type&#39;</span>, <span class="stringliteral">&#39;message&#39;</span> =&gt; <span class="stringliteral">&#39;Message&#39;</span>);</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;    $table = array_reverse($table);</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;    $table_rows = <a class="code" href="group__outputfunctions.html#gae21dcb7f9594eefec94104dbe7cede09">drush_rows_of_key_value_to_array_table</a>($table, $field_list, array());</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;    $tbl = <a class="code" href="group__outputfunctions.html#ga2dfb80176f98c67097334acfa98211cd">drush_print_table</a>($table_rows, TRUE);</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;    <span class="comment">// Reuse the table object to display each line generated while in tail mode.</span></div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;    <span class="comment">// To make it possible some hacking is done on the object:</span></div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;    <span class="comment">// remove the header and reset the rows on each iteration.</span></div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;    $tbl-&gt;_headers = NULL;</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;    <span class="comment">// Obtain the last wid. If the table has no rows, start at 0.</span></div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;    <span class="keywordflow">if</span> (count($table_rows) &gt; 1) {</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;      $last = array_pop($table_rows);</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;      $last_wid = $last[0];</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;    }</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;      $last_wid = 0;</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;    }</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;    <span class="comment">// Adapt the where snippet.</span></div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;    <span class="keywordflow">if</span> ($where[<span class="stringliteral">&#39;where&#39;</span>] != <span class="stringliteral">&#39;&#39;</span>) {</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;      $where[<span class="stringliteral">&#39;where&#39;</span>] .= <span class="stringliteral">&#39; AND &#39;</span>;</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;    }</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;    $where[<span class="stringliteral">&#39;where&#39;</span>] .= <span class="stringliteral">&#39;wid &gt; :wid&#39;</span>;</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;    <span class="comment">// sleep-delay</span></div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;    $sleep_delay = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;sleep-delay&#39;</span>, 1);</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;    <span class="keywordflow">while</span> (TRUE) {</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;      $where[<span class="stringliteral">&#39;args&#39;</span>][<span class="stringliteral">&#39;:wid&#39;</span>] = $last_wid;</div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;      $table = array();</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;      <span class="comment">// Reset table rows.</span></div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;      $tbl-&gt;_data = array();</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;      $rsc = <a class="code" href="group__dbfunctions.html#gaaf67a267a19ac63f7eb05721b2170f89">drush_db_select</a>(<span class="stringliteral">&#39;watchdog&#39;</span>, <span class="charliteral">&#39;*&#39;</span>, $where[<span class="stringliteral">&#39;where&#39;</span>], $where[<span class="stringliteral">&#39;args&#39;</span>], NULL, NULL, <span class="stringliteral">&#39;wid&#39;</span>, <span class="stringliteral">&#39;ASC&#39;</span>);</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;      <span class="keywordflow">while</span> ($result = <a class="code" href="group__dbfunctions.html#ga4cd1e1df83196d9a69084246703c9057">drush_db_fetch_object</a>($rsc)) {</div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;        $row = core_watchdog_format_result($result, $extended);</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;        $table[] = array($row-&gt;wid, $row-&gt;date, $row-&gt;severity, $row-&gt;type, $row-&gt;message);</div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;<span class="preprocessor">        #$tbl-&gt;addRow(array($row-&gt;wid, $row-&gt;date, $row-&gt;severity, $row-&gt;type, $row-&gt;message));</span></div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;<span class="preprocessor"></span>        $last_wid = $row-&gt;wid;</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;      }</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;      $tbl-&gt;addData($table);</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;      print $tbl-&gt;_buildTable();</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;      sleep($sleep_delay);</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;    }</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;  }</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;  <span class="keywordflow">return</span> $table;</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;}</div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;<span class="comment"> * Format a watchdog database row.</span></div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;<span class="comment"> * @param $result</span></div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;<span class="comment"> *   Array. A database result object.</span></div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;<span class="comment"> * @param $extended</span></div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;<span class="comment"> *   Boolean. Return extended message details.</span></div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;<span class="comment"> *   Array. The result object with some attributes themed.</span></div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;<span class="keyword">function</span> core_watchdog_format_result($result, $extended = FALSE) {</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;  <span class="comment">// Severity.</span></div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;  $severities = <a class="code" href="commands_2core_2drupal_2environment_8inc.html#ae44a69423e59e63b8acd6dadc602081d">drush_watchdog_severity_levels</a>();</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;  $result-&gt;severity = $severities[$result-&gt;severity];</div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;</div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;  <span class="comment">// Date.</span></div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;  $result-&gt;date = format_date($result-&gt;timestamp, <span class="stringliteral">&#39;custom&#39;</span>, <span class="stringliteral">&#39;d/M H:i&#39;</span>);</div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;  unset($result-&gt;timestamp);</div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;</div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;  <span class="comment">// Message.</span></div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;  $variables = $result-&gt;variables;</div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;  <span class="keywordflow">if</span> (is_string($variables)) {</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;    $variables = unserialize($variables);</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;  }</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;  <span class="keywordflow">if</span> (is_array($variables)) {</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;    $result-&gt;message = strtr($result-&gt;message, $variables);</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;  }</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;  unset($result-&gt;variables);</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;  $message_length = 188;</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;  <span class="comment">// Print all the data available</span></div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;  <span class="keywordflow">if</span> ($extended) {</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;    <span class="comment">// Possible empty values.</span></div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;    <span class="keywordflow">if</span> (empty($result-&gt;link)) {</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;      unset($result-&gt;link);</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;    }</div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;    <span class="keywordflow">if</span> (empty($result-&gt;referer)) {</div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;      unset($result-&gt;referer);</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;    }</div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;    <span class="comment">// Username.</span></div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;    <span class="keywordflow">if</span> ($account = user_load($result-&gt;uid)) {</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;      $result-&gt;username = $account-&gt;name;</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;    }</div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;      $result-&gt;username = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Anonymous&#39;</span>);</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;    }</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;    unset($result-&gt;uid);</div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;    $message_length = PHP_INT_MAX;</div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;  }</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;  $result-&gt;message = truncate_utf8(strip_tags(decode_entities($result-&gt;message)), $message_length, FALSE, FALSE);</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;}</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;<span class="comment"> * Command callback.</span></div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;<span class="comment"> * @param $arg</span></div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;<span class="comment"> *   The id of the message to delete or &#39;all&#39;.</span></div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;<span class="keyword">function</span> drush_core_watchdog_delete($arg = NULL) {</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;  <a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">drush_include_engine</a>(<span class="stringliteral">&#39;drupal&#39;</span>, <span class="stringliteral">&#39;environment&#39;</span>);</div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;</div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;  <span class="keywordflow">if</span> ($arg == <span class="stringliteral">&#39;all&#39;</span>) {</div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;    <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;All watchdog messages will be deleted.&#39;</span>));</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">drush_confirm</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Do you really want to continue?&#39;</span>))) {</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>();</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;    }</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;    <a class="code" href="group__dbfunctions.html#ga67f2a8891d0642284b856f8d90fa768d">drush_db_delete</a>(<span class="stringliteral">&#39;watchdog&#39;</span>);</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;All watchdog messages have been deleted.&#39;</span>), <span class="stringliteral">&#39;ok&#39;</span>);</div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;  }</div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (is_numeric($arg)) {</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;    <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Watchdog message #!wid will be deleted.&#39;</span>, array(<span class="stringliteral">&#39;!wid&#39;</span> =&gt; $arg)));</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;    <span class="keywordflow">if</span>(!<a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">drush_confirm</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Do you really want to continue?&#39;</span>))) {</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>();</div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;    }</div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;    $affected_rows = <a class="code" href="group__dbfunctions.html#ga67f2a8891d0642284b856f8d90fa768d">drush_db_delete</a>(<span class="stringliteral">&#39;watchdog&#39;</span>, <span class="stringliteral">&#39;wid=:wid&#39;</span>, array(<span class="stringliteral">&#39;:wid&#39;</span> =&gt; $arg));</div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;    <span class="keywordflow">if</span> ($affected_rows == 1) {</div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;      <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Watchdog message #!wid has been deleted.&#39;</span>, array(<span class="stringliteral">&#39;!wid&#39;</span> =&gt; $arg)), <span class="stringliteral">&#39;ok&#39;</span>);</div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;    }</div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Watchdog message #!wid does not exist.&#39;</span>, array(<span class="stringliteral">&#39;!wid&#39;</span> =&gt; $arg)));</div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;    }</div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;  }</div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;    $type = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;type&#39;</span>);</div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;    $severity = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;severity&#39;</span>);</div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;    <span class="keywordflow">if</span> ((!isset($arg))&amp;&amp;(!isset($type))&amp;&amp;(!isset($severity))) {</div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;No options provided.&#39;</span>));</div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;    }</div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;    $where = core_watchdog_query($type, $severity, $arg, <span class="stringliteral">&#39;OR&#39;</span>);</div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;    <span class="keywordflow">if</span> ($where === FALSE) {</div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;      <span class="comment">// Drush set error was already called by core_watchdog_query</span></div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;      <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;    }</div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;    <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;All messages with !where will be deleted.&#39;</span>, array(<span class="stringliteral">&#39;!where&#39;</span> =&gt; preg_replace(<span class="stringliteral">&quot;/message LIKE %$arg%/&quot;</span>, <span class="stringliteral">&quot;message body containing &#39;$arg&#39;&quot;</span> , strtr($where[<span class="stringliteral">&#39;where&#39;</span>], $where[<span class="stringliteral">&#39;args&#39;</span>])))));</div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;    <span class="keywordflow">if</span>(!<a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">drush_confirm</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Do you really want to continue?&#39;</span>))) {</div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>();</div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;    }</div>
<div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;    $affected_rows = <a class="code" href="group__dbfunctions.html#ga67f2a8891d0642284b856f8d90fa768d">drush_db_delete</a>(<span class="stringliteral">&#39;watchdog&#39;</span>, $where[<span class="stringliteral">&#39;where&#39;</span>], $where[<span class="stringliteral">&#39;args&#39;</span>]);</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;!affected_rows watchdog messages have been deleted.&#39;</span>, array(<span class="stringliteral">&#39;!affected_rows&#39;</span> =&gt; $affected_rows)), <span class="stringliteral">&#39;ok&#39;</span>);</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;  }</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;}</div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;<span class="comment"> * Build a WHERE snippet based on given parameters.</span></div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;<span class="comment"> * @param $type</span></div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;<span class="comment"> *   String. Valid watchdog type.</span></div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;<span class="comment"> * @param $severity</span></div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;<span class="comment"> *   Int or String for a valid watchdog severity message.</span></div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;<span class="comment"> * @param $filter</span></div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;<span class="comment"> *   String. Value to filter watchdog messages by.</span></div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;<span class="comment"> * @param $criteria</span></div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;<span class="comment"> *   (&#39;AND&#39;, &#39;OR&#39;). Criteria for the WHERE snippet.</span></div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;<span class="comment"> *   False or array with structure (&#39;where&#39; =&gt; string, &#39;args&#39; =&gt; array())</span></div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;<span class="keyword">function</span> core_watchdog_query($type = NULL, $severity = NULL, $filter = NULL, $criteria = <span class="stringliteral">&#39;AND&#39;</span>) {</div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;  $args = array();</div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;  $conditions = array();</div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;  <span class="keywordflow">if</span> ($type) {</div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;    $types = <a class="code" href="commands_2core_2drupal_2environment_8inc.html#ab162dcfd1b7a906f4097dc5e3d0ce5b5">drush_watchdog_message_types</a>();</div>
<div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;    <span class="keywordflow">if</span> (array_search($type, $types) === FALSE) {</div>
<div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;      $msg = <span class="stringliteral">&quot;Unrecognized message type: !type.\nRecognized types are: !types.&quot;</span>;</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;WATCHDOG_UNRECOGNIZED_TYPE&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>($msg, array(<span class="stringliteral">&#39;!type&#39;</span> =&gt; $type, <span class="stringliteral">&#39;!types&#39;</span> =&gt; implode(<span class="stringliteral">&#39;, &#39;</span>, $types))));</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;    }</div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;    $conditions[] = <span class="stringliteral">&quot;type = :type&quot;</span>;</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;    $args[<span class="stringliteral">&#39;:type&#39;</span>] = $type;</div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;  }</div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;  <span class="keywordflow">if</span> (isset($severity)) {</div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;    $severities = <a class="code" href="commands_2core_2drupal_2environment_8inc.html#ae44a69423e59e63b8acd6dadc602081d">drush_watchdog_severity_levels</a>();</div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;    <span class="keywordflow">if</span> (isset($severities[$severity])) {</div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;      $level = $severity;</div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;    }</div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;    elseif (($key = array_search($severity, $severities)) !== FALSE) {</div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;      $level = $key;</div>
<div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;    }</div>
<div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;      $level = FALSE;</div>
<div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;    }</div>
<div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;    <span class="keywordflow">if</span> ($level === FALSE) {</div>
<div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;      <span class="keywordflow">foreach</span> ($severities as $key =&gt; $value) {</div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;        $levels[] = <span class="stringliteral">&quot;$value($key)&quot;</span>;</div>
<div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;      }</div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;      $msg = <span class="stringliteral">&quot;Unknown severity level: !severity.\nValid severity levels are: !levels.&quot;</span>;</div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>($msg, array(<span class="stringliteral">&#39;!severity&#39;</span> =&gt; $severity, <span class="stringliteral">&#39;!levels&#39;</span> =&gt; implode(<span class="stringliteral">&#39;, &#39;</span>, $levels))));</div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;    }</div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;    $conditions[] = <span class="stringliteral">&#39;severity = :severity&#39;</span>;</div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;    $args[<span class="stringliteral">&#39;:severity&#39;</span>] = $level;</div>
<div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;  }</div>
<div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;  <span class="keywordflow">if</span> ($filter) {</div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;    $conditions[] = <span class="stringliteral">&quot;message LIKE :filter&quot;</span>;</div>
<div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;    $args[<span class="stringliteral">&#39;:filter&#39;</span>] = <span class="charliteral">&#39;%&#39;</span>.$filter.<span class="charliteral">&#39;%&#39;</span>;</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;  }</div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;</div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;  $where = implode(<span class="stringliteral">&quot; $criteria &quot;</span>, $conditions);</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;  <span class="keywordflow">return</span> array(<span class="stringliteral">&#39;where&#39;</span> =&gt; $where, <span class="stringliteral">&#39;args&#39;</span> =&gt; $args);</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Oct 8 2014 09:04:54 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>