Skip to content

Firefly III: a personal finances manager

Fix https://github.com/firefly-iii/firefly-iii/issues/8192

James Cole3355645cb458
diff --git a/.ci/php-cs-fixer/composer.lock b/.ci/php-cs-fixer/composer.lock
index 7bf45bfc60..6527af292f 100644
--- a/.ci/php-cs-fixer/composer.lock
+++ b/.ci/php-cs-fixer/composer.lock
@@ -226,16 +226,16 @@
},
{
"name": "friendsofphp/php-cs-fixer",
- "version": "v3.39.0",
+ "version": "v3.39.1",
"source": {
"type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
- "reference": "04bf7b28fc847185b247d112cab617da941e3cca"
+ "reference": "857046d26b0d92dc13c4be769309026b100b517e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/04bf7b28fc847185b247d112cab617da941e3cca",
- "reference": "04bf7b28fc847185b247d112cab617da941e3cca",
+ "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/857046d26b0d92dc13c4be769309026b100b517e",
+ "reference": "857046d26b0d92dc13c4be769309026b100b517e",
"shasum": ""
},
"require": {
@@ -307,7 +307,7 @@
],
"support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
- "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.39.0"
+ "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.39.1"
},
"funding": [
{
@@ -315,7 +315,7 @@
"type": "github"
}
],
- "time": "2023-11-22T11:20:09+00:00"
+ "time": "2023-11-24T22:59:03+00:00"
},
{
"name": "psr/container",
diff --git a/app/Http/Controllers/Rule/CreateController.php b/app/Http/Controllers/Rule/CreateController.php
index 60f095dc85..6314df0193 100644
--- a/app/Http/Controllers/Rule/CreateController.php
+++ b/app/Http/Controllers/Rule/CreateController.php
@@ -100,13 +100,15 @@ class CreateController extends Controller
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words]));
$operators[] = [
'type' => 'description_contains',
- 'value' => $words];
+ 'value' => $words
+ ];
}
$oldTriggers = $this->parseFromOperators($operators);
}
+ //var_dump($oldTriggers);exit;
// restore actions and triggers from old input:
- if (null !== $request->old()) {
+ if (is_array($request->old()) && count($request->old()) > 0) {
$oldTriggers = $this->getPreviousTriggers($request);
$oldActions = $this->getPreviousActions($request);
}
diff --git a/app/Support/Http/Controllers/RuleManagement.php b/app/Support/Http/Controllers/RuleManagement.php
index 770c20abf3..1f495166bc 100644
--- a/app/Support/Http/Controllers/RuleManagement.php
+++ b/app/Support/Http/Controllers/RuleManagement.php
@@ -138,12 +138,14 @@ trait RuleManagement
$index = 0;
foreach ($submittedOperators as $operator) {
+ $rootOperator = OperatorQuerySearch::getRootOperator($operator['type']);
+ $needsContext = (bool) config(sprintf('search.operators.%s.needs_context',$rootOperator));
try {
$renderedEntries[] = view(
'rules.partials.trigger',
[
- 'oldTrigger' => OperatorQuerySearch::getRootOperator($operator['type']),
- 'oldValue' => $operator['value'],
+ 'oldTrigger' => $rootOperator,
+ 'oldValue' => $needsContext ? $operator['value'] : '',
'oldChecked' => false,
'oldProhibited' => $operator['prohibited'] ?? false,
'count' => $index + 1,
diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php
index 46a839247f..39d795403a 100644
--- a/app/Support/Search/OperatorQuerySearch.php
+++ b/app/Support/Search/OperatorQuerySearch.php
@@ -60,8 +60,7 @@ use TypeError;
/**
* Class OperatorQuerySearch
*/
-class
-OperatorQuerySearch implements SearchInterface
+class OperatorQuerySearch implements SearchInterface
{
protected Carbon $date;
private AccountRepositoryInterface $accountRepository;
@@ -212,8 +211,14 @@ OperatorQuerySearch implements SearchInterface
$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) {
+ if ('false' === $value && in_array($operator, $this->validOperators, true) && false === $context && !$prohibited) {
$prohibited = 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';
}
// must be valid operator:
diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php
index ff24071dce..47505be414 100644
--- a/app/TransactionRules/Engine/SearchRuleEngine.php
+++ b/app/TransactionRules/Engine/SearchRuleEngine.php
@@ -115,13 +115,13 @@ class SearchRuleEngine implements RuleEngineInterface
}
// if needs no context, value is different:
- $needsContext = config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true;
+ $needsContext = (bool) config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true;
if (false === $needsContext) {
- app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger: %s:true', $ruleTrigger->trigger_type));
+ app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
$searchArray[$ruleTrigger->trigger_type][] = 'true';
}
if (true === $needsContext) {
- app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger: %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
+ app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger (context): %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
$searchArray[$ruleTrigger->trigger_type][] = sprintf('"%s"', $ruleTrigger->trigger_value);
}
}
@@ -136,6 +136,7 @@ class SearchRuleEngine implements RuleEngineInterface
if ($this->hasSpecificJournalTrigger($searchArray)) {
$date = $this->setDateFromJournalTrigger($searchArray);
}
+
// build and run the search engine.
$searchEngine = app(SearchInterface::class);
$searchEngine->setUser($this->user);
@@ -145,7 +146,9 @@ class SearchRuleEngine implements RuleEngineInterface
foreach ($searchArray as $type => $searches) {
foreach ($searches as $value) {
- $searchEngine->parseQuery(sprintf('%s:%s', $type, $value));
+ $query = sprintf('%s:%s', $type, $value);
+ app('log')->debug(sprintf('SearchRuleEngine:: add query "%s"', $query));
+ $searchEngine->parseQuery($query);
}
}