From 1c5641c501f0245fef83b5888eaaae032aee68a1 Mon Sep 17 00:00:00 2001 From: Jens Pfeifer Date: Thu, 22 Aug 2024 23:24:59 +0000 Subject: [PATCH] Console command Admin::PostMasterFilter::Import now will also update existing filters instead of only create new ones. Thanks to @meisterheister for reporting the issue. --- CHANGES.md | 1 + Kernel/System/ZnunyHelper.pm | 2 +- scripts/test/ZnunyHelper/PostMasterFilter.t | 62 +++++++++++++++++++-- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 981b2f5cde5..941f5d31589 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,5 @@ # 7.1.3 2024-??-?? + - 2024-08-22 Console command Admin::PostMasterFilter::Import now will also update existing filters instead of only create new ones. Thanks to @meisterheister for reporting the issue. [#527](https://github.com/znuny/Znuny/issues/527) - 2024-08-22 Added '--single-transaction' option to scripts/backup.pl for MySQL/MariaDB. The --single-transaction flag will start a transaction before running. - 2024-08-21 Improved CSS for skin 'Dark'. [#584](https://github.com/znuny/Znuny/issues/584) - 2024-08-21 Sector Nord AG: Fixed overflow of dynamic field groups in AgentTicketZoom process widget. Thanks to Sector Nord AG (@jsinagowitz). [PR#553](https://github.com/znuny/Znuny/pull/553) diff --git a/Kernel/System/ZnunyHelper.pm b/Kernel/System/ZnunyHelper.pm index 278188be2f0..9b51ab3f42f 100644 --- a/Kernel/System/ZnunyHelper.pm +++ b/Kernel/System/ZnunyHelper.pm @@ -2344,7 +2344,7 @@ sub _PostMasterFilterConfigImport { } return if !IsArrayRefWithData($Filter); - return $Self->_PostMasterFilterCreateIfNotExists( @{$Filter} ); + return $Self->_PostMasterFilterCreate( @{$Filter} ); } =head2 _GroupCreateIfNotExists() diff --git a/scripts/test/ZnunyHelper/PostMasterFilter.t b/scripts/test/ZnunyHelper/PostMasterFilter.t index 949a1b99417..39dbd28ff36 100644 --- a/scripts/test/ZnunyHelper/PostMasterFilter.t +++ b/scripts/test/ZnunyHelper/PostMasterFilter.t @@ -93,7 +93,7 @@ $Self->True( '_PostMasterFilterCreateIfNotExists', ); -# _PostMasterFilterCreateIfNotExists yml +# _PostMasterFilterConfigImport yml my $Name = 'PostmasterFilterYML' . $RandomNumber; my $YML = "--- - Match: @@ -114,7 +114,7 @@ $Result = $ZnunyHelperObject->_PostMasterFilterConfigImport( $Self->True( $Result, - '_PostMasterFilterCreateIfNotExists', + '_PostMasterFilterConfigImport', ); %Data = $PMFilterObject->FilterGet( @@ -130,7 +130,7 @@ $Self->IsDeeply( 'Value' => '333' } ], - 'Name' => 'PostmasterFilterYML' . $RandomNumber, + 'Name' => $Name, 'Not' => [ { 'Key' => 'Body', @@ -145,7 +145,61 @@ $Self->IsDeeply( ], 'StopAfterMatch' => 0 }, - '_PostMasterFilterCreate', + '_PostMasterFilterConfigImport', +); + +# Update filter with same name via _PostMasterFilterConfigImport +$YML = "--- +- Match: + - Key: Body + Value: 444 + Name: $Name + Not: + - Key: Body + Value: ~ + Set: + - Key: X-OTRS-DynamicField-test2 + Value: 555 + StopAfterMatch: 0"; + +$Result = $ZnunyHelperObject->_PostMasterFilterConfigImport( + Filter => \$YML, +); + +$Self->True( + $Result, + '_PostMasterFilterConfigImport', +); + +%Data = $PMFilterObject->FilterGet( + Name => $Name +); + +$Self->IsDeeply( + \%Data, + { + 'Match' => [ + { + 'Key' => 'Body', + 'Value' => '444' + } + ], + 'Name' => $Name, + 'Not' => [ + { + 'Key' => 'Body', + 'Value' => undef, + } + ], + 'Set' => [ + { + 'Key' => 'X-OTRS-DynamicField-test2', + 'Value' => '555' + } + ], + 'StopAfterMatch' => 0 + }, + '_PostMasterFilterConfigImport', ); 1;