Skip to content

Commit

Permalink
fix: HasRootProblem behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 11, 2024
1 parent eb503ec commit 243c129
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions library/Icingadb/Model/Behavior/HasRootProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,32 @@ public function rewriteColumn($column, ?string $relation = null): ?AliasedExpres
return null;
}

$path = 'from.dependency_node';
$path = 'from.';
$subQueryRelation = $relation !== null ? $relation . $path : $path;
$subQuery = $this->query->createSubQuery(new DependencyEdge(), $subQueryRelation)
$subQuery = $this->query->createSubQuery(new DependencyEdge(), $subQueryRelation, null, false)
->limit(1)
->columns([new Expression('1')]);

$subQuery->getSelectBase()->join(
['root_dependency' => 'dependency'],
[$subQuery->getResolver()->getAlias($subQuery->getModel()) . '.dependency_id = root_dependency.id']
)->join(
['root_dependency_state' => 'dependency_state'],
['root_dependency.id = root_dependency_state.dependency_id']
)->where(new Expression("root_dependency_state.failed = 'y'"));
$subQuery->getSelectBase()->resetWhere();
$subQueryAlias = $subQuery->getResolver()->getAlias($subQuery->getModel());

$subQuery->getSelectBase()
->join(
['to_dependency_node' => 'dependency_node'],
["to_dependency_node.id = $subQueryAlias.to_node_id"]
)->joinLeft(
['root_dependency' => 'dependency'],
[ "$subQueryAlias.dependency_id = root_dependency.id"]
)->joinLeft(
['root_dependency_state' => 'dependency_state'],
['root_dependency.id = root_dependency_state.dependency_id']
)->joinLeft(
['root_group' => 'redundancy_group'],
['root_group.id = to_dependency_node.redundancy_group_id']
)->joinLeft(
['root_group_state' => 'redundancy_group_state'],
['root_group_state.redundancy_group_id = root_group.id']
)->where(new Expression("root_dependency_state.failed = 'y' OR root_group_state.failed = 'y'"));

$column = $relation !== null ? str_replace('.', '_', $relation) . "_$column" : $column;

Expand Down

0 comments on commit 243c129

Please sign in to comment.