Use Query::filter() for applying WHERE conditions

This commit is contained in:
Eric Lippmann 2022-03-29 14:39:50 +02:00 committed by Johannes Meyer
parent df886f6e94
commit 04410a866d
8 changed files with 30 additions and 35 deletions

View file

@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Model\Comment;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\CommentDetail;
use Icinga\Module\Icingadb\Widget\ItemList\CommentList;
use ipl\Stdlib\Filter;
use ipl\Web\Url;
class CommentController extends Controller
@ -34,9 +35,7 @@ class CommentController extends Controller
'service.host',
'service.host.state'
]);
$query->getSelectBase()
->where(['comment.name = ?' => $name]);
$query->filter(Filter::equal('comment.name', $name));
$this->applyRestrictions($query);

View file

@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Model\Downtime;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\DowntimeDetail;
use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList;
use ipl\Stdlib\Filter;
use ipl\Web\Url;
class DowntimeController extends Controller
@ -44,8 +45,7 @@ class DowntimeController extends Controller
'triggered_by.service',
'triggered_by.service.state'
]);
$query->getSelectBase()
->where(['downtime.name = ?' => $name]);
$query->filter(Filter::equal('downtime.name', $name));
$this->applyRestrictions($query);

View file

@ -41,9 +41,9 @@ class HostController extends Controller
$name = $this->params->getRequired('name');
$query = Host::on($this->getDb())->with(['state', 'icon_image']);
$query->setResultSetClass(VolatileStateResults::class);
$query->getSelectBase()
->where(['host.name = ?' => $name]);
$query
->setResultSetClass(VolatileStateResults::class)
->filter(Filter::equal('host.name', $name));
$this->applyRestrictions($query);
@ -63,8 +63,7 @@ class HostController extends Controller
public function indexAction()
{
$serviceSummary = ServicestateSummary::on($this->getDb())->with('state');
$serviceSummary->getSelectBase()
->where(['service.host_id = ?' => $this->host->id]);
$serviceSummary->filter(Filter::equal('service.host_id', $this->host->id));
$this->applyRestrictions($serviceSummary);
@ -193,11 +192,9 @@ class HostController extends Controller
'host',
'host.state'
]);
$services->setResultSetClass(VolatileStateResults::class);
$services
->getSelectBase()
->where(['service_host.id = ?' => $this->host->id]);
->setResultSetClass(VolatileStateResults::class)
->filter(Filter::equal('host.id', $this->host->id));
$this->applyRestrictions($services);

View file

@ -50,9 +50,9 @@ class HostgroupController extends Controller
$db = $this->getDb();
$hosts = Host::on($db)->with(['state', 'state.last_comment', 'icon_image'])->utilize('hostgroup');
$hosts->setResultSetClass(VolatileStateResults::class);
$hosts->getSelectBase()->where(['host_hostgroup.id = ?' => $this->hostgroup->id]);
$hosts
->setResultSetClass(VolatileStateResults::class)
->filter(Filter::equal('hostgroup.id', $this->hostgroup->id));
$this->applyRestrictions($hosts);
$limitControl = $this->createLimitControl();

View file

@ -43,11 +43,12 @@ class ServiceController extends Controller
'host',
'host.state'
]);
$query->setResultSetClass(VolatileStateResults::class);
$query->getSelectBase()
->where(['service.name = ?' => $name])
->where(['service_host.name = ?' => $hostName]);
$query
->setResultSetClass(VolatileStateResults::class)
->filter(Filter::all(
Filter::equal('service.name', $name),
Filter::equal('host.name', $hostName)
));
$this->applyRestrictions($query);
@ -127,13 +128,10 @@ class ServiceController extends Controller
'acknowledgement',
'state'
]);
$history
->getSelectBase()
->where([
'history.host_id = ?' => $this->service->host_id,
'history.service_id = ?' => $this->service->id
]);
$history->filter(Filter::all(
Filter::equal('history.host_id', $this->service->host_id),
Filter::equal('history.service_id', $this->service->id)
));
$before = $this->params->shift('before', time());
$url = Url::fromRequest()->setParams(clone $this->params);

View file

@ -55,9 +55,10 @@ class ServicegroupController extends Controller
'host',
'host.state'
])->utilize('servicegroup');
$services->setResultSetClass(VolatileStateResults::class);
$services
->setResultSetClass(VolatileStateResults::class)
->filter(Filter::equal('servicegroup.id', $this->servicegroup->id));
$services->getSelectBase()->where(['service_servicegroup.id = ?' => $this->servicegroup->id]);
$this->applyRestrictions($services);
$limitControl = $this->createLimitControl();

View file

@ -9,6 +9,7 @@ use Icinga\Module\Icingadb\Model\User;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\UserDetail;
use Icinga\Module\Icingadb\Widget\ItemList\UserList;
use ipl\Stdlib\Filter;
class UserController extends Controller
{
@ -24,8 +25,7 @@ class UserController extends Controller
$name = $this->params->getRequired('name');
$query = User::on($this->getDb());
$query->getSelectBase()
->where(['user.name = ?' => $name]);
$query->filter(Filter::equal('user.name', $name));
$this->applyRestrictions($query);

View file

@ -9,6 +9,7 @@ use Icinga\Module\Icingadb\Model\Usergroup;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\UsergroupDetail;
use Icinga\Module\Icingadb\Widget\ItemList\UsergroupList;
use ipl\Stdlib\Filter;
class UsergroupController extends Controller
{
@ -24,8 +25,7 @@ class UsergroupController extends Controller
$name = $this->params->getRequired('name');
$query = Usergroup::on($this->getDb());
$query->getSelectBase()
->where(['usergroup.name = ?' => $name]);
$query->filter(Filter::equal('usergroup.name', $name));
$this->applyRestrictions($query);