mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-02-07 04:36:24 +00:00
🤖 Auto commit for release 'develop' on 2026-01-23
This commit is contained in:
@@ -45,7 +45,7 @@ use Illuminate\Support\Facades\Log;
|
||||
class SearchRuleEngine implements RuleEngineInterface
|
||||
{
|
||||
private readonly Collection $groups;
|
||||
private array $operators = [];
|
||||
private array $operators = [];
|
||||
// always collect the triggers from the database, unless indicated otherwise.
|
||||
private bool $refreshTriggers = true;
|
||||
private array $resultCount = [];
|
||||
@@ -54,7 +54,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->rules = new Collection();
|
||||
$this->rules = new Collection();
|
||||
$this->groups = new Collection();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
Log::debug('SearchRuleEngine::find()');
|
||||
$collection = new Collection();
|
||||
foreach ($this->rules as $rule) {
|
||||
$found = new Collection();
|
||||
$found = new Collection();
|
||||
if (true === $rule->strict) {
|
||||
$found = $this->findStrictRule($rule);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
$collection = $collection->merge($found);
|
||||
}
|
||||
$result = $collection->unique();
|
||||
$result = $collection->unique();
|
||||
Log::debug(sprintf('SearchRuleEngine::find() returns %d unique transactions.', $result->count()));
|
||||
|
||||
return $result;
|
||||
@@ -90,8 +90,8 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
private function findStrictRule(Rule $rule): Collection
|
||||
{
|
||||
Log::debug(sprintf('Now in findStrictRule(#%d)', $rule->id ?? 0));
|
||||
$searchArray = [];
|
||||
$triggers = [];
|
||||
$searchArray = [];
|
||||
$triggers = [];
|
||||
if ($this->refreshTriggers) {
|
||||
$triggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
// if the trigger needs no context, value is different:
|
||||
$needsContext = (bool) (config(sprintf('search.operators.%s.needs_context', $contextSearch)) ?? true);
|
||||
$needsContext = (bool) (config(sprintf('search.operators.%s.needs_context', $contextSearch)) ?? true);
|
||||
if (false === $needsContext) {
|
||||
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = 'true';
|
||||
@@ -126,7 +126,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
Log::debug(sprintf('SearchRuleEngine:: add local added operator: %s:"%s"', $operator['type'], $operator['value']));
|
||||
$searchArray[$operator['type']][] = sprintf('"%s"', $operator['value']);
|
||||
}
|
||||
$date = today(config('app.timezone'));
|
||||
$date = today(config('app.timezone'));
|
||||
if ($this->hasSpecificJournalTrigger($searchArray)) {
|
||||
$date = $this->setDateFromJournalTrigger($searchArray);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
}
|
||||
|
||||
$result = $searchEngine->searchTransactions();
|
||||
$result = $searchEngine->searchTransactions();
|
||||
|
||||
return $result->getCollection();
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$dateTrigger = true;
|
||||
}
|
||||
}
|
||||
$result = $journalTrigger && $dateTrigger;
|
||||
$result = $journalTrigger && $dateTrigger;
|
||||
Log::debug(sprintf('Result of hasSpecificJournalTrigger is %s.', var_export($result, true)));
|
||||
|
||||
return $result;
|
||||
@@ -190,7 +190,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
if (0 !== $journalId) {
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$journal = $repository->find($journalId);
|
||||
$journal = $repository->find($journalId);
|
||||
if (null !== $journal) {
|
||||
$date = $journal->date;
|
||||
Log::debug(sprintf('Found journal #%d with date %s.', $journal->id, $journal->date->format('Y-m-d')));
|
||||
@@ -205,7 +205,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->user = $user;
|
||||
$this->operators = [];
|
||||
}
|
||||
|
||||
@@ -272,10 +272,10 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$searchEngine->parseQuery(sprintf('%s:%s', $type, $value));
|
||||
}
|
||||
|
||||
$result = $searchEngine->searchTransactions();
|
||||
$collection = $result->getCollection();
|
||||
$result = $searchEngine->searchTransactions();
|
||||
$collection = $result->getCollection();
|
||||
Log::debug(sprintf('Found in this run, %d transactions', $collection->count()));
|
||||
$total = $total->merge($collection);
|
||||
$total = $total->merge($collection);
|
||||
Log::debug(sprintf('Total collection is now %d transactions', $total->count()));
|
||||
++$count;
|
||||
// if trigger says stop processing, do so.
|
||||
@@ -289,7 +289,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
Log::debug(sprintf('Done running %d trigger(s)', $count));
|
||||
|
||||
// make collection unique
|
||||
$unique = $total->unique(static function (array $group): string {
|
||||
$unique = $total->unique(static function (array $group): string {
|
||||
$str = '';
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$str = sprintf('%s%d', $str, $transaction['transaction_journal_id']);
|
||||
@@ -381,7 +381,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
|
||||
$this->processResults($rule, $collection);
|
||||
|
||||
$result = $collection->count() > 0;
|
||||
$result = $collection->count() > 0;
|
||||
if ($result) {
|
||||
Log::debug(sprintf('SearchRuleEngine:: Done. Rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count()));
|
||||
|
||||
@@ -477,9 +477,10 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
private function addNotes(array $transaction): array
|
||||
{
|
||||
$transaction['notes'] = '';
|
||||
$dbNote = Note::where('noteable_id', (int) $transaction['transaction_journal_id'])
|
||||
$dbNote = Note::where('noteable_id', (int) $transaction['transaction_journal_id'])
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first(['notes.*']);
|
||||
->first(['notes.*'])
|
||||
;
|
||||
if (null !== $dbNote) {
|
||||
$transaction['notes'] = $dbNote->text;
|
||||
}
|
||||
@@ -523,7 +524,8 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
// ->where('rule_triggers.trigger_type', 'user_action')
|
||||
// ->where('rule_triggers.trigger_value', 'store-journal')
|
||||
->where('rules.active', true)
|
||||
->get(['rules.*']);
|
||||
->get(['rules.*'])
|
||||
;
|
||||
}
|
||||
Log::debug(sprintf('Going to fire group #%d with %d rule(s)', $group->id, $rules->count()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user