mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Q&D fix for suggestions which bypass ORM behaviors
This commit is contained in:
parent
c41dbb80f4
commit
6c1850d732
2 changed files with 27 additions and 2 deletions
25
library/Icingadb/Util/ObjectSuggestionsCursor.php
Normal file
25
library/Icingadb/Util/ObjectSuggestionsCursor.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/* Icinga DB Web | (c) 2022 Icinga GmbH | GPLv2 */
|
||||
|
||||
namespace Icinga\Module\Icingadb\Util;
|
||||
|
||||
use ipl\Sql\Cursor;
|
||||
use Iterator;
|
||||
|
||||
class ObjectSuggestionsCursor extends Cursor
|
||||
{
|
||||
public function getIterator(): Iterator
|
||||
{
|
||||
foreach (parent::getIterator() as $key => $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()));
|
||||
|
|
|
|||
Loading…
Reference in a new issue