-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #1295: added a stub for a S3 article storage backend
- Loading branch information
1 parent
07e0244
commit e6f9c6f
Showing
5 changed files
with
343 additions
and
10 deletions.
There are no files selected for viewing
301 changes: 301 additions & 0 deletions
301
Kernel/System/Ticket/Article/Backend/MIMEBase/ArticleStorageS3.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,301 @@ | ||
# -- | ||
# OTOBO is a web-based ticketing system for service organisations. | ||
# -- | ||
# Copyright (C) 2019-2021 Rother OSS GmbH, https://otobo.de/ | ||
# -- | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, either version 3 of the License, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# -- | ||
|
||
package Kernel::System::Ticket::Article::Backend::MIMEBase::ArticleStorageS3; | ||
|
||
use strict; | ||
use warnings; | ||
use v5.24; | ||
use namespace::autoclean; | ||
use utf8; | ||
|
||
use parent qw(Kernel::System::Ticket::Article::Backend::MIMEBase::Base); | ||
|
||
# core modules | ||
use MIME::Base64; | ||
|
||
# CPAN modules | ||
use MIME::Words qw(:all); | ||
use Amazon::S3::Thin; | ||
|
||
# OTOBO modules | ||
use Kernel::System::VariableCheck qw(:all); | ||
|
||
our @ObjectDependencies = ( | ||
'Kernel::System::Log', | ||
'Kernel::System::Main', | ||
); | ||
|
||
=head1 NAME | ||
Kernel::System::Ticket::Article::Backend::MIMEBase::ArticleStorageS3 - S3 based ticket article storage interface | ||
=head1 DESCRIPTION | ||
This class provides functions to manipulate ticket articles in the database. | ||
The methods are currently documented in L<Kernel::System::Ticket::Article::Backend::MIMEBase>. | ||
Inherits from L<Kernel::System::Ticket::Article::Backend::MIMEBase::Base>. | ||
See also L<Kernel::System::Ticket::Article::Backend::MIMEBase::ArticleStorageFS> and | ||
L<Kernel::System::Ticket::Article::Backend::MIMEBase::ArticleStorageDB>. | ||
=cut | ||
|
||
sub ArticleDelete { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
for my $Item (qw(ArticleID UserID)) { | ||
if ( !$Param{$Item} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need $Item!" | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
# delete attachments | ||
$Self->ArticleDeleteAttachment( | ||
ArticleID => $Param{ArticleID}, | ||
UserID => $Param{UserID}, | ||
); | ||
|
||
# delete plain message | ||
$Self->ArticleDeletePlain( | ||
ArticleID => $Param{ArticleID}, | ||
UserID => $Param{UserID}, | ||
); | ||
|
||
return 1; | ||
} | ||
|
||
sub ArticleDeletePlain { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
for my $Item (qw(ArticleID UserID)) { | ||
if ( !$Param{$Item} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need $Item!" | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
# delete attachments | ||
# TODO_S3 | ||
|
||
# the S3 backend does not support storing articles in mixed backends | ||
return 1; | ||
} | ||
|
||
sub ArticleDeleteAttachment { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
for my $Item (qw(ArticleID UserID)) { | ||
if ( !$Param{$Item} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need $Item!" | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
# delete attachments | ||
# TODO_S3 | ||
|
||
# the S3 backend does not support storing articles in mixed backends | ||
return 1; | ||
} | ||
|
||
sub ArticleWritePlain { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
for my $Item (qw(ArticleID Email UserID)) { | ||
if ( !$Param{$Item} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need $Item!" | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
# write article to S3 | ||
# TODO_S3 | ||
|
||
return 1; | ||
} | ||
|
||
sub ArticleWriteAttachment { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
for my $Item (qw(Filename ContentType ArticleID UserID)) { | ||
if ( !IsStringWithData( $Param{$Item} ) ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need $Item!" | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
$Param{Filename} = $Kernel::OM->Get('Kernel::System::Main')->FilenameCleanUp( | ||
Filename => $Param{Filename}, | ||
Type => 'Local', | ||
NoReplace => 1, | ||
); | ||
|
||
my $NewFileName = $Param{Filename}; | ||
my %UsedFile; | ||
my %Index = $Self->ArticleAttachmentIndex( | ||
ArticleID => $Param{ArticleID}, | ||
); | ||
|
||
for my $IndexFile ( sort keys %Index ) { | ||
$UsedFile{ $Index{$IndexFile}->{Filename} } = 1; | ||
} | ||
for ( my $i = 1; $i <= 50; $i++ ) { | ||
if ( exists $UsedFile{$NewFileName} ) { | ||
if ( $Param{Filename} =~ /^(.*)\.(.+?)$/ ) { | ||
$NewFileName = "$1-$i.$2"; | ||
} | ||
else { | ||
$NewFileName = "$Param{Filename}-$i"; | ||
} | ||
} | ||
} | ||
|
||
# get file name | ||
$Param{Filename} = $NewFileName; | ||
|
||
# get attachment size | ||
$Param{Filesize} = bytes::length( $Param{Content} ); | ||
|
||
# set content id in angle brackets | ||
if ( $Param{ContentID} ) { | ||
$Param{ContentID} =~ s/^([^<].*[^>])$/<$1>/; | ||
} | ||
|
||
my $Disposition; | ||
my $Filename; | ||
if ( $Param{Disposition} ) { | ||
( $Disposition, $Filename ) = split ';', $Param{Disposition}; | ||
} | ||
$Disposition //= ''; | ||
|
||
# write attachment to db | ||
# TODO_S3 | ||
|
||
return 1; | ||
} | ||
|
||
sub ArticlePlain { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
if ( !$Param{ArticleID} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need ArticleID!" | ||
); | ||
|
||
return; | ||
} | ||
|
||
# prepare/filter ArticleID | ||
$Param{ArticleID} = quotemeta( $Param{ArticleID} ); | ||
$Param{ArticleID} =~ s/\0//g; | ||
|
||
# TODO_S3 | ||
|
||
# the S3 backend does not support storing articles in mixed backends | ||
return 1; | ||
} | ||
|
||
sub ArticleAttachmentIndexRaw { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
if ( !$Param{ArticleID} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => 'Need ArticleID!' | ||
); | ||
|
||
return; | ||
} | ||
|
||
my %Index; | ||
my $Counter = 0; | ||
|
||
# TODO_S3 | ||
|
||
# return existing index | ||
return %Index if %Index; | ||
|
||
# the S3 backend does not support storing articles in mixed backends | ||
return 1; | ||
} | ||
|
||
sub ArticleAttachment { | ||
my ( $Self, %Param ) = @_; | ||
|
||
# check needed stuff | ||
for my $Item (qw(ArticleID FileID)) { | ||
if ( !$Param{$Item} ) { | ||
$Kernel::OM->Get('Kernel::System::Log')->Log( | ||
Priority => 'error', | ||
Message => "Need $Item!" | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
# prepare/filter ArticleID | ||
$Param{ArticleID} = quotemeta( $Param{ArticleID} ); | ||
$Param{ArticleID} =~ s/\0//g; | ||
|
||
# get attachment index | ||
my %Index = $Self->ArticleAttachmentIndex( | ||
ArticleID => $Param{ArticleID}, | ||
); | ||
|
||
return if !$Index{ $Param{FileID} }; | ||
|
||
my %Data = %{ $Index{ $Param{FileID} } }; | ||
|
||
# TODO_S3 | ||
|
||
return %Data if defined $Data{Content}; | ||
|
||
# the S3 backend does not support storing articles in mixed backends | ||
return; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.