diff --git a/library/Icingadb/Util/ObjectSuggestionsCursor.php b/library/Icingadb/Util/ObjectSuggestionsCursor.php new file mode 100644 index 00000000..44b8c17d --- /dev/null +++ b/library/Icingadb/Util/ObjectSuggestionsCursor.php @@ -0,0 +1,25 @@ + $value) { + // TODO(lippserd): This is a quick and dirty fix for PostgreSQL binary datatypes for which PDO returns + // PHP resources that would cause exceptions since resources are not a valid type for attribute values. + // We need to do it this way as the suggestion implementation bypasses ORM behaviors here and there. + if (is_resource($value)) { + $value = stream_get_contents($value); + } + + yield $key => $value; + } + } +} diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index 0b0b2eae..a5ff35fb 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Model\Behavior\ReRoute; use Icinga\Module\Icingadb\Model\CustomvarFlat; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; +use Icinga\Module\Icingadb\Util\ObjectSuggestionsCursor; use ipl\Html\HtmlElement; use ipl\Orm\Exception\InvalidColumnException; use ipl\Orm\Exception\InvalidRelationException; @@ -18,7 +19,6 @@ use ipl\Orm\Model; use ipl\Orm\Relation\BelongsToMany; use ipl\Orm\Resolver; use ipl\Orm\UnionModel; -use ipl\Sql\Cursor; use ipl\Sql\Expression; use ipl\Sql\Select; use ipl\Stdlib\Filter; @@ -161,7 +161,7 @@ class ObjectSuggestions extends Suggestions $this->applyRestrictions($query); try { - return (new Cursor($query->getDb(), $query->assembleSelect()->distinct())) + return (new ObjectSuggestionsCursor($query->getDb(), $query->assembleSelect()->distinct())) ->setFetchMode(PDO::FETCH_COLUMN); } catch (InvalidColumnException $e) { throw new SearchException(sprintf(t('"%s" is not a valid column'), $e->getColumn()));