diff --git a/monitoring.module b/monitoring.module index 6835099..290a5a2 100644 --- a/monitoring.module +++ b/monitoring.module @@ -266,6 +266,32 @@ function monitoring_sensor_result_last($sensor_name) { } /** + * Gets second last sensor result. + * + * @deprecated since 8.x-1.x (to be removed in 8.x-2.0). + * + * @param string $sensor_name + * The name of the sensor. + * + * @return \Drupal\monitoring\Entity\SensorResultEntity|null + * A SensorResultEntity representing the second last sensor result. + */ +function monitoring_sensor_result_second_last($sensor_name) { + $result = \Drupal::entityQuery('monitoring_sensor_result') + ->condition('sensor_name', $sensor_name) + ->sort('timestamp', 'DESC') + ->sort('record_id', 'DESC') + ->range(1, 1) + ->execute(); + + if (!empty($result)) { + return entity_load('monitoring_sensor_result', reset($result)); + } + + return NULL; +} + +/** * Implements hook_views_pre_render(). * * Alters the views page title. diff --git a/src/Result/SensorResult.php b/src/Result/SensorResult.php index e12d209..e449502 100644 --- a/src/Result/SensorResult.php +++ b/src/Result/SensorResult.php @@ -4,7 +4,7 @@ namespace Drupal\monitoring\Result; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; -use Drupal\monitoring\Entity\SensorResultEntity; +use Drupal\monitoring\Entity\SensorResultDataInterface; use Drupal\monitoring\Sensor\SensorCompilationException; use Drupal\monitoring\Entity\SensorConfig; use Drupal\monitoring\Sensor\Thresholds; @@ -64,7 +64,7 @@ class SensorResult implements SensorResultInterface { /** * The previous sensor result. * - * @var \Drupal\monitoring\Entity\SensorResultEntity|null + * @var \Drupal\monitoring\Entity\SensorResultDataInterface|null */ protected $previousResult = NULL; @@ -519,7 +519,7 @@ class SensorResult implements SensorResultInterface { /** * {@inheritdoc} */ - public function setPreviousResult(SensorResultEntity $previous_result = NULL) { + public function setPreviousResult(SensorResultDataInterface $previous_result = NULL) { $this->previousResult = $previous_result; } diff --git a/src/Result/SensorResultInterface.php b/src/Result/SensorResultInterface.php index d740161..3bb8fe8 100644 --- a/src/Result/SensorResultInterface.php +++ b/src/Result/SensorResultInterface.php @@ -3,7 +3,6 @@ namespace Drupal\monitoring\Result; use Drupal\monitoring\Entity\SensorResultDataInterface; -use Drupal\monitoring\Entity\SensorResultEntity; /** * Interface for a sensor result. @@ -198,16 +197,16 @@ interface SensorResultInterface extends SensorResultDataInterface { /** * Sets the previous sensor result. * - * @param \Drupal\monitoring\Entity\SensorResultEntity|null $previous_result + * @param \Drupal\monitoring\Entity\SensorResultDataInterface|null $previous_result * A SensorResultEntity representing the previous sensor result to set. * NULL if there is no previous result. */ - public function setPreviousResult(SensorResultEntity $previous_result = NULL); + public function setPreviousResult(SensorResultDataInterface $previous_result = NULL); /** * Gets the previous sensor result. * - * @return \Drupal\monitoring\Entity\SensorResultEntity|null + * @return \Drupal\monitoring\Entity\SensorResultDataInterface|null * A SensorResultEntity representing the previous sensor result. NULL if * there is no previous result. */ diff --git a/tests/src/Kernel/MonitoringCoreKernelTest.php b/tests/src/Kernel/MonitoringCoreKernelTest.php index 281440d..f70a8fc 100644 --- a/tests/src/Kernel/MonitoringCoreKernelTest.php +++ b/tests/src/Kernel/MonitoringCoreKernelTest.php @@ -9,8 +9,6 @@ namespace Drupal\Tests\monitoring\Kernel; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Logger\RfcLogLevel; use Drupal\monitoring\Entity\SensorConfig; -use Drupal\monitoring\Entity\SensorResultEntity; -use Drupal\monitoring\Result\SensorResult; use Drupal\monitoring\Result\SensorResultInterface; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType;