Auto commit for release 'develop' on 2025-01-05

This commit is contained in:
github-actions
2025-01-05 09:23:02 +01:00
parent 481bb3fb0a
commit b4c67c02a7
27 changed files with 228 additions and 204 deletions

View File

@@ -44,7 +44,6 @@ use FireflyIII\Support\Search\QueryParser\Node;
use FireflyIII\Support\Search\QueryParser\FieldNode;
use FireflyIII\Support\Search\QueryParser\StringNode;
use FireflyIII\Support\Search\QueryParser\NodeGroup;
use FireflyIII\Support\ParseDateString;
use FireflyIII\User;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -147,6 +146,7 @@ class OperatorQuerySearch implements SearchInterface
public function parseQuery(string $query): void
{
app('log')->debug(sprintf('Now in parseQuery("%s")', $query));
/** @var QueryParserInterface $parser */
$parser = app(QueryParserInterface::class);
app('log')->debug(sprintf('Using %s as implementation for QueryParserInterface', get_class($parser)));
@@ -182,18 +182,22 @@ class OperatorQuerySearch implements SearchInterface
switch (true) {
case $node instanceof StringNode:
$this->handleStringNode($node, $flipProhibitedFlag);
break;
case $node instanceof FieldNode:
$this->handleFieldNode($node, $flipProhibitedFlag);
break;
case $node instanceof NodeGroup:
$this->handleNodeGroup($node, $flipProhibitedFlag);
break;
default:
app('log')->error(sprintf('Cannot handle node %s', get_class($node)));
throw new FireflyException(sprintf('Firefly III search can\'t handle "%s"-nodes', get_class($node)));
}
}
@@ -207,19 +211,17 @@ class OperatorQuerySearch implements SearchInterface
}
}
private function handleStringNode(StringNode $node, bool $flipProhibitedFlag): void
{
$string = $node->getValue();
$string = $node->getValue();
$prohibited = $node->isProhibited($flipProhibitedFlag);
if($prohibited) {
if ($prohibited) {
app('log')->debug(sprintf('Exclude string "%s" from search string', $string));
$this->prohibitedWords[] = $string;
}
if(!$prohibited) {
if (!$prohibited) {
app('log')->debug(sprintf('Add string "%s" to search string', $string));
$this->words[] = $string;
}
@@ -230,39 +232,39 @@ class OperatorQuerySearch implements SearchInterface
*/
private function handleFieldNode(FieldNode $node, bool $flipProhibitedFlag): void
{
$operator = strtolower($node->getOperator());
$value = $node->getValue();
$operator = strtolower($node->getOperator());
$value = $node->getValue();
$prohibited = $node->isProhibited($flipProhibitedFlag);
$context = config(sprintf('search.operators.%s.needs_context', $operator));
$context = config(sprintf('search.operators.%s.needs_context', $operator));
// is an operator that needs no context, and value is false, then prohibited = true.
if ('false' === $value && in_array($operator, $this->validOperators, true) && false === $context && !$prohibited) {
$prohibited = true;
$value = 'true';
$value = 'true';
}
// if the operator is prohibited, but the value is false, do an uno reverse
if ('false' === $value && $prohibited && in_array($operator, $this->validOperators, true) && false === $context) {
$prohibited = false;
$value = 'true';
$value = 'true';
}
// must be valid operator:
$inArray = in_array($operator, $this->validOperators, true);
$inArray = in_array($operator, $this->validOperators, true);
if ($inArray) {
if ($this->updateCollector($operator, $value, $prohibited)) {
$this->operators->push([
'type' => self::getRootOperator($operator),
'value' => $value,
'type' => self::getRootOperator($operator),
'value' => $value,
'prohibited' => $prohibited,
]);
app('log')->debug(sprintf('Added operator type "%s"', $operator));
}
}
if(!$inArray) {
if (!$inArray) {
app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator));
$this->invalidOperators[] = [
'type' => $operator,
'type' => $operator,
'value' => $value,
];
}

View File

@@ -35,8 +35,8 @@ class FieldNode extends Node
public function __construct(string $operator, string $value, bool $prohibited = false)
{
$this->operator = $operator;
$this->value = $value;
$this->operator = $operator;
$this->value = $value;
$this->prohibited = $prohibited;
}

View File

@@ -41,17 +41,17 @@ class GdbotsQueryParser implements QueryParserInterface
}
/**
* @return NodeGroup
* @throws FireflyException
*/
public function parse(string $query): NodeGroup
{
try {
$result = $this->parser->parse($query);
$nodes = array_map(
fn(GdbotsNode\Node $node) => $this->convertNode($node),
$nodes = array_map(
fn (GdbotsNode\Node $node) => $this->convertNode($node),
$result->getNodes()
);
return new NodeGroup($nodes);
} catch (\LogicException|\TypeError $e) {
fwrite(STDERR, "Setting up GdbotsQueryParserTest\n");
@@ -78,9 +78,10 @@ class GdbotsQueryParser implements QueryParserInterface
case $node instanceof GdbotsNode\Subquery:
Log::debug('Subquery');
return new NodeGroup(
array_map(
fn(GdbotsNode\Node $subNode) => $this->convertNode($subNode),
fn (GdbotsNode\Node $subNode) => $this->convertNode($subNode),
$node->getNodes()
)
);

View File

@@ -47,10 +47,11 @@ abstract class Node
public function isProhibited(bool $flipFlag): bool
{
if ($flipFlag) {
//Log::debug(sprintf('This %s is (flipped) now prohibited: %s',get_class($this), var_export(!$this->prohibited, true)));
// Log::debug(sprintf('This %s is (flipped) now prohibited: %s',get_class($this), var_export(!$this->prohibited, true)));
return !$this->prohibited;
}
//Log::debug(sprintf('This %s is (not flipped) now prohibited: %s',get_class($this), var_export($this->prohibited, true)));
// Log::debug(sprintf('This %s is (not flipped) now prohibited: %s',get_class($this), var_export($this->prohibited, true)));
return $this->prohibited;
}

View File

@@ -37,11 +37,10 @@ class NodeGroup extends Node
/**
* @param Node[] $nodes
* @param bool $prohibited
*/
public function __construct(array $nodes, bool $prohibited = false)
{
$this->nodes = $nodes;
$this->nodes = $nodes;
$this->prohibited = $prohibited;
}

View File

@@ -52,23 +52,22 @@ class QueryParser implements QueryParserInterface
private string $query;
private int $position = 0;
/** @return NodeGroup */
public function parse(string $query): NodeGroup
{
Log::debug(sprintf('Parsing query in QueryParser: "%s"', $query));
$this->query = $query;
$this->position = 0;
return $this->buildNodeGroup(false);
}
/** @return NodeGroup */
private function buildNodeGroup(bool $isSubquery, bool $prohibited = false): NodeGroup
{
$nodes = [];
$nodeResult = $this->buildNextNode($isSubquery);
while ($nodeResult->node !== null) {
$nodes[] = $nodeResult->node;
while (null !== $nodeResult->node) {
$nodes[] = $nodeResult->node;
if ($nodeResult->isSubqueryEnd) {
break;
}
@@ -90,13 +89,15 @@ class QueryParser implements QueryParserInterface
// If we're in a quoted string, we treat all characters except another quote as ordinary characters
if ($inQuotes) {
if ($char !== '"') {
if ('"' !== $char) {
$tokenUnderConstruction .= $char;
$this->position++;
++$this->position;
continue;
}
// char is "
$this->position++;
++$this->position;
return new NodeResult(
$this->createNode($tokenUnderConstruction, $fieldName, $prohibited),
false
@@ -105,47 +106,53 @@ class QueryParser implements QueryParserInterface
switch ($char) {
case '-':
if ($tokenUnderConstruction === '') {
if ('' === $tokenUnderConstruction) {
// A minus sign at the beginning of a token indicates prohibition
Log::debug('Indicate prohibition');
$prohibited = true;
}
if ($tokenUnderConstruction !== '') {
if ('' !== $tokenUnderConstruction) {
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
}
break;
case '"':
if ($tokenUnderConstruction === '') {
if ('' === $tokenUnderConstruction) {
// A quote sign at the beginning of a token indicates the start of a quoted string
$inQuotes = true;
}
if ($tokenUnderConstruction !== '') {
if ('' !== $tokenUnderConstruction) {
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
}
break;
case '(':
if ($tokenUnderConstruction === '') {
if ('' === $tokenUnderConstruction) {
// A left parentheses at the beginning of a token indicates the start of a subquery
$this->position++;
return new NodeResult($this->buildNodeGroup(true, $prohibited),
false
++$this->position;
return new NodeResult(
$this->buildNodeGroup(true, $prohibited),
false
);
}
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
break;
case ')':
// A right parentheses while in a subquery means the subquery ended,
// thus also signaling the end of any node currently being built
if ($isSubquery) {
$this->position++;
++$this->position;
return new NodeResult(
$tokenUnderConstruction !== ''
'' !== $tokenUnderConstruction
? $this->createNode($tokenUnderConstruction, $fieldName, $prohibited)
: null,
true
@@ -153,40 +160,44 @@ class QueryParser implements QueryParserInterface
}
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
break;
case ':':
if ($tokenUnderConstruction !== '') {
if ('' !== $tokenUnderConstruction) {
// If we meet a colon with a left-hand side string, we know we're in a field and are about to set up the value
$fieldName = $tokenUnderConstruction;
$tokenUnderConstruction = '';
}
if ($tokenUnderConstruction === '') {
if ('' === $tokenUnderConstruction) {
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
}
break;
case ' ':
// A space indicates the end of a token construction if non-empty, otherwise it's just ignored
if ($tokenUnderConstruction !== '') {
$this->position++;
if ('' !== $tokenUnderConstruction) {
++$this->position;
return new NodeResult(
$this->createNode($tokenUnderConstruction, $fieldName, $prohibited),
false
);
}
break;
default:
$tokenUnderConstruction .= $char;
}
$this->position++;
++$this->position;
}
$finalNode = $tokenUnderConstruction !== '' || $fieldName !== ''
$finalNode = '' !== $tokenUnderConstruction || '' !== $fieldName
? $this->createNode($tokenUnderConstruction, $fieldName, $prohibited)
: null;
@@ -195,11 +206,13 @@ class QueryParser implements QueryParserInterface
private function createNode(string $token, string $fieldName, bool $prohibited): Node
{
if (strlen($fieldName) > 0) {
if ('' !== $fieldName) {
Log::debug(sprintf('Create FieldNode %s:%s (%s)', $fieldName, $token, var_export($prohibited, true)));
return new FieldNode(trim($fieldName), trim($token), $prohibited);
}
Log::debug(sprintf('Create StringNode "%s" (%s)', $token, var_export($prohibited, true)));
return new StringNode(trim($token), $prohibited);
}
}

View File

@@ -28,7 +28,6 @@ namespace FireflyIII\Support\Search\QueryParser;
interface QueryParserInterface
{
/**
* @return NodeGroup
* @throws \LogicException
* @throws \TypeError
*/

View File

@@ -34,7 +34,7 @@ class StringNode extends Node
public function __construct(string $value, bool $prohibited = false)
{
$this->value = $value;
$this->value = $value;
$this->prohibited = $prohibited;
}

View File

@@ -38,9 +38,11 @@ interface SearchInterface
public function getModifiers(): Collection;
public function getOperators(): Collection;
public function getWords(): array;
public function getWordsAsString(): string;
public function getExcludedWords(): array;
public function hasModifiers(): bool;