0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-07 18:09:45 +00:00
nextcloud_server/lib/private/Files/Search/QueryOptimizer/ReplacingOptimizerStep.php
Andy Scherzinger dae7c159f7
chore: Add SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2024-05-24 13:11:22 +02:00

37 lines
1 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Files\Search\QueryOptimizer;
use OC\Files\Search\SearchBinaryOperator;
use OCP\Files\Search\ISearchOperator;
/**
* Optimizer step that can replace the $operator altogether instead of just modifying it
* These steps need some extra logic to properly replace the arguments of binary operators
*/
class ReplacingOptimizerStep extends QueryOptimizerStep {
/**
* Allow optimizer steps to modify query operators
*
* Returns true if the reference $operator points to a new value
*/
public function processOperator(ISearchOperator &$operator): bool {
if ($operator instanceof SearchBinaryOperator) {
$modified = false;
$arguments = $operator->getArguments();
foreach ($arguments as &$argument) {
if ($this->processOperator($argument)) {
$modified = true;
}
}
if ($modified) {
$operator->setArguments($arguments);
}
}
return false;
}
}