You are here

public function Dblog404SensorPlugin::getQuery in Monitoring 8

Builds the query for verbose output.

Similar to the aggregate query, but without aggregation.

Return value

\Drupal\Core\Database\Query\Select The select query object.

Overrides DatabaseAggregatorSensorPlugin::getQuery

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin::getAggregateQuery()

File

src/Plugin/monitoring/SensorPlugin/Dblog404SensorPlugin.php, line 52
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\Dblog404SensorPlugin.

Class

Dblog404SensorPlugin
Monitors 404 page errors from dblog.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function getQuery() {
  $query = parent::getQuery();
  $this
    ->addAggregateExpression($query);
  $query
    ->groupBy('location');

  // Get just the max timestamp, drop the rest.
  $fields =& $query
    ->getFields();
  unset($fields['timestamp']);
  $query
    ->addExpression('MAX(timestamp)', 'timestamp');

  // Drop the existing order, order by record count instead.
  $order =& $query
    ->getOrderBy();
  $order = [];
  $query
    ->orderBy('records_count', 'DESC');
  $query
    ->range(0, 20);
  return $query;
}