aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php
blob: 7f75731fe94ba732979096459179d4b85a8c674f (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
30
<?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);
	}

}