From dae7e7d507ed3fddfc7790a61b57eba3e46fa96c Mon Sep 17 00:00:00 2001 From: Sobuno Date: Fri, 3 Jan 2025 01:00:17 +0100 Subject: [PATCH] Handle excludedWords on Rule management pages as well --- .../Controllers/Rule/CreateController.php | 30 +++++++++++++------ app/Http/Controllers/Rule/EditController.php | 23 +++++++++++--- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Rule/CreateController.php b/app/Http/Controllers/Rule/CreateController.php index 9729dfe015..ab2e59b46c 100644 --- a/app/Http/Controllers/Rule/CreateController.php +++ b/app/Http/Controllers/Rule/CreateController.php @@ -89,16 +89,28 @@ 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->getWordsAsString(); - $operators = $search->getOperators()->toArray(); - if ('' !== $words) { - session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words])); - $operators[] = [ - 'type' => 'description_contains', - 'value' => $words, - ]; + $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) { + $operators[] = [ + 'type' => 'description_contains', + 'value' => $word, + ]; + } + } + if (count($excludedWords) > 0) { + session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)])); + foreach($excludedWords as $excludedWord) { + $operators[] = [ + 'type' => '-description_contains', + 'value' => $excludedWord, + ]; + } } $oldTriggers = $this->parseFromOperators($operators); } diff --git a/app/Http/Controllers/Rule/EditController.php b/app/Http/Controllers/Rule/EditController.php index a00df8ef4c..4c4e04b6fc 100644 --- a/app/Http/Controllers/Rule/EditController.php +++ b/app/Http/Controllers/Rule/EditController.php @@ -87,11 +87,26 @@ class EditController extends Controller if ('' !== $query) { $search = app(SearchInterface::class); $search->parseQuery($query); - $words = $search->getWordsAsString(); + $words = $search->getWords(); + $excludedWords = $search->getExcludedWords(); $operators = $search->getOperators()->toArray(); - if ('' !== $words) { - session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words])); - $operators[] = ['type' => 'description_contains', 'value' => $words]; + if (count($words) > 0) { + session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)])); + foreach($words as $word) { + $operators[] = [ + 'type' => 'description_contains', + 'value' => $word, + ]; + } + } + if (count($excludedWords) > 0) { + session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)])); + foreach($excludedWords as $excludedWord) { + $operators[] = [ + 'type' => '-description_contains', + 'value' => $excludedWord, + ]; + } } $oldTriggers = $this->parseFromOperators($operators); }