You are here

class SensorImageMissingStyle in Monitoring 7

Monitors image derivate creation errors from dblog.

Displays image derivate with highest occurrence as message.

Hierarchy

Expanded class hierarchy of SensorImageMissingStyle

File

lib/Drupal/monitoring/Sensor/Sensors/SensorImageMissingStyle.php, line 16
Contains \Drupal\monitoring\Sensor\Sensors\SensorImageMissingStyle.

Namespace

Drupal\monitoring\Sensor\Sensors
View source
class SensorImageMissingStyle extends SensorDatabaseAggregator {

  /**
   * The path of the most failed image.
   *
   * @var string
   */
  protected $sourceImagePath;

  /**
   * {@inheritdoc}
   */
  public function buildQuery() {

    // Extends the watchdog query.
    $query = parent::buildQuery();
    $query
      ->addField('watchdog', 'variables');
    $query
      ->groupBy('variables');
    $query
      ->orderBy('records_count', 'DESC');
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function runSensor(SensorResultInterface $result) {
    parent::runSensor($result);
    $query_result = $this
      ->fetchObject();
    if (!empty($query_result)) {
      $variables = unserialize($query_result->variables);
      if (isset($variables['%source_image_path'])) {
        $result
          ->addStatusMessage($variables['%source_image_path']);
        $this->sourceImagePath = $variables['%source_image_path'];
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function resultVerbose(SensorResultInterface $result) {
    $verbose = parent::resultVerbose($result);

    // If non found, no reason to query file_managed table.
    if ($result
      ->getValue() == 0) {
      return $verbose;
    }

    // In case we were not able to retrieve this info from the watchdog
    // variables.
    if (empty($this->sourceImagePath)) {
      $message = t('Source image path is empty, cannot query file_managed table');
    }
    $file = db_query('SELECT * FROM file_managed WHERE uri = :uri', array(
      ':uri' => $this->sourceImagePath,
    ))
      ->fetchObject();
    if (!empty($file)) {
      $message = t('File managed records: <pre>@file_managed</pre>', array(
        '@file_managed' => var_export(file_usage_list($file), TRUE),
      ));
    }
    if (empty($message)) {
      $message = t('File @file record not found in the file_managed table.', array(
        '@file' => $result
          ->getMessage(),
      ));
    }
    $verbose .= ' ' . $message;
    return $verbose;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Sensor::$info protected property Current sensor info object.
Sensor::getSensorName public function Gets sensor name (not the label). Overrides SensorInterface::getSensorName
Sensor::isEnabled public function Determines if sensor is enabled. Overrides SensorInterface::isEnabled
Sensor::__construct function Instantiates a sensor object. 1
SensorDatabaseAggregator::$fetchedObject protected property The fetched object from the query result.
SensorDatabaseAggregator::$queryArguments protected property The arguments of the executed query.
SensorDatabaseAggregator::$queryResult protected property The result of the db query execution.
SensorDatabaseAggregator::buildQueryAggregate protected function Adds aggregate expressions to the query.
SensorDatabaseAggregator::fetchObject public function Get fetched object from the executed query.
SensorDatabaseAggregator::getEntityTypeFromTable protected function Returns the entity type for a given base table.
SensorDatabaseAggregator::getFieldName protected function Returns the field name to use for a condition and ensures necessary joins.
SensorDatabaseAggregator::getQueryArguments protected function Returns query arguments of the last executed query.
SensorDatabaseAggregator::getQueryResult protected function Executes the query and returns the result.
SensorDatabaseAggregator::getTimeIntervalOptions protected function Returns time interval options.
SensorDatabaseAggregator::joinFieldTable protected function Joins the field data table for a given field.
SensorDatabaseAggregator::settingsForm public function Gets settings form for a specific sensor. Overrides SensorThresholds::settingsForm 1
SensorImageMissingStyle::$sourceImagePath protected property The path of the most failed image.
SensorImageMissingStyle::buildQuery public function Builds the database query. Overrides SensorDatabaseAggregator::buildQuery
SensorImageMissingStyle::resultVerbose public function Provide additional info about sensor call. Overrides SensorDatabaseAggregator::resultVerbose
SensorImageMissingStyle::runSensor public function Runs the sensor, updating $sensor_result. Overrides SensorDatabaseAggregator::runSensor
SensorThresholds::setFormError protected function Sets a form error for the given threshold key.
SensorThresholds::settingsFormValidate public function Form validator for a sensor settings form. Overrides SensorConfigurable::settingsFormValidate