Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DependencyNode: Add fix for host join #1081

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions library/Icingadb/Model/DependencyNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;
use ipl\Sql\Connection;
use ipl\Sql\Select;

/**
* Dependency node model.
Expand All @@ -27,6 +29,43 @@
*/
class DependencyNode extends Model
{
public static function on(Connection $db): Query
{
$query = parent::on($db);

//TODO: only workaround, remove once https://github.com/Icinga/ipl-orm/issues/76#issuecomment-2370629031
// is fixed
$query->on(Query::ON_SELECT_ASSEMBLED, function (Select $select) {
$where = $select->getWhere();
$filter = 'dependency_node.id IN (?)';
if (! isset($where[1][0][1][0][1][$filter])) {
return;
}

$subQuery = $where[1][0][1][0][1][$filter];
$select->resetWhere();

$joins = $subQuery->getJoin();
$subQuery->resetJoin();

foreach ($joins as $join) {
$condition = $join[2];
if ($condition[1][0] === 'sub_host_dependency_node.host_id = sub_host.id') {
$condition[1][0] = sprintf(
'%s AND sub_host_dependency_node.service_id IS NULL',
$condition[1][0]
);
}

$subQuery->join($join[1], $condition);
}

$select->where([$filter => $subQuery]);
});

return $query;
}

public function getTableName(): string
{
return 'dependency_node';
Expand Down
Loading