diff --git a/Kernel/Modules/AgentTicketPhoneCommon.pm b/Kernel/Modules/AgentTicketPhoneCommon.pm index c1e6e0d1e11..49ccf1656b5 100644 --- a/Kernel/Modules/AgentTicketPhoneCommon.pm +++ b/Kernel/Modules/AgentTicketPhoneCommon.pm @@ -431,42 +431,6 @@ sub Run { ); } - # If is an action about attachments - my $IsUpload = 0; - - # attachment delete - my @AttachmentIDs = map { - my ($ID) = $_ =~ m{ \A AttachmentDelete (\d+) \z }xms; - $ID ? $ID : (); - } $ParamObject->GetParamNames(); - - COUNT: - for my $Count ( reverse sort @AttachmentIDs ) { - my $Delete = $ParamObject->GetParam( Param => "AttachmentDelete$Count" ); - next COUNT if !$Delete; - $Error{AttachmentDelete} = 1; - $UploadCacheObject->FormIDRemoveFile( - FormID => $Self->{FormID}, - FileID => $Count, - ); - $IsUpload = 1; - } - - # attachment upload - if ( $ParamObject->GetParam( Param => 'AttachmentUpload' ) ) { - $IsUpload = 1; - %Error = (); - $Error{AttachmentUpload} = 1; - my %UploadStuff = $ParamObject->GetUploadAll( - Param => 'FileUpload', - ); - $UploadCacheObject->FormIDAddFile( - FormID => $Self->{FormID}, - Disposition => 'attachment', - %UploadStuff, - ); - } - # Get and validate draft action. my $FormDraftAction = $ParamObject->GetParam( Param => 'FormDraftAction' ); if ( $FormDraftAction && !$Config->{FormDraft} ) { @@ -525,7 +489,6 @@ sub Run { ErrorMessage => $Kernel::OM->Get('Kernel::Language') ->Translate( "FormDraft name %s is already in use!", $Title ), ); - $IsUpload = 1; last DRAFT; } } diff --git a/Kernel/Modules/AjaxAttachment.pm b/Kernel/Modules/AjaxAttachment.pm index 090adc2a450..ed8e463ab29 100644 --- a/Kernel/Modules/AjaxAttachment.pm +++ b/Kernel/Modules/AjaxAttachment.pm @@ -95,18 +95,18 @@ sub Run { elsif ( $Self->{Subaction} eq 'Delete' ) { my $Return; - my $AttachmentFileID = $ParamObject->GetParam( Param => 'FileID' ) || ''; + my $AttachmentFilename = $ParamObject->GetParam( Param => 'Filename' ) || ''; - if ( !$AttachmentFileID ) { + if ( !$AttachmentFilename ) { $Return->{Message} = $LayoutObject->{LanguageObject}->Translate( - 'Error: the file could not be deleted properly. Please contact your administrator (missing FileID).' + 'Error: the file could not be deleted properly. Please contact your administrator (missing Filename).' ); } else { my $DeleteAttachment = $UploadCacheObject->FormIDRemoveFile( - FormID => $Self->{FormID}, - FileID => $AttachmentFileID, + FormID => $Self->{FormID}, + Filename => $AttachmentFilename, ); if ($DeleteAttachment) { @@ -127,9 +127,10 @@ sub Run { } $Return = { - Message => 'Success', - Data => \@AttachmentData, + Message => 'Success', + NumberOfAttachmentsLeft => scalar @AttachmentData, }; + } } diff --git a/Kernel/System/FormDraft.pm b/Kernel/System/FormDraft.pm index cf841dd3d65..5f5d3cd1a9f 100644 --- a/Kernel/System/FormDraft.pm +++ b/Kernel/System/FormDraft.pm @@ -98,7 +98,6 @@ Returns (without GetContent or GetContent = 1): 'ContentID' => undef, # optional 'Filename' => 'thankyou.txt', 'Filesize' => 25, - 'FileID' => 1, 'Disposition' => 'attachment', }, ... @@ -261,7 +260,6 @@ add a new draft 'ContentID' => undef, # optional 'Filename' => 'thankyou.txt', 'Filesize' => 25, - 'FileID' => 1, 'Disposition' => 'attachment', }, ... @@ -348,7 +346,6 @@ update an existing draft 'ContentID' => undef, # optional 'Filename' => 'thankyou.txt', 'Filesize' => 25, - 'FileID' => 1, 'Disposition' => 'attachment', }, ... diff --git a/Kernel/System/Web/UploadCache.pm b/Kernel/System/Web/UploadCache.pm index 70a72c0ee23..ea60b0a5f08 100644 --- a/Kernel/System/Web/UploadCache.pm +++ b/Kernel/System/Web/UploadCache.pm @@ -117,7 +117,7 @@ removes a file from a form id $UploadCacheObject->FormIDRemoveFile( FormID => 12345, - FileID => 1, + FileName => 'document.txt', ); =cut @@ -136,7 +136,7 @@ returns an array with a hash ref of all files for a Form ID FormID => 12345, ); - Return data of on hash is Content, ContentType, ContentID, Filename, Filesize, FileID; + Return data of on hash is Content, ContentType, ContentID, Filename, Filesize; =cut @@ -156,7 +156,7 @@ Note: returns no content, only meta data. FormID => 12345, ); - Return data of hash is ContentType, ContentID, Filename, Filesize, FileID; + Return data of hash is ContentType, ContentID, Filename, Filesize; =cut diff --git a/Kernel/System/Web/UploadCache/DB.pm b/Kernel/System/Web/UploadCache/DB.pm index d613b8532e9..cf547356d6f 100644 --- a/Kernel/System/Web/UploadCache/DB.pm +++ b/Kernel/System/Web/UploadCache/DB.pm @@ -123,7 +123,7 @@ sub FormIDAddFile { sub FormIDRemoveFile { my ( $Self, %Param ) = @_; - for my $Needed (qw(FormID FileID)) { + for my $Needed (qw(FormID Filename)) { if ( !$Param{$Needed} ) { $Kernel::OM->Get('Kernel::System::Log')->Log( Priority => 'error', @@ -138,16 +138,23 @@ sub FormIDRemoveFile { # finish if files have been already removed by other process return if !@Index; - my $ID = $Param{FileID} - 1; - $Param{Filename} = $Index[$ID]->{Filename}; + # Find and remove file with given filename; return success if + # file not found (to avoid error if user double clicks delete icon). + FILE: + for my $File (@Index) { + if ( $File->{Filename} eq $Param{Filename} ) { - return if !$Kernel::OM->Get('Kernel::System::DB')->Do( - SQL => ' - DELETE FROM web_upload_cache - WHERE form_id = ? - AND filename = ?', - Bind => [ \$Param{FormID}, \$Param{Filename} ], - ); + return if !$Kernel::OM->Get('Kernel::System::DB')->Do( + SQL => ' + DELETE FROM web_upload_cache + WHERE form_id = ? + AND filename = ?', + Bind => [ \$Param{FormID}, \$Param{Filename} ], + ); + + last FILE; + } + } return 1; } @@ -155,7 +162,6 @@ sub FormIDRemoveFile { sub FormIDGetAllFilesData { my ( $Self, %Param ) = @_; - my $Counter = 0; my @Data; for my $Needed (qw(FormID)) { if ( !$Param{$Needed} ) { @@ -181,7 +187,6 @@ sub FormIDGetAllFilesData { ); while ( my @Row = $DBObject->FetchrowArray() ) { - $Counter++; # encode attachment if it's a postgresql backend!!! if ( !$DBObject->GetDatabaseFunction('DirectBlob') ) { @@ -198,7 +203,6 @@ sub FormIDGetAllFilesData { Filename => $Row[0], Filesize => $Row[2], Disposition => $Row[5], - FileID => $Counter, } ); } @@ -209,7 +213,6 @@ sub FormIDGetAllFilesData { sub FormIDGetAllFilesMeta { my ( $Self, %Param ) = @_; - my $Counter = 0; my @Data; for my $Needed (qw(FormID)) { if ( !$Param{$Needed} ) { @@ -234,7 +237,6 @@ sub FormIDGetAllFilesMeta { ); while ( my @Row = $DBObject->FetchrowArray() ) { - $Counter++; # add the info push( @@ -245,7 +247,6 @@ sub FormIDGetAllFilesMeta { Filename => $Row[0], Filesize => $Row[2], Disposition => $Row[4], - FileID => $Counter, } ); } diff --git a/Kernel/System/Web/UploadCache/FS.pm b/Kernel/System/Web/UploadCache/FS.pm index 0b2e6132adb..93b8fa09b4b 100644 --- a/Kernel/System/Web/UploadCache/FS.pm +++ b/Kernel/System/Web/UploadCache/FS.pm @@ -176,7 +176,7 @@ sub FormIDAddFile { sub FormIDRemoveFile { my ( $Self, %Param ) = @_; - for my $Needed (qw(FormID FileID)) { + for my $Needed (qw(FormID Filename)) { if ( !$Param{$Needed} ) { $Kernel::OM->Get('Kernel::System::Log')->Log( Priority => 'error', @@ -193,38 +193,44 @@ sub FormIDRemoveFile { # finish if files have been already removed by other process return if !@Index; - my $ID = $Param{FileID} - 1; - my %File = %{ $Index[$ID] }; + # Find and remove file with given filename; return success if + # file not found (to avoid error if user double clicks delete icon). + FILE: + for my $File (@Index) { + if ( $File->{Filename} eq $Param{Filename} ) { + my $Directory = $Self->{TempDir} . '/' . $Param{FormID}; - my $Directory = $Self->{TempDir} . '/' . $Param{FormID}; + if ( !-d $Directory ) { + return 1; + } - if ( !-d $Directory ) { - return 1; - } + # Get main object. + my $MainObject = $Kernel::OM->Get('Kernel::System::Main'); - # get main object - my $MainObject = $Kernel::OM->Get('Kernel::System::Main'); + $MainObject->FileDelete( + Directory => $Directory, + Filename => $File->{Filename}, + NoFilenameClean => 1, + ); + $MainObject->FileDelete( + Directory => $Directory, + Filename => $File->{Filename} . '.ContentType', + NoFilenameClean => 1, + ); + $MainObject->FileDelete( + Directory => $Directory, + Filename => $File->{Filename} . '.ContentID', + NoFilenameClean => 1, + ); + $MainObject->FileDelete( + Directory => $Directory, + Filename => $File->{Filename} . '.Disposition', + NoFilenameClean => 1, + ); - $MainObject->FileDelete( - Directory => $Directory, - Filename => "$File{Filename}", - NoReplace => 1, - ); - $MainObject->FileDelete( - Directory => $Directory, - Filename => "$File{Filename}.ContentType", - NoReplace => 1, - ); - $MainObject->FileDelete( - Directory => $Directory, - Filename => "$File{Filename}.ContentID", - NoReplace => 1, - ); - $MainObject->FileDelete( - Directory => $Directory, - Filename => "$File{Filename}.Disposition", - NoReplace => 1, - ); + last FILE; + } + } return 1; } @@ -258,8 +264,6 @@ sub FormIDGetAllFilesData { Filter => "*", ); - my $Counter = 0; - FILEPATH: for my $FilePath (@List) { @@ -268,7 +272,6 @@ sub FormIDGetAllFilesData { next FILEPATH if $FilePath =~ /\.ContentID$/; next FILEPATH if $FilePath =~ /\.Disposition$/; - $Counter++; my $FileSize = -s $FilePath; my $Filename = basename($FilePath); @@ -318,7 +321,6 @@ sub FormIDGetAllFilesData { ContentType => ${$ContentType}, Filename => $Filename, Filesize => $FileSize, - FileID => $Counter, Disposition => ${$Disposition}, }, ); @@ -356,8 +358,6 @@ sub FormIDGetAllFilesMeta { Filter => "*", ); - my $Counter = 0; - FILEPATH: for my $FilePath (@List) { @@ -366,7 +366,6 @@ sub FormIDGetAllFilesMeta { next FILEPATH if $FilePath =~ /\.ContentID$/; next FILEPATH if $FilePath =~ /\.Disposition$/; - $Counter++; my $FileSize = -s $FilePath; my $Filename = basename($FilePath); @@ -410,7 +409,6 @@ sub FormIDGetAllFilesMeta { ContentType => ${$ContentType}, Filename => $Filename, Filesize => $FileSize, - FileID => $Counter, Disposition => ${$Disposition}, }, ); diff --git a/scripts/test/WebUploadCache.t b/scripts/test/WebUploadCache.t index ad8fd8e95cd..369b19013f6 100644 --- a/scripts/test/WebUploadCache.t +++ b/scripts/test/WebUploadCache.t @@ -159,8 +159,8 @@ for my $Module (qw(DB FS)) { if ( $Module eq 'FS' ) { my $Delete = $UploadCacheObject->FormIDRemoveFile( - FormID => $InvalidFormID, - FileID => 1, + FormID => $InvalidFormID, + Filename => $ExpectedFilename, ); $Self->False( @@ -170,8 +170,8 @@ for my $Module (qw(DB FS)) { } my $Delete = $UploadCacheObject->FormIDRemoveFile( - FormID => $FormID, - FileID => 1, + FormID => $FormID, + Filename => $ExpectedFilename, ); $Self->True( $Delete || '', @@ -276,8 +276,8 @@ for my $Module (qw(DB FS)) { ); } my $Delete = $UploadCacheObject->FormIDRemoveFile( - FormID => $FormID, - FileID => 1, + FormID => $FormID, + Filename => $ExpectedFilename, ); $Self->True( $Delete || '', diff --git a/var/httpd/htdocs/js/Core.AJAX.js b/var/httpd/htdocs/js/Core.AJAX.js index 4440b8ba66a..298345b941d 100644 --- a/var/httpd/htdocs/js/Core.AJAX.js +++ b/var/httpd/htdocs/js/Core.AJAX.js @@ -220,7 +220,6 @@ Core.AJAX = (function (TargetNS) { 'Filename' : this.Filename, 'Filetype' : this.ContentType, 'Filesize' : this.Filesize, - 'FileID' : this.FileID, }); $(AttachmentItem).prependTo($('.AttachmentList tbody')).fadeIn(); diff --git a/var/httpd/htdocs/js/Core.UI.js b/var/httpd/htdocs/js/Core.UI.js index d06b8f9bba4..86f5b59a23a 100644 --- a/var/httpd/htdocs/js/Core.UI.js +++ b/var/httpd/htdocs/js/Core.UI.js @@ -715,10 +715,6 @@ Core.UI = (function (TargetNS) { $TargetObj = $ExistingItemObj.closest('tr'); - if ($TargetObj.find('a').data('file-id')) { - return; - } - $TargetObj .find('.Filetype') .text(Attachment.ContentType) @@ -728,8 +724,7 @@ Core.UI = (function (TargetNS) { .attr('data-file-size', Attachment.Filesize) .next('td') .find('a') - .removeClass('Hidden') - .data('file-id', Attachment.FileID); + .removeClass('Hidden'); } else { @@ -737,7 +732,6 @@ Core.UI = (function (TargetNS) { 'Filename' : Attachment.Filename, 'Filetype' : Attachment.ContentType, 'Filesize' : Attachment.Filesize, - 'FileID' : Attachment.FileID, }); $(AttachmentItem).prependTo($ContainerObj.find('.AttachmentList tbody')).fadeIn(); @@ -841,7 +835,7 @@ Core.UI = (function (TargetNS) { Data = { Action: $(this).data('delete-action') ? $(this).data('delete-action') : 'AjaxAttachment', Subaction: 'Delete', - FileID: $(this).data('file-id'), + Filename: $(this).closest('tr').find('td.Filename').text(), FormID: FormID, ObjectID: $(this).data('object-id'), FieldID: $(this).data('field-id'), @@ -855,12 +849,7 @@ Core.UI = (function (TargetNS) { $(this).remove(); - if (Response.Data && Response.Data.length) { - - // go through all attachments and update the FileIDs - $.each(Response.Data, function(index, Attachment) { - $AttachmentListContainerObj.find('.AttachmentList td:contains(' + Attachment.Filename + ')').closest('tr').find('a').data('file-id', Attachment.FileID); - }); + if (Response.NumberOfAttachmentsLeft && (Response.NumberOfAttachmentsLeft > 0)) { $AttachmentListContainerObj.find('.Busy').fadeOut(); } else {