FlattenNestedBool.php 909 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace OC\Files\Search\QueryOptimizer;
  3. use OC\Files\Search\SearchBinaryOperator;
  4. use OCP\Files\Search\ISearchBinaryOperator;
  5. use OCP\Files\Search\ISearchOperator;
  6. class FlattenNestedBool extends QueryOptimizerStep {
  7. public function processOperator(ISearchOperator &$operator) {
  8. if (
  9. $operator instanceof SearchBinaryOperator && (
  10. $operator->getType() === ISearchBinaryOperator::OPERATOR_OR ||
  11. $operator->getType() === ISearchBinaryOperator::OPERATOR_AND
  12. )
  13. ) {
  14. $newArguments = [];
  15. foreach ($operator->getArguments() as $oldArgument) {
  16. if ($oldArgument instanceof SearchBinaryOperator && $oldArgument->getType() === $operator->getType()) {
  17. $newArguments = array_merge($newArguments, $oldArgument->getArguments());
  18. } else {
  19. $newArguments[] = $oldArgument;
  20. }
  21. }
  22. $operator->setArguments($newArguments);
  23. }
  24. parent::processOperator($operator);
  25. }
  26. }