aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php
blob: c573e3af3c055463b8b67335755ca88542ffc72e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

namespace OC\Files\Search\QueryOptimizer;

use OC\Files\Search\SearchBinaryOperator;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchOperator;

class FlattenNestedBool extends QueryOptimizerStep {
	public function processOperator(ISearchOperator &$operator) {
		if (
			$operator instanceof SearchBinaryOperator && (
				$operator->getType() === ISearchBinaryOperator::OPERATOR_OR ||
				$operator->getType() === ISearchBinaryOperator::OPERATOR_AND
			)
		) {
			$newArguments = [];
			foreach ($operator->getArguments() as $oldArgument) {
				if ($oldArgument instanceof SearchBinaryOperator && $oldArgument->getType() === $operator->getType()) {
					$newArguments = array_merge($newArguments, $oldArgument->getArguments());
				} else {
					$newArguments[] = $oldArgument;
				}
			}
			$operator->setArguments($newArguments);
		}
		parent::processOperator($operator);
	}
}