-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show root problem list for objects with problem and are part of depen…
…dency (#1057) ref #1050 blocked by: #1055 blocked by: Icinga/ipl-web#231, Icinga/ipl-web#234
- Loading branch information
Showing
20 changed files
with
672 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { | ||
return null; | ||
} | ||
|
||
$resolver = $this->query->getResolver(); | ||
if ($relation !== null) { | ||
$serviceTableAlias = $resolver->getAlias($resolver->resolveRelation($relation)->getTarget()); | ||
$column = $resolver->qualifyColumnAlias($column, $serviceTableAlias); | ||
} 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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.