-
Notifications
You must be signed in to change notification settings - Fork 29
Show root problem list for objects with problem and are part of dependency #1057
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
Changes from all commits
0e67df5
e22bd1b
7aecb99
5ed7840
4d5b28d
ee0a4fd
cd70de4
bfb4c51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model\Behavior; | ||
|
||
use Icinga\Module\Icingadb\Model\DependencyEdge; | ||
use ipl\Orm\AliasedExpression; | ||
use ipl\Orm\ColumnDefinition; | ||
use ipl\Orm\Exception\InvalidColumnException; | ||
use ipl\Orm\Query; | ||
use ipl\Sql\Expression; | ||
use ipl\Stdlib\Filter; | ||
use ipl\Orm\Contract\RewriteColumnBehavior; | ||
use ipl\Orm\Contract\QueryAwareBehavior; | ||
|
||
/** | ||
* Behavior to check if the service has a problematic parent | ||
*/ | ||
class HasProblematicParent implements RewriteColumnBehavior, QueryAwareBehavior | ||
{ | ||
/** @var Query */ | ||
protected $query; | ||
|
||
public function setQuery(Query $query): self | ||
{ | ||
$this->query = $query; | ||
|
||
return $this; | ||
} | ||
|
||
public function rewriteColumn($column, ?string $relation = null): ?AliasedExpression | ||
{ | ||
if (! $this->isSelectableColumn($column)) { | ||
Check failure on line 34 in library/Icingadb/Model/Behavior/HasProblematicParent.php
|
||
return null; | ||
} | ||
|
||
$resolver = $this->query->getResolver(); | ||
if ($relation !== null) { | ||
$serviceTableAlias = $resolver->getAlias($resolver->resolveRelation($relation)->getTarget()); | ||
$column = $resolver->qualifyColumnAlias($column, $serviceTableAlias); | ||
Check failure on line 41 in library/Icingadb/Model/Behavior/HasProblematicParent.php
|
||
} else { | ||
$serviceTableAlias = $resolver->getAlias($this->query->getModel()); | ||
} | ||
|
||
$subQueryModel = new DependencyEdge(); | ||
$subQuery = (new Query()) | ||
->setDb($this->query->getDb()) | ||
->setModel($subQueryModel) | ||
->columns([new Expression('1')]) | ||
->utilize('from') | ||
->limit(1) | ||
->filter(Filter::equal('dependency.state.failed', 'y')); | ||
|
||
$subQueryResolver = $subQuery->getResolver()->setAliasPrefix('hpp_'); | ||
$subQueryTarget = $subQueryResolver->resolveRelation($subQueryModel->getTableName() . '.from')->getTarget(); | ||
$targetForeignKey = $subQueryResolver->qualifyColumn( | ||
'service_id', | ||
$subQueryResolver->getAlias($subQueryTarget) | ||
); | ||
|
||
$subQuery->getSelectBase() | ||
->where("$targetForeignKey = {$resolver->qualifyColumn('id', $serviceTableAlias)}"); | ||
|
||
[$select, $values] = $this->query->getDb() | ||
->getQueryBuilder() | ||
->assembleSelect($subQuery->assembleSelect()); | ||
|
||
return new AliasedExpression( | ||
$this->query->getDb()->quoteIdentifier([$column]), | ||
"($select)", | ||
null, | ||
...$values | ||
); | ||
} | ||
|
||
public function isSelectableColumn(string $name): bool | ||
{ | ||
return $name === 'has_problematic_parent'; | ||
} | ||
|
||
public function rewriteColumnDefinition(ColumnDefinition $def, string $relation): void | ||
{ | ||
} | ||
|
||
public function rewriteCondition(Filter\Condition $condition, $relation = null) | ||
{ | ||
$column = substr($condition->getColumn(), strlen($relation ?? '')); | ||
|
||
if ($this->isSelectableColumn($column)) { | ||
throw new InvalidColumnException($column, $this->query->getModel()); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.