Skip to content

Commit

Permalink
Fixed bug - ArticleStorageSwitch creates duplicate files with an addi…
Browse files Browse the repository at this point in the history
…tional file extension '-1'.
  • Loading branch information
dennykorsukewitz committed Sep 25, 2024
1 parent 9bd8dc8 commit a7578e7
Show file tree
Hide file tree
Showing 6 changed files with 2,429 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 7.1.3 2024-??-??
- 2024-09-24 Fixed bug - ArticleStorageSwitch creates duplicate files with an additional file extension '-1'.
- 2024-09-18 Fixed exit code of migration script.
- 2024-09-18 Fixed bug - In the AgentDashboard: Statistics widgets are always displayed, regardless of which DashboardWidgetExpand is currently set.
- 2024-09-11 Fixed Bug - Duplicate value 'ArticleAgentNotification' in Ticket.xml 'Events###Article'. Thanks for reporting (@BuilderNSV). [#594](https://github.com/znuny/Znuny/issues/594)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ sub ArticleWriteAttachment {
my $NewFileName = $Param{Filename};
my %UsedFile;
my %Index = $Self->ArticleAttachmentIndex(
ArticleID => $Param{ArticleID},
ArticleID => $Param{ArticleID},
OnlyMyBackend => 1,
);

for my $IndexFile ( sort keys %Index ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ sub ArticleWriteAttachment {
my $NewFileName = $Param{Filename};
my %UsedFile;
my %Index = $Self->ArticleAttachmentIndex(
ArticleID => $Param{ArticleID},
ArticleID => $Param{ArticleID},
OnlyMyBackend => 1,
);

# Normalize filenames to find file names which are identical but in a different unicode form.
Expand Down
61 changes: 60 additions & 1 deletion scripts/test/Ticket/ArticleStorageSwitch.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ for my $SourceBackend (qw(ArticleStorageDB ArticleStorageFS)) {
Value => 'Kernel::System::Ticket::Article::Backend::MIMEBase::' . $SourceBackend,
);

$ConfigObject->Set(
Key => 'Ticket::Article::Backend::MIMEBase::CheckAllStorageBackends',
Value => '1',
);

my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my $ArticleObject = $Kernel::OM->Get('Kernel::System::Ticket::Article');
my $ArticleBackendObject = $ArticleObject->BackendForChannel( ChannelName => 'Email' );
Expand All @@ -50,7 +55,7 @@ for my $SourceBackend (qw(ArticleStorageDB ArticleStorageFS)) {
my @TicketIDs;
my %ArticleIDs;
my $NamePrefix = "ArticleStorageSwitch ($SourceBackend)";
for my $File (qw(1 2 3 4 5 6 7 8 9 10 11 20)) {
for my $File (qw(1 2 3 4 5 6 7 8 9 10 11 20 28 29)) {

my $NamePrefix = "$NamePrefix #$File ";

Expand Down Expand Up @@ -174,6 +179,60 @@ for my $SourceBackend (qw(ArticleStorageDB ArticleStorageFS)) {
ArticleID => $ArticleID,
);

if (
$ArticleBackendObject->{ArticleStorageModule} eq
'Kernel::System::Ticket::Article::Backend::MIMEBase::ArticleStorageFS'
)
{

$Self->{ArticleDataDir} = $ConfigObject->Get('Ticket::Article::Backend::MIMEBase::ArticleDataDir');

my $ContentPath = $Kernel::OM->Get('Kernel::System::Ticket::Article')->ArticleContentPathGet(
ArticleID => $ArticleID,
);
my @Files = $MainObject->DirectoryRead(
Directory => "$Self->{ArticleDataDir}/$ContentPath/$ArticleID",
Filter => "*",
Silent => 1,
);
FILE:
for my $File (@Files) {

# get file name
$File =~ s{^.*/([^/]+)$}{$1}smx;

# check if file is valid (e.g. file-1 is valid | file-1-1 is not valid)
next FILE if $File !~ m{ -\d-\d }smx;

$Self->False(
$File,
"FileName is not valid. $File"
);
}
}
elsif (
$ArticleBackendObject->{ArticleStorageModule} eq
'Kernel::System::Ticket::Article::Backend::MIMEBase::ArticleStorageDB'
)
{
FILE:
for my $Index ( sort keys %Index ) {

my $File = $Index{$Index}->{Filename};

# get file name
$File =~ s{^.*/([^/]+)$}{$1}smx;

# check if file is valid (e.g. file-1 is valid | file-1-1 is not valid)
next FILE if $File !~ m{ -\d-\d }smx;

$Self->False(
$File,
"FileName is not valid. $File"
);
}
}

# check file attributes
for my $AttachmentID ( sort keys %{ $ArticleIDs{$ArticleID} } ) {

Expand Down
Loading

0 comments on commit a7578e7

Please sign in to comment.