# all options for attachment_storage need to be handled here
if ($name eq 'database') {
require Bugzilla::Attachment::Storage::Database;
- return Bugzilla::Attachment::Storage::Database->new({attachment => $self});
+ return Bugzilla::Attachment::Storage::Database->new({attach_id => $self->id});
}
elsif ($name eq 'filesystem') {
require Bugzilla::Attachment::Storage::FileSystem;
- return Bugzilla::Attachment::Storage::FileSystem->new({attachment => $self});
+ return Bugzilla::Attachment::Storage::FileSystem->new({attach_id => $self->id});
}
elsif ($name eq 's3') {
require Bugzilla::Attachment::Storage::S3;
- return Bugzilla::Attachment::Storage::S3->new({attachment => $self});
+ return Bugzilla::Attachment::Storage::S3->new({attach_id => $self->id, datasize => $self->datasize});
}
else {
return undef;
use 5.10.1;
use Moo::Role;
-use Type::Utils qw(class_type);
+use Types::Standard qw(Int);
requires qw(set_data get_data remove_data data_exists data_type);
-has 'attachment' => (
+has 'attach_id' => (
is => 'ro',
required => 1,
- isa => class_type({class => 'Bugzilla::Attachment'})
+ isa => Int
);
sub set_class {
my ($self) = @_;
Bugzilla->dbh->do(
"REPLACE INTO attachment_storage_class (id, storage_class) VALUES (?, ?)",
- undef, $self->attachment->id, $self->data_type);
+ undef, $self->attach_id, $self->data_type);
return $self;
}
sub remove_class {
my ($self) = @_;
Bugzilla->dbh->do("DELETE FROM attachment_storage_class WHERE id = ?",
- undef, $self->attachment->id);
+ undef, $self->attach_id);
return $self;
}
= $dbh->prepare(
"REPLACE INTO attach_data (id, thedata) VALUES (?, ?)"
);
- $sth->bind_param(1, $self->attachment->id);
+ $sth->bind_param(1, $self->attach_id);
$sth->bind_param(2, $data, $dbh->BLOB_TYPE);
$sth->execute();
return $self;
my $dbh = Bugzilla->dbh;
my ($data)
= $dbh->selectrow_array("SELECT thedata FROM attach_data WHERE id = ?",
- undef, $self->attachment->id);
+ undef, $self->attach_id);
return $data;
}
sub remove_data {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
- $dbh->do("DELETE FROM attach_data WHERE id = ?", undef, $self->attachment->id);
+ $dbh->do("DELETE FROM attach_data WHERE id = ?", undef, $self->attach_id);
return $self;
}
my ($self) = @_;
my $dbh = Bugzilla->dbh;
my ($exists) = $dbh->selectrow_array("SELECT 1 FROM attach_data WHERE id = ?",
- undef, $self->attachment->id);
+ undef, $self->attach_id);
return !!$exists;
}
sub _local_path {
my ($self) = @_;
- my $hash = sprintf 'group.%03d', $self->attachment->id % 1000;
+ my $hash = sprintf 'group.%03d', $self->attach_id % 1000;
return bz_locations()->{attachdir} . '/' . $hash;
}
sub _local_file {
my ($self) = @_;
- return $self->_local_path() . '/attachment.' . $self->attachment->id;
+ return $self->_local_path() . '/attachment.' . $self->attach_id;
}
1;
use Bugzilla::Error;
use Bugzilla::S3;
+use Types::Standard qw(Int);
+
with 'Bugzilla::Attachment::Storage::Base';
has 's3' => (is => 'lazy');
has 'bucket' => (is => 'lazy');
+has 'datasize' => (
+ is => 'ro',
+ required => 1,
+ isa => Int
+);
sub _build_s3 {
my $self = shift;
sub set_data {
my ($self, $data) = @_;
- my $attach_id = $self->attachment->id;
+ my $attach_id = $self->attach_id;
# If the attachment is larger than attachment_s3_minsize,
# we instead store it in the database.
if (Bugzilla->params->{attachment_s3_minsize}
- && $self->attachment->datasize < Bugzilla->params->{attachment_s3_minsize})
+ && $self->datasize < Bugzilla->params->{attachment_s3_minsize})
{
require Bugzilla::Attachment::Storage::Database;
- return Bugzilla::Attachment::Storage::Database->new({attachment => $self->attachment})
+ return Bugzilla::Attachment::Storage::Database->new({attach_id => $self->attach_id})
->set_data($data);
}
sub get_data {
my ($self) = @_;
- my $attach_id = $self->attachment->id;
+ my $attach_id = $self->attach_id;
my $response = $self->bucket->get_key($attach_id);
if (!$response) {
warn "Failed to retrieve attachment $attach_id from S3: "
sub remove_data {
my ($self) = @_;
- my $attach_id = $self->attachment->id;
+ my $attach_id = $self->attach_id;
$self->bucket->delete_key($attach_id)
or warn "Failed to remove attachment $attach_id from S3: "
. $self->bucket->errstr . "\n";
sub data_exists {
my ($self) = @_;
- return !!$self->bucket->head_key($self->attachment->id);
+ return !!$self->bucket->head_key($self->attach_id);
}
1;
);
INFO($log_message);
-# change to the phabricator user, which returns a guard that restores the previous user.
+ # change to the phabricator user, which returns a guard that restores the previous user.
my $restore_prev_user = set_phab_user();
my $bug = $revision->bug;
INFO('Checking for revision attachment');
my $rev_attachment = create_revision_attachment($bug, $revision, $timestamp,
- $revision->author->bugzilla_user);
+ $revision->author->bugzilla_user);
INFO('Attachment ' . $rev_attachment->id . ' created or already exists.');
# ATTACHMENT OBSOLETES
f7 => 'reporter',
o7 => 'equals',
v7 => $bug_user->login,
-
f9 => 'CP',
# The bug needs to be private