Skip to content

Commit

Permalink
Issue #1295: introducing the method DiscardObject()
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Nov 27, 2021
1 parent 02749d1 commit 4904c22
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
40 changes: 40 additions & 0 deletions Kernel/System/Storage/S3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,44 @@ sub SaveObjectToFile {
return 1;
}

=head2 DiscardObject()
Remove an object from the S3 storage.
=cut

sub DiscardObject {
my ( $Self, %Param ) = @_;

# check needed params
for my $Needed (qw(Key)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Message => "Needed $Needed: $!",
Priority => 'error',
);

return;
}
}

my $KeyWithBucket = join '/', $Self->{Bucket}, $Self->{HomePrefix}, $Param{Key};
my $Now = Mojo::Date->new(time)->to_datetime;
my $URL = Mojo::URL->new
->scheme( $Self->{Scheme} )
->host( $Self->{Host} )
->path($KeyWithBucket);
my $Transaction = $Self->{S3Object}->signed_request(
method => 'DELETE',
datetime => $Now,
url => $URL,
);

# run blocking request
$Self->{UserAgent}->start($Transaction);

return 1 if $Transaction->result->is_success;
return;
}

1;
19 changes: 3 additions & 16 deletions Kernel/System/Ticket/Article/Backend/MIMEBase/ArticleStorageS3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,10 @@ sub ArticleDeletePlain {

# delete plain
my $FilePath = $Self->_FilePath( $Param{ArticleID}, 'plain.txt' );
my $Now = Mojo::Date->new(time)->to_datetime;
my $URL = Mojo::URL->new
->scheme( $Self->{Scheme} )
->host( $Self->{Host} )
->path( join '/', $Self->{Bucket}, $Self->{HomePrefix}, $FilePath );
my $Transaction = $Self->{S3Object}->signed_request(
method => 'DELETE',
datetime => $Now,
url => $URL,
);

# run blocking request
$Self->{UserAgent}->start($Transaction);

# the S3 backend does not support storing articles in mixed backends
# TODO: check success
return 1;
return $Self->{StorageS3Object}->DiscardObject(
Key => $FilePath,
);
}

sub ArticleDeleteAttachment {
Expand Down

0 comments on commit 4904c22

Please sign in to comment.