From 9abc3b4d8fa9ccef72a637c10bc734207cdc51d4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 25 Mar 2022 16:34:46 +0100 Subject: [PATCH] Stop using Resolver without a Query --- library/Icingadb/Redis/VolatileStateResults.php | 14 +++++++++++++- .../Web/Control/SearchBar/ObjectSuggestions.php | 11 +++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/library/Icingadb/Redis/VolatileStateResults.php b/library/Icingadb/Redis/VolatileStateResults.php index 86cceb7a..5ad1d404 100644 --- a/library/Icingadb/Redis/VolatileStateResults.php +++ b/library/Icingadb/Redis/VolatileStateResults.php @@ -9,15 +9,27 @@ use Icinga\Application\Benchmark; use Icinga\Module\Icingadb\Common\IcingaRedis; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; +use ipl\Orm\Query; use ipl\Orm\Resolver; use ipl\Orm\ResultSet; use RuntimeException; class VolatileStateResults extends ResultSet { + /** @var Resolver */ + private $resolver; + /** @var bool Whether Redis updates were applied */ private $updatesApplied = false; + public static function fromQuery(Query $query) + { + $self = parent::fromQuery($query); + $self->resolver = $query->getResolver(); + + return $self; + } + public function current() { if (! $this->updatesApplied && ! $this->isCacheDisabled) { @@ -59,7 +71,7 @@ class VolatileStateResults extends ResultSet $hostStates = []; foreach ($this as $row) { if ($type === null) { - $behaviors = (new Resolver())->getBehaviors($row->state); + $behaviors = $this->resolver->getBehaviors($row->state); switch (true) { case $row instanceof Host: diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index 741c04c7..e21c958b 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -169,8 +169,11 @@ class ObjectSuggestions extends Suggestions protected function fetchColumnSuggestions($searchTerm) { + $model = $this->getModel(); + $query = $model::on($this->getDb()); + // Ordinary columns first - foreach (self::collectFilterColumns($this->getModel()) as $columnName => $columnMeta) { + foreach (self::collectFilterColumns($model, $query->getResolver()) as $columnName => $columnMeta) { yield $columnName => $columnMeta; } @@ -269,12 +272,8 @@ class ObjectSuggestions extends Suggestions * * @return Generator */ - public static function collectFilterColumns(Model $model, Resolver $resolver = null): Generator + public static function collectFilterColumns(Model $model, Resolver $resolver): Generator { - if ($resolver === null) { - $resolver = new Resolver(); - } - $metaData = $resolver->getMetaData($model); foreach ($metaData as $columnName => $columnMeta) { yield $columnName => $columnMeta;