mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 12:28:46 +00:00
Auto commit for release 'develop' on 2025-01-05
This commit is contained in:
@@ -35,13 +35,13 @@ class BillObserver
|
||||
{
|
||||
public function created(Bill $bill): void
|
||||
{
|
||||
// Log::debug('Observe "created" of a bill.');
|
||||
// Log::debug('Observe "created" of a bill.');
|
||||
$this->updateNativeAmount($bill);
|
||||
}
|
||||
|
||||
public function deleting(Bill $bill): void
|
||||
{
|
||||
// app('log')->debug('Observe "deleting" of a bill.');
|
||||
// app('log')->debug('Observe "deleting" of a bill.');
|
||||
foreach ($bill->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class BillObserver
|
||||
|
||||
public function updated(Bill $bill): void
|
||||
{
|
||||
// Log::debug('Observe "updated" of a bill.');
|
||||
// Log::debug('Observe "updated" of a bill.');
|
||||
$this->updateNativeAmount($bill);
|
||||
}
|
||||
|
||||
|
||||
@@ -376,6 +376,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
if (0 === count($array)) {
|
||||
Log::debug('No excluded search words provided, skipping.');
|
||||
|
||||
return $this;
|
||||
}
|
||||
Log::debug(sprintf('%d excluded search words provided.', count($array)));
|
||||
@@ -952,6 +953,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
if (0 === count($array)) {
|
||||
Log::debug('No words in array');
|
||||
|
||||
return $this;
|
||||
}
|
||||
Log::debug(sprintf('%d word(s) in array', count($array)));
|
||||
|
||||
@@ -89,14 +89,14 @@ class CreateController extends Controller
|
||||
// build triggers from query, if present.
|
||||
$query = (string) $request->get('from_query');
|
||||
if ('' !== $query) {
|
||||
$search = app(SearchInterface::class);
|
||||
$search = app(SearchInterface::class);
|
||||
$search->parseQuery($query);
|
||||
$words = $search->getWords();
|
||||
$excludedWords = $search->getExcludedWords();
|
||||
$operators = $search->getOperators()->toArray();
|
||||
$words = $search->getWords();
|
||||
$excludedWords = $search->getExcludedWords();
|
||||
$operators = $search->getOperators()->toArray();
|
||||
if (count($words) > 0) {
|
||||
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)]));
|
||||
foreach($words as $word) {
|
||||
foreach ($words as $word) {
|
||||
$operators[] = [
|
||||
'type' => 'description_contains',
|
||||
'value' => $word,
|
||||
@@ -105,14 +105,14 @@ class CreateController extends Controller
|
||||
}
|
||||
if (count($excludedWords) > 0) {
|
||||
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)]));
|
||||
foreach($excludedWords as $excludedWord) {
|
||||
foreach ($excludedWords as $excludedWord) {
|
||||
$operators[] = [
|
||||
'type' => '-description_contains',
|
||||
'value' => $excludedWord,
|
||||
];
|
||||
}
|
||||
}
|
||||
$oldTriggers = $this->parseFromOperators($operators);
|
||||
$oldTriggers = $this->parseFromOperators($operators);
|
||||
}
|
||||
// var_dump($oldTriggers);exit;
|
||||
|
||||
|
||||
@@ -85,14 +85,14 @@ class EditController extends Controller
|
||||
// build triggers from query, if present.
|
||||
$query = (string) $request->get('from_query');
|
||||
if ('' !== $query) {
|
||||
$search = app(SearchInterface::class);
|
||||
$search = app(SearchInterface::class);
|
||||
$search->parseQuery($query);
|
||||
$words = $search->getWords();
|
||||
$excludedWords = $search->getExcludedWords();
|
||||
$operators = $search->getOperators()->toArray();
|
||||
$words = $search->getWords();
|
||||
$excludedWords = $search->getExcludedWords();
|
||||
$operators = $search->getOperators()->toArray();
|
||||
if (count($words) > 0) {
|
||||
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)]));
|
||||
foreach($words as $word) {
|
||||
foreach ($words as $word) {
|
||||
$operators[] = [
|
||||
'type' => 'description_contains',
|
||||
'value' => $word,
|
||||
@@ -101,14 +101,14 @@ class EditController extends Controller
|
||||
}
|
||||
if (count($excludedWords) > 0) {
|
||||
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)]));
|
||||
foreach($excludedWords as $excludedWord) {
|
||||
foreach ($excludedWords as $excludedWord) {
|
||||
$operators[] = [
|
||||
'type' => '-description_contains',
|
||||
'value' => $excludedWord,
|
||||
];
|
||||
}
|
||||
}
|
||||
$oldTriggers = $this->parseFromOperators($operators);
|
||||
$oldTriggers = $this->parseFromOperators($operators);
|
||||
}
|
||||
// has old input?
|
||||
if (null !== $request->old() && is_array($request->old()) && count($request->old()) > 0) {
|
||||
|
||||
@@ -51,8 +51,8 @@ class SearchServiceProvider extends ServiceProvider
|
||||
static function (): GdbotsQueryParser|QueryParser {
|
||||
$implementation = config('search.query_parser');
|
||||
|
||||
return match($implementation) {
|
||||
'new' => app(QueryParser::class),
|
||||
return match ($implementation) {
|
||||
'new' => app(QueryParser::class),
|
||||
default => app(GdbotsQueryParser::class),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ class Navigation
|
||||
{
|
||||
$format = 'Y-m-d';
|
||||
$diff = $start->diffInMonths($end, true);
|
||||
//Log::debug(sprintf('preferredCarbonFormat(%s, %s) = %f', $start->format('Y-m-d'), $end->format('Y-m-d'), $diff));
|
||||
// Log::debug(sprintf('preferredCarbonFormat(%s, %s) = %f', $start->format('Y-m-d'), $end->format('Y-m-d'), $diff));
|
||||
if ($diff >= 1.001) {
|
||||
// Log::debug(sprintf('Return Y-m because %s', $diff));
|
||||
$format = 'Y-m';
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace FireflyIII\Support\Search\QueryParser;
|
||||
interface QueryParserInterface
|
||||
{
|
||||
/**
|
||||
* @return NodeGroup
|
||||
* @throws \LogicException
|
||||
* @throws \TypeError
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user