Skip to content

Commit

Permalink
Adjust usages of ipl\Stdlib\Filter::equal() and ::unequal()
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed May 24, 2022
1 parent 8f05906 commit 5b026f8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
7 changes: 4 additions & 3 deletions application/controllers/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\HistoryList;
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
use ipl\Sql\Sql;
use ipl\Stdlib\Filter;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
Expand Down Expand Up @@ -80,9 +79,11 @@ public function indexAction()
$this->filter($history, $filter);

$history->getWith()['history.host']->setJoinType('LEFT');
$history->getSelectBase()
$history->filter(Filter::any(
// Because of LEFT JOINs, make sure we'll fetch history entries only for items which still exist:
->where(['history_host.id IS NOT NULL', 'history_service.id IS NOT NULL'], Sql::ANY);
Filter::like('host.id', '*'),
Filter::like('service.id', '*')
));

yield $this->export($history);

Expand Down
10 changes: 4 additions & 6 deletions application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ public function historyAction()
'state'
]);

$history
->getSelectBase()
->where([
'history.host_id = ?' => $this->host->id,
'history.service_id IS NULL'
]);
$history->filter(Filter::all(
Filter::equal('history.host_id', $this->host->id),
Filter::unlike('history.service_id', '*')
));

$before = $this->params->shift('before', time());
$url = Url::fromRequest()->setParams(clone $this->params);
Expand Down
9 changes: 4 additions & 5 deletions application/controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ public function indexAction()

$notifications->filter(Filter::lessThanOrEqual('send_time', $before));
$this->filter($notifications, $filter);
$notifications->getSelectBase()
$notifications->filter(Filter::any(
// Make sure we'll fetch service history entries only for services which still exist
->where([
'notification_history.service_id IS NULL',
'notification_history_service.id IS NOT NULL'
], Sql::ANY);
Filter::unlike('service_id', '*'),
Filter::like('history.service.id', '*')
));

yield $this->export($notifications);

Expand Down
4 changes: 2 additions & 2 deletions library/Icingadb/Common/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function applyRestrictions(Query $query)
$this->forceQueryOptimization($serviceFilter, 'servicegroup.name');
}

$roleFilter->add(Filter::any(Filter::unequal('service.id', '*'), $serviceFilter));
$roleFilter->add(Filter::any(Filter::unlike('service.id', '*'), $serviceFilter));
}
}

Expand Down Expand Up @@ -322,7 +322,7 @@ protected function parseBlacklist(string $blacklist, string $column): Filter\Non
{
$filter = Filter::none();
foreach (explode(',', $blacklist) as $value) {
$filter->add(Filter::equal($column, trim($value)));
$filter->add(Filter::like($column, trim($value)));
}

return $filter;
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Compat/UrlMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ protected static function contactsColumns(): array
$receivesStateNotifications = function ($state, $type = null) {
return function ($filter) use ($state, $type) {
/** @var Filter\Condition $filter */
$negate = $filter instanceof Filter\Unequal;
$negate = $filter instanceof Filter\Unequal || $filter instanceof Filter\Unlike;
switch ($filter->getValue()) {
case '0':
$filter = Filter::any(
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/Behavior/FlattenedObjectVars.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function rewriteCondition(Filter\Condition $condition, $relation = null)

$column = $condition->metaData()->get('columnName');
if ($column !== null && $column !== 'flatname' && $column !== 'flatvalue') {
$nameFilter = Filter::equal($relation . 'flatname', $column);
$nameFilter = Filter::like($relation . 'flatname', $column);
$class = get_class($condition);
$valueFilter = new $class($relation . 'flatvalue', $condition->getValue());

Expand Down
8 changes: 4 additions & 4 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function createQuickSearchFilter($searchTerm)

$quickFilter = Filter::any();
foreach ($model->getSearchColumns() as $column) {
$where = Filter::equal($model->getTableName() . '.' . $column, $searchTerm);
$where = Filter::like($model->getTableName() . '.' . $column, $searchTerm);
$where->metaData()->set('columnLabel', $model->getMetaData()[$column]);
$quickFilter->add($where);
}
Expand Down Expand Up @@ -134,10 +134,10 @@ protected function fetchValueSuggestions($column, $searchTerm, Filter\Chain $sea

if (substr($targetPath, -5) === '.vars') {
$columnPath = $targetPath . '.flatvalue';
$query->filter(Filter::equal($targetPath . '.flatname', $columnName));
$query->filter(Filter::like($targetPath . '.flatname', $columnName));
}

$inputFilter = Filter::equal($columnPath, $searchTerm);
$inputFilter = Filter::like($columnPath, $searchTerm);
$query->columns($columnPath);
$query->orderBy($columnPath);

Expand Down Expand Up @@ -253,7 +253,7 @@ protected function queryCustomvarConfig(string $searchTerm): Select

$customVars->columns('flatname');
$this->applyRestrictions($customVars);
$customVars->filter(Filter::equal('flatname', $searchTerm));
$customVars->filter(Filter::like('flatname', $searchTerm));
$idColumn = $resolver->qualifyColumn('id', $resolver->getAlias($customVars->getModel()));
$customVars = $customVars->assembleSelect();

Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function handleSearchRequest(Query $query)

$filter = Filter::any();
foreach ($query->getModel()->getSearchColumns() as $column) {
$filter->add(Filter::equal($column, "*$q*"));
$filter->add(Filter::like($column, "*$q*"));
}

$requestUrl = Url::fromRequest();
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ protected function getUsersAndUsergroups(): array
if ($this->objectType === 'host') {
$objectFilter = Filter::all(
Filter::equal('notification.host_id', $this->object->id),
Filter::unequal('notification.service_id', '*')
Filter::unlike('notification.service_id', '*')
);
$objectFilter->metaData()->set('forceOptimization', false);
$groupBy = true;
Expand Down

0 comments on commit 5b026f8

Please sign in to comment.