Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renewed attempt at dockerization #92

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Bugzilla/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,23 @@ around 'attrs' => sub {
my $symbol = '&' . $method;
$stash->add_symbol(
$symbol => sub {
my $self = shift;
return $self->dbh->$method(@_);
my $self = shift;
my $wantarray = wantarray;
my $result = eval {
if ($wantarray) {
[$self->dbh->$method(@_)];
}
else {
[scalar $self->dbh->$method(@_)];
}
};
if (not defined $result) {
my $err = $@;
Carp::confess($err);
}
else {
return $wantarray ? @$result : $result->[0];
}
}
);
}
Expand Down Expand Up @@ -511,8 +526,8 @@ sub bz_server_version {
sub bz_last_key {
my ($self, $table, $column) = @_;

return $self->last_insert_id(Bugzilla->localconfig->db_name,
undef, $table, $column);
return $self->last_insert_id(Bugzilla->localconfig->db_name, undef, $table,
$column);
}

sub bz_check_regexp {
Expand Down Expand Up @@ -579,7 +594,7 @@ sub bz_setup_foreign_keys {
# so if it doesn't have them, then we're setting up FKs
# for the first time, and should be quieter about it.
my $activity_fk = $self->bz_fk_info('profiles_activity', 'userid');
my $any_fks = $activity_fk && $activity_fk->{created};
my $any_fks = $activity_fk && $activity_fk->{created};
if (!$any_fks) {
print get_text('install_fk_setup'), "\n";
}
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/Install/Localconfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ our @EXPORT_OK = qw(
);

# might want to change this for upstream
use constant ENV_PREFIX => 'BMO_';
use constant ENV_PREFIX => 'BZ_';
use constant PARAM_OVERRIDE =>
qw( use_mailer_queue mail_delivery_method shadowdb shadowdbhost shadowdbport shadowdbsock );

Expand All @@ -57,7 +57,7 @@ use constant LOCALCONFIG_VARS => (
{name => 'webservergroup', default => \&_sensible_group,},
{name => 'use_suexec', default => 0,},
{name => 'db_driver', default => 'mysql',},
{name => 'db_host', default => 'localhost',},
{name => 'db_host', default => '127.0.0.1',},
{name => 'db_name', default => 'bugs',},
{

Expand Down
101 changes: 57 additions & 44 deletions Bugzilla/WebService/Bug.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,23 @@ use constant ATTACHMENT_MAPPED_RETURNS => {
mimetype => 'content_type',
};

our %api_field_types = (
%{{map { $_ => 'double' } Bugzilla::Bug::NUMERIC_COLUMNS()}},
%{{map { $_ => 'dateTime' } Bugzilla::Bug::DATE_COLUMNS()}},
);
our $api_field_types = sub {
Bugzilla::request_cache->{api_field_types} ||= {
%{{map { $_ => 'double' } Bugzilla::Bug::NUMERIC_COLUMNS()}},
%{{map { $_ => 'dateTime' } Bugzilla::Bug::DATE_COLUMNS()}},
};
};

our %api_field_names = reverse %{Bugzilla::Bug::FIELD_MAP()};
# This doesn't normally belong in FIELD_MAP, but we do want to translate
# "bug_group" back into "groups".
$api_field_names{'bug_group'} = 'groups';
our $api_field_names = sub {
Bugzilla::request_cache->{api_field_types} ||= do {
my $tmp = {reverse %{Bugzilla::Bug::FIELD_MAP()}};

# This doesn't normally belong in FIELD_MAP, but we do want to translate
# "bug_group" back into "groups".
$tmp->{'bug_group'} = 'groups';
$tmp;
};
};

######################################################
# Add aliases here for old method name compatibility #
Expand Down Expand Up @@ -171,7 +179,7 @@ sub fields {
foreach my $field (@fields) {
my $visibility_field
= $field->visibility_field ? $field->visibility_field->name : undef;
my $vis_values = $field->visibility_values;
my $vis_values = $field->visibility_values;
my $value_field = $field->value_field ? $field->value_field->name : undef;

my (@values, $has_values);
Expand All @@ -180,27 +188,27 @@ sub fields {
or $field->name eq 'keywords')
{
$has_values = 1;
@values = @{$self->_legal_field_values({field => $field})};
@values = @{$self->_legal_field_values({field => $field})};
}

if (grep($_ eq $field->name, PRODUCT_SPECIFIC_FIELDS)) {
$value_field = 'product';
}

my %field_data = (
id => $self->type('int', $field->id),
type => $self->type('int', $field->type),
is_custom => $self->type('boolean', $field->custom),
name => $self->type('string', $field->name),
display_name => $self->type('string', $field->description),
is_mandatory => $self->type('boolean', $field->is_mandatory),
is_on_bug_entry => $self->type('boolean', $field->enter_bug),
visibility_field => $self->type('string', $visibility_field),
id => $self->type('int', $field->id),
type => $self->type('int', $field->type),
is_custom => $self->type('boolean', $field->custom),
name => $self->type('string', $field->name),
display_name => $self->type('string', $field->description),
is_mandatory => $self->type('boolean', $field->is_mandatory),
is_on_bug_entry => $self->type('boolean', $field->enter_bug),
visibility_field => $self->type('string', $visibility_field),
visibility_values => [map { $self->type('string', $_->name) } @$vis_values],
);
if ($has_values) {
$field_data{value_field} = $self->type('string', $value_field);
$field_data{values} = \@values;
$field_data{values} = \@values;
}
push(@fields_out, filter $params, \%field_data);
}
Expand Down Expand Up @@ -318,8 +326,8 @@ sub comments {
{function => 'Bug.comments', params => ['ids', 'comment_ids']});
}

my $bug_ids = $params->{ids} || [];
my $comment_ids = $params->{comment_ids} || [];
my $bug_ids = $params->{ids} || [];
my $comment_ids = $params->{comment_ids} || [];
my $skip_private = $params->{skip_private} ? 1 : 0;

my $dbh = Bugzilla->switch_to_shadow_db();
Expand All @@ -330,6 +338,7 @@ sub comments {
}

if ($skip_private) {

# Cache permissions for bugs. This highly reduces the number of calls to the DB.
# visible_bugs() is only able to handle bug IDs, so we have to skip aliases.
my @int = grep { $_ =~ /^\d+$/ } @$bug_ids;
Expand All @@ -343,7 +352,8 @@ sub comments {
if ($skip_private) {
$bug = Bugzilla::Bug->new({id => $bug_id, cache => 1});
next if $bug->error || !$user->can_see_bug($bug->id);
} else {
}
else {
$bug = Bugzilla::Bug->check($bug_id);
}

Expand All @@ -362,7 +372,7 @@ sub comments {

my %comments;
if (scalar @$comment_ids) {
my @ids = map { trim($_) } @$comment_ids;
my @ids = map { trim($_) } @$comment_ids;
my $comment_data = Bugzilla::Comment->new_from_list(\@ids);

# See if we were passed any invalid comment ids.
Expand Down Expand Up @@ -501,6 +511,7 @@ sub history {
my $skip_private = $params->{skip_private} ? 1 : 0;

if ($skip_private) {

# Cache permissions for bugs. This highly reduces the number of calls to the DB.
# visible_bugs() is only able to handle bug IDs, so we have to skip aliases.
my @int = grep { $_ =~ /^\d+$/ } @$ids;
Expand All @@ -515,7 +526,8 @@ sub history {
if ($skip_private) {
$bug = Bugzilla::Bug->new({id => $bug_id, cache => 1});
next if $bug->error || !$user->can_see_bug($bug->id);
} else {
}
else {
$bug = Bugzilla::Bug->check($bug_id);
}

Expand Down Expand Up @@ -586,7 +598,7 @@ sub search {

# Allow to search only in bug description (initial comment)
if (defined $match_params->{description}) {
$match_params->{longdesc} = delete $match_params->{description};
$match_params->{longdesc} = delete $match_params->{description};
$match_params->{longdesc_initial} = 1;
}

Expand All @@ -595,7 +607,7 @@ sub search {
my %options = (fields => ['bug_id']);

# Find the highest custom field id
my @field_ids = grep(/^f(\d+)$/, keys %$match_params);
my @field_ids = grep(/^f(\d+)$/, keys %$match_params);
my $last_field_id = @field_ids ? max @field_ids + 1 : 1;

# Do special search types for certain fields.
Expand Down Expand Up @@ -836,9 +848,10 @@ sub update {
}

my %changes = %{$all_changes{$bug->id}};
my $names = $api_field_names->();
foreach my $field (keys %changes) {
my $change = $changes{$field};
my $api_field = $api_field_names{$field} || $field;
my $change = $changes{$field};
my $api_field = $names->{$field} || $field;

# We normalize undef to an empty string, so that the API
# stays consistent for things like Deadline that can become
Expand Down Expand Up @@ -1194,10 +1207,9 @@ sub add_comment {
$bug->add_comment(
$comment,
{
isprivate => $params->{is_private},
work_time => $params->{work_time},
is_markdown =>
( defined $params->{is_markdown} ? $params->{is_markdown} : 0 )
isprivate => $params->{is_private},
work_time => $params->{work_time},
is_markdown => (defined $params->{is_markdown} ? $params->{is_markdown} : 0)
}
);

Expand Down Expand Up @@ -1481,7 +1493,7 @@ sub _bug_to_hash {
foreach my $attachment (@{$bug->attachments}) {
next if $attachment->isprivate && !$user->is_insider;
push(@result,
$self->_attachment_to_hash($attachment, $params, ['extra'], 'attachments'));
$self->_attachment_to_hash($attachment, $params, ['extra'], 'attachments'));
}
$item{'attachments'} = \@result;
}
Expand All @@ -1494,12 +1506,12 @@ sub _bug_to_hash {
}
if (filter_wants $params, 'comments', ['extra']) {
my @result;
my $comments
= $bug->comments({order => 'oldest_to_newest', after => $params->{new_since}});
my $comments = $bug->comments(
{order => 'oldest_to_newest', after => $params->{new_since}});
foreach my $comment (@$comments) {
next if $comment->is_private && !$user->is_insider;
push(@result,
$self->_translate_comment($comment, $params, ['extra'], 'comments'));
$self->_translate_comment($comment, $params, ['extra'], 'comments'));
}
$item{'comments'} = \@result;
}
Expand Down Expand Up @@ -1528,7 +1540,8 @@ sub _bug_to_hash {
my $comment = Bugzilla::Comment->match({bug_id => $bug->id, LIMIT => 1})->[0];
$item{'description'}
= ($comment && (!$comment->is_private || Bugzilla->user->is_insider))
? $comment->body : '';
? $comment->body
: '';
}
if (filter_wants $params, 'dupe_of') {
$item{'dupe_of'} = $self->type('int', $bug->dup_id);
Expand All @@ -1549,7 +1562,7 @@ sub _bug_to_hash {
= Bugzilla::Bug::GetBugActivity($bug->id, undef, $params->{new_since}, 1);
foreach my $changeset (@$activity) {
push(@result,
$self->_changeset_to_hash($changeset, $params, ['extra'], 'history'));
$self->_changeset_to_hash($changeset, $params, ['extra'], 'history'));
}
$item{'history'} = \@result;
}
Expand Down Expand Up @@ -1755,19 +1768,19 @@ sub _changeset_to_hash {

foreach my $change (@{$changeset->{changes}}) {
my $field_name = delete $change->{fieldname};
my $api_field_type = $api_field_types{$field_name} || 'string';
my $api_field_name = $api_field_names{$field_name} || $field_name;
my $api_field_type = $api_field_types->()->{$field_name} || 'string';
my $api_field_name = $api_field_names->()->{$field_name} || $field_name;
my $attach_id = delete $change->{attachid};
my $comment = delete $change->{comment};

$change->{field_name} = $self->type('string', $api_field_name);
$change->{removed} = $self->type($api_field_type, $change->{removed});
$change->{added} = $self->type($api_field_type, $change->{added});
$change->{field_name} = $self->type('string', $api_field_name);
$change->{removed} = $self->type($api_field_type, $change->{removed});
$change->{added} = $self->type($api_field_type, $change->{added});
$change->{attachment_id} = $self->type('int', $attach_id) if $attach_id;
$change->{comment_id} = $self->type('int', $comment->id) if $comment;
$change->{comment_count} = $self->type('int', $comment->count) if $comment;

push (@{$item->{changes}}, $change);
push(@{$item->{changes}}, $change);
}

return filter($filters, $item, $types, $prefix);
Expand Down
Loading