summaryrefslogtreecommitdiffstats
path: root/Bugzilla/API
diff options
context:
space:
mode:
authorMatt Tyson <mtyson@redhat.com>2016-01-15 15:44:09 +0100
committerGervase Markham <gerv@mozilla.org>2016-01-15 15:44:09 +0100
commit38e12dd8a2c0b35391f20b60e9e3e8643c08f404 (patch)
tree17bc36ed5ff0a19741fc88378fbddc2578936b2b /Bugzilla/API
parent513b4458b42e7f20ee0e57995c339c2dd6c495e7 (diff)
downloadbugzilla-38e12dd8a2c0b35391f20b60e9e3e8643c08f404.tar.gz
bugzilla-38e12dd8a2c0b35391f20b60e9e3e8643c08f404.tar.xz
'Bug 1159057: change to create flags as part of bug creation process. r=gerv
Diffstat (limited to 'Bugzilla/API')
-rw-r--r--Bugzilla/API/1_0/Resource/Bug.pm30
-rw-r--r--Bugzilla/API/1_0/Util.pm5
2 files changed, 22 insertions, 13 deletions
diff --git a/Bugzilla/API/1_0/Resource/Bug.pm b/Bugzilla/API/1_0/Resource/Bug.pm
index c6ae6a19a..a8565b7a0 100644
--- a/Bugzilla/API/1_0/Resource/Bug.pm
+++ b/Bugzilla/API/1_0/Resource/Bug.pm
@@ -820,7 +820,7 @@ sub update {
foreach my $bug (@bugs) {
$bug->set_all(\%values);
if ($flags) {
- my ($old_flags, $new_flags) = extract_flags($flags, $bug);
+ my ($old_flags, $new_flags) = extract_flags($flags, $bug->flag_types, $bug->flags);
$bug->set_flags($old_flags, $new_flags);
}
}
@@ -885,19 +885,29 @@ sub create {
my $flags = delete $params->{flags};
+ if ($flags) {
+ my $product = Bugzilla::Product->check($params->{product});
+ my $component = Bugzilla::Component->check({
+ product => $product,
+ name => $params->{component}
+ });
+ my $flag_types = Bugzilla::FlagType::match({
+ product_id => $product->id,
+ component_id => $component->id,
+ is_active => 1,
+ });
+
+ my(undef, $new_flags) = extract_flags($flags, $flag_types);
+
+ $params->{flags} = $new_flags;
+ }
+
# We start a nested transaction in case flag setting fails
# we want the bug creation to roll back as well.
$dbh->bz_start_transaction();
my $bug = Bugzilla::Bug->create($params);
- # Set bug flags
- if ($flags) {
- my ($flags, $new_flags) = extract_flags($flags, $bug);
- $bug->set_flags($flags, $new_flags);
- $bug->update($bug->creation_ts);
- }
-
$dbh->bz_commit_transaction();
$bug->send_changes();
@@ -989,7 +999,7 @@ sub add_attachment {
});
if ($flags) {
- my ($old_flags, $new_flags) = extract_flags($flags, $bug, $attachment);
+ my ($old_flags, $new_flags) = extract_flags($flags, $attachment->flag_types, $attachment->flags);
$attachment->set_flags($old_flags, $new_flags);
}
@@ -1066,7 +1076,7 @@ sub update_attachment {
# Update the values
foreach my $attachment (@attachments) {
my ($update_flags, $new_flags) = $flags
- ? extract_flags($flags, $attachment->bug, $attachment)
+ ? extract_flags($flags, $attachment->flag_types, $attachment->flags)
: ([], []);
if ($attachment->validate_can_edit) {
$attachment->set_all($params);
diff --git a/Bugzilla/API/1_0/Util.pm b/Bugzilla/API/1_0/Util.pm
index d22935f6e..afdde314e 100644
--- a/Bugzilla/API/1_0/Util.pm
+++ b/Bugzilla/API/1_0/Util.pm
@@ -51,11 +51,10 @@ our @EXPORT = qw(
);
sub extract_flags {
- my ($flags, $bug, $attachment) = @_;
+ my ($flags, $flag_types, $current_flags) = @_;
my (@new_flags, @old_flags);
- my $flag_types = $attachment ? $attachment->flag_types : $bug->flag_types;
- my $current_flags = $attachment ? $attachment->flags : $bug->flags;
+ $current_flags //= [];
# Copy the user provided $flags as we may call extract_flags more than
# once when editing multiple bugs or attachments.