1
0

ReplacingOptimizerStep.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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\ISearchOperator;
  9. /**
  10. * Optimizer step that can replace the $operator altogether instead of just modifying it
  11. * These steps need some extra logic to properly replace the arguments of binary operators
  12. */
  13. class ReplacingOptimizerStep extends QueryOptimizerStep {
  14. /**
  15. * Allow optimizer steps to modify query operators
  16. *
  17. * Returns true if the reference $operator points to a new value
  18. */
  19. public function processOperator(ISearchOperator &$operator): bool {
  20. if ($operator instanceof SearchBinaryOperator) {
  21. $modified = false;
  22. $arguments = $operator->getArguments();
  23. foreach ($arguments as &$argument) {
  24. if ($this->processOperator($argument)) {
  25. $modified = true;
  26. }
  27. }
  28. if ($modified) {
  29. $operator->setArguments($arguments);
  30. }
  31. }
  32. return false;
  33. }
  34. }