FlattenNestedBool.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Files\Search\QueryOptimizer;
  7. use OC\Files\Search\SearchBinaryOperator;
  8. use OCP\Files\Search\ISearchBinaryOperator;
  9. use OCP\Files\Search\ISearchOperator;
  10. class FlattenNestedBool extends QueryOptimizerStep {
  11. public function processOperator(ISearchOperator &$operator) {
  12. if (
  13. $operator instanceof SearchBinaryOperator && (
  14. $operator->getType() === ISearchBinaryOperator::OPERATOR_OR ||
  15. $operator->getType() === ISearchBinaryOperator::OPERATOR_AND
  16. )
  17. ) {
  18. $newArguments = [];
  19. foreach ($operator->getArguments() as $oldArgument) {
  20. if ($oldArgument instanceof SearchBinaryOperator && $oldArgument->getType() === $operator->getType()) {
  21. $newArguments = array_merge($newArguments, $oldArgument->getArguments());
  22. } else {
  23. $newArguments[] = $oldArgument;
  24. }
  25. }
  26. $operator->setArguments($newArguments);
  27. }
  28. parent::processOperator($operator);
  29. }
  30. }