mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Utilize ipl\Orm\Query::filter() where appropriate
This commit is contained in:
parent
3e2222cd7e
commit
18f009c55f
8 changed files with 30 additions and 40 deletions
|
|
@ -10,7 +10,6 @@ use Icinga\Module\Icingadb\Model\Hostgroupsummary;
|
|||
use Icinga\Module\Icingadb\Web\Controller;
|
||||
use Icinga\Module\Icingadb\Widget\HostList;
|
||||
use Icinga\Module\Icingadb\Widget\ItemList\HostgroupList;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Stdlib\Filter;
|
||||
|
||||
class HostgroupController extends Controller
|
||||
|
|
@ -26,10 +25,9 @@ class HostgroupController extends Controller
|
|||
|
||||
$query = Hostgroupsummary::on($this->getDb());
|
||||
|
||||
FilterProcessor::apply(
|
||||
Filter::equal('hostgroup.name', $name),
|
||||
$query
|
||||
);
|
||||
foreach ($query->getUnions() as $unionPart) {
|
||||
$unionPart->filter(Filter::equal('hostgroup.name', $name));
|
||||
}
|
||||
|
||||
$this->applyRestrictions($query);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use Icinga\Module\Icingadb\Widget\Detail\ObjectsDetail;
|
|||
use Icinga\Module\Icingadb\Widget\HostList;
|
||||
use Icinga\Module\Icingadb\Widget\HostStatusBar;
|
||||
use Icinga\Module\Icingadb\Widget\ShowMore;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Filter\QueryString;
|
||||
use ipl\Web\Url;
|
||||
|
|
@ -145,7 +144,7 @@ class HostsController extends Controller
|
|||
$comments = Host::on($db)->with(['comment']);
|
||||
$comments->getWith()['host.comment']->setJoinType('INNER');
|
||||
// TODO: This should be automatically done by the model/resolver and added as ON condition
|
||||
FilterProcessor::apply(Filter::equal('comment.object_type', 'host'), $comments);
|
||||
$comments->filter(Filter::equal('comment.object_type', 'host'));
|
||||
$this->filter($comments);
|
||||
$summary->comments_total = $comments->count();
|
||||
|
||||
|
|
@ -185,13 +184,8 @@ class HostsController extends Controller
|
|||
|
||||
switch ($this->getRequest()->getActionName()) {
|
||||
case 'acknowledge':
|
||||
FilterProcessor::apply(
|
||||
Filter::all([
|
||||
Filter::equal('state.is_problem', 'y'),
|
||||
Filter::equal('state.is_acknowledged', 'n')
|
||||
]),
|
||||
$hosts
|
||||
);
|
||||
$hosts->filter(Filter::equal('state.is_problem', 'y'))
|
||||
->filter(Filter::equal('state.is_acknowledged', 'n'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use Icinga\Module\Icingadb\Model\ServicegroupSummary;
|
|||
use Icinga\Module\Icingadb\Web\Controller;
|
||||
use Icinga\Module\Icingadb\Widget\ServiceList;
|
||||
use Icinga\Module\Icingadb\Widget\ItemList\ServicegroupList;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Stdlib\Filter;
|
||||
|
||||
class ServicegroupController extends Controller
|
||||
|
|
@ -26,10 +25,9 @@ class ServicegroupController extends Controller
|
|||
|
||||
$query = ServicegroupSummary::on($this->getDb());
|
||||
|
||||
FilterProcessor::apply(
|
||||
Filter::equal('servicegroup.name', $name),
|
||||
$query
|
||||
);
|
||||
foreach ($query->getUnions() as $unionPart) {
|
||||
$unionPart->filter(Filter::equal('servicegroup.name', $name));
|
||||
}
|
||||
|
||||
$this->applyRestrictions($query);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use Icinga\Module\Icingadb\Widget\Detail\ObjectsDetail;
|
|||
use Icinga\Module\Icingadb\Widget\ServiceList;
|
||||
use Icinga\Module\Icingadb\Widget\ServiceStatusBar;
|
||||
use Icinga\Module\Icingadb\Widget\ShowMore;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Filter\QueryString;
|
||||
use ipl\Web\Url;
|
||||
|
|
@ -153,6 +152,8 @@ class ServicesController extends Controller
|
|||
|
||||
$comments = Service::on($db)->with(['comment']);
|
||||
$comments->getWith()['service.comment']->setJoinType('INNER');
|
||||
// TODO: This should be automatically done by the model/resolver and added as ON condition
|
||||
$comments->filter(Filter::equal('comment.object_type', 'service'));
|
||||
$this->filter($comments);
|
||||
$summary->comments_total = $comments->count();
|
||||
|
||||
|
|
@ -196,13 +197,8 @@ class ServicesController extends Controller
|
|||
|
||||
switch ($this->getRequest()->getActionName()) {
|
||||
case 'acknowledge':
|
||||
FilterProcessor::apply(
|
||||
Filter::all([
|
||||
Filter::equal('state.is_problem', 'y'),
|
||||
Filter::equal('state.is_acknowledged', 'n')
|
||||
]),
|
||||
$services
|
||||
);
|
||||
$services->filter(Filter::equal('state.is_problem', 'y'))
|
||||
->filter(Filter::equal('state.is_acknowledged', 'n'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ trait Auth
|
|||
}
|
||||
}
|
||||
|
||||
FilterProcessor::apply($queryFilter, $query);
|
||||
$query->filter($queryFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
|
|||
use Icinga\Module\Icingadb\Model\CustomvarFlat;
|
||||
use InvalidArgumentException;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Orm\Model;
|
||||
use ipl\Orm\Relation\BelongsToMany;
|
||||
use ipl\Orm\Resolver;
|
||||
|
|
@ -144,7 +143,7 @@ class ObjectSuggestions extends Suggestions
|
|||
// resolve the filter leads to false-positives.
|
||||
$flatnameFilter->noOptimization = true;
|
||||
|
||||
FilterProcessor::apply($flatnameFilter, $query);
|
||||
$query->filter($flatnameFilter);
|
||||
}
|
||||
|
||||
$inputFilter = Filter::equal($columnPath, $searchTerm);
|
||||
|
|
@ -153,14 +152,14 @@ class ObjectSuggestions extends Suggestions
|
|||
|
||||
// This had so many iterations, if it still doesn't work, consider removing it entirely :(
|
||||
if ($searchFilter instanceof Filter\None) {
|
||||
FilterProcessor::apply($inputFilter, $query);
|
||||
$query->filter($inputFilter);
|
||||
} elseif ($searchFilter instanceof Filter\All) {
|
||||
$searchFilter->add($inputFilter);
|
||||
} else {
|
||||
$searchFilter = $inputFilter;
|
||||
}
|
||||
|
||||
FilterProcessor::apply($searchFilter, $query);
|
||||
$query->filter($searchFilter);
|
||||
$this->applyRestrictions($query);
|
||||
|
||||
try {
|
||||
|
|
@ -253,7 +252,7 @@ class ObjectSuggestions extends Suggestions
|
|||
|
||||
$customVars->columns('flatname');
|
||||
$this->applyRestrictions($customVars);
|
||||
FilterProcessor::apply(Filter::equal('flatname', $searchTerm), $customVars);
|
||||
$customVars->filter(Filter::equal('flatname', $searchTerm));
|
||||
$idColumn = $resolver->qualifyColumnsAndAliases((array) 'id', $customVars->getModel(), false);
|
||||
$customVars = $customVars->assembleSelect();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ use InvalidArgumentException;
|
|||
use ipl\Html\Html;
|
||||
use ipl\Html\ValidHtml;
|
||||
use ipl\Orm\Common\SortUtil;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Orm\Query;
|
||||
use ipl\Orm\UnionQuery;
|
||||
use ipl\Stdlib\Contract\Paginatable;
|
||||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Compat\CompatController;
|
||||
|
|
@ -354,7 +354,13 @@ class Controller extends CompatController
|
|||
{
|
||||
$this->applyRestrictions($query);
|
||||
|
||||
FilterProcessor::apply($filter ?: $this->getFilter(), $query);
|
||||
if ($query instanceof UnionQuery) {
|
||||
foreach ($query->getUnions() as $query) {
|
||||
$query->filter($filter ?: $this->getFilter());
|
||||
}
|
||||
} else {
|
||||
$query->filter($filter ?: $this->getFilter());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ use ipl\Html\BaseHtmlElement;
|
|||
use ipl\Html\Html;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\HtmlString;
|
||||
use ipl\Orm\Compat\FilterProcessor;
|
||||
use ipl\Orm\ResultSet;
|
||||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Widget\Icon;
|
||||
|
|
@ -120,7 +119,7 @@ class ObjectDetail extends BaseHtmlElement
|
|||
->limit(3)
|
||||
->peekAhead();
|
||||
// TODO: This should be automatically done by the model/resolver and added as ON condition
|
||||
FilterProcessor::apply(Filter::equal('object_type', $this->objectType), $comments);
|
||||
$comments->filter(Filter::equal('object_type', $this->objectType));
|
||||
|
||||
$comments = $comments->execute();
|
||||
/** @var ResultSet $comments */
|
||||
|
|
@ -170,7 +169,7 @@ class ObjectDetail extends BaseHtmlElement
|
|||
->limit(3)
|
||||
->peekAhead();
|
||||
// TODO: This should be automatically done by the model/resolver and added as ON condition
|
||||
FilterProcessor::apply(Filter::equal('object_type', $this->objectType), $downtimes);
|
||||
$downtimes->filter(Filter::equal('object_type', $this->objectType));
|
||||
|
||||
$downtimes = $downtimes->execute();
|
||||
/** @var ResultSet $downtimes */
|
||||
|
|
@ -409,14 +408,14 @@ class ObjectDetail extends BaseHtmlElement
|
|||
);
|
||||
|
||||
$userQuery = User::on($this->getDb());
|
||||
FilterProcessor::apply($objectFilter, $userQuery);
|
||||
$userQuery->filter($objectFilter);
|
||||
$this->applyRestrictions($userQuery);
|
||||
foreach ($userQuery as $user) {
|
||||
$users[$user->name] = $user;
|
||||
}
|
||||
|
||||
$usergroupQuery = Usergroup::on($this->getDb());
|
||||
FilterProcessor::apply($objectFilter, $usergroupQuery);
|
||||
$usergroupQuery->filter($objectFilter);
|
||||
$this->applyRestrictions($usergroupQuery);
|
||||
foreach ($usergroupQuery as $usergroup) {
|
||||
$usergroups[$usergroup->name] = $usergroup;
|
||||
|
|
|
|||
Loading…
Reference in a new issue