Bug.pm 87 KB
Newer Older
1 2 3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
#
5 6
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
7 8 9 10 11 12

package Bugzilla::WebService::Bug;

use strict;
use base qw(Bugzilla::WebService);

13
use Bugzilla::Comment;
14 15 16
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Field;
17
use Bugzilla::WebService::Constants;
18
use Bugzilla::WebService::Util qw(filter filter_wants validate);
19
use Bugzilla::Bug;
20
use Bugzilla::BugMail;
21
use Bugzilla::Util qw(trick_taint trim);
22 23 24
use Bugzilla::Version;
use Bugzilla::Milestone;
use Bugzilla::Status;
25
use Bugzilla::Token qw(issue_hash_token);
26 27 28 29 30

#############
# Constants #
#############

31 32
use constant PRODUCT_SPECIFIC_FIELDS => qw(version target_milestone component);

33 34 35 36 37
use constant DATE_FIELDS => {
    comments => ['new_since'],
    search   => ['last_change_time', 'creation_time'],
};

38 39 40 41
use constant BASE64_FIELDS => {
    add_attachment => ['data'],
};

42 43 44 45 46 47 48 49 50 51
use constant READ_ONLY => qw(
    attachments
    comments
    fields
    get
    history
    legal_values
    search
);

52 53 54 55
######################################################
# Add aliases here for old method name compatibility #
######################################################

56 57 58 59 60 61
BEGIN { 
  # In 3.0, get was called get_bugs
  *get_bugs = \&get;
  # Before 3.4rc1, "history" was get_history.
  *get_history = \&history;
}
62

63 64 65
###########
# Methods #
###########
66

67 68 69
sub fields {
    my ($self, $params) = validate(@_, 'ids', 'names');

70 71
    Bugzilla->switch_to_shadow_db();

72 73 74 75 76 77 78 79 80 81 82 83 84
    my @fields;
    if (defined $params->{ids}) {
        my $ids = $params->{ids};
        foreach my $id (@$ids) {
            my $loop_field = Bugzilla::Field->check({ id => $id });
            push(@fields, $loop_field);
        }
    }

    if (defined $params->{names}) {
        my $names = $params->{names};
        foreach my $field_name (@$names) {
            my $loop_field = Bugzilla::Field->check($field_name);
85 86 87 88 89
            # Don't push in duplicate fields if we also asked for this field
            # in "ids".
            if (!grep($_->id == $loop_field->id, @fields)) {
                push(@fields, $loop_field);
            }
90 91 92
        }
    }

93
    if (!defined $params->{ids} and !defined $params->{names}) {
94
        @fields = @{ Bugzilla->fields({ obsolete => 0 }) };
95 96 97 98
    }

    my @fields_out;
    foreach my $field (@fields) {
99
        my $visibility_field = $field->visibility_field
100
                               ? $field->visibility_field->name : undef;
101
        my $vis_values = $field->visibility_values;
102 103 104
        my $value_field = $field->value_field
                          ? $field->value_field->name : undef;

105
        my (@values, $has_values);
106 107 108
        if ( ($field->is_select and $field->name ne 'product')
             or grep($_ eq $field->name, PRODUCT_SPECIFIC_FIELDS))
        {
109
             $has_values = 1;
110 111 112 113 114 115 116
             @values = @{ $self->_legal_field_values({ field => $field }) };
        }

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

117
        my %field_data = (
118 119 120 121 122
           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),
123
           is_mandatory      => $self->type('boolean', $field->is_mandatory),
124 125
           is_on_bug_entry   => $self->type('boolean', $field->enter_bug),
           visibility_field  => $self->type('string', $visibility_field),
126 127
           visibility_values =>
              [ map { $self->type('string', $_->name) } @$vis_values ],
128 129 130 131 132 133
        );
        if ($has_values) {
           $field_data{value_field} = $self->type('string', $value_field);
           $field_data{values}      = \@values;
        };
        push(@fields_out, filter $params, \%field_data);
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    }

    return { fields => \@fields_out };
}

sub _legal_field_values {
    my ($self, $params) = @_;
    my $field = $params->{field};
    my $field_name = $field->name;
    my $user = Bugzilla->user;

    my @result;
    if (grep($_ eq $field_name, PRODUCT_SPECIFIC_FIELDS)) {
        my @list;
        if ($field_name eq 'version') {
            @list = Bugzilla::Version->get_all;
        }
        elsif ($field_name eq 'component') {
            @list = Bugzilla::Component->get_all;
        }
        else {
            @list = Bugzilla::Milestone->get_all;
        }

        foreach my $value (@list) {
            my $sortkey = $field_name eq 'target_milestone'
                          ? $value->sortkey : 0;
            # XXX This is very slow for large numbers of values.
            my $product_name = $value->product->name;
            if ($user->can_see_product($product_name)) {
                push(@result, {
165 166 167
                    name     => $self->type('string', $value->name),
                    sort_key => $self->type('int', $sortkey),
                    sortkey  => $self->type('int', $sortkey), # deprecated
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
                    visibility_values => [$self->type('string', $product_name)],
                });
            }
        }
    }

    elsif ($field_name eq 'bug_status') {
        my @status_all = Bugzilla::Status->get_all;
        foreach my $status (@status_all) {
            my @can_change_to;
            foreach my $change_to (@{ $status->can_change_to }) {
                # There's no need to note that a status can transition
                # to itself.
                next if $change_to->id == $status->id;
                my %change_to_hash = (
                    name => $self->type('string', $change_to->name),
                    comment_required => $self->type('boolean', 
                        $change_to->comment_required_on_change_from($status)),
                );
                push(@can_change_to, \%change_to_hash);
            }

            push (@result, {
191 192 193
               name     => $self->type('string', $status->name),
               is_open  => $self->type('boolean', $status->is_open),
               sort_key => $self->type('int', $status->sortkey),
Frédéric Buclin's avatar
Frédéric Buclin committed
194
               sortkey  => $self->type('int', $status->sortkey), # deprecated
195
               can_change_to => \@can_change_to,
196
               visibility_values => [],
197 198 199 200 201 202 203
            });
        }
    }

    else {
        my @values = Bugzilla::Field::Choice->type($field)->get_all();
        foreach my $value (@values) {
204
            my $vis_val = $value->visibility_value;
205
            push(@result, {
206 207
                name     => $self->type('string', $value->name),
                sort_key => $self->type('int'   , $value->sortkey),
Frédéric Buclin's avatar
Frédéric Buclin committed
208
                sortkey  => $self->type('int'   , $value->sortkey), # deprecated
209 210 211 212
                visibility_values => [
                    defined $vis_val ? $self->type('string', $vis_val->name) 
                                     : ()
                ],
213 214 215 216 217 218 219
            });
        }
    }

    return \@result;
}

220
sub comments {
221
    my ($self, $params) = validate(@_, 'ids', 'comment_ids');
222

223
    if (!(defined $params->{ids} || defined $params->{comment_ids})) {
224 225
        ThrowCodeError('params_required',
                       { function => 'Bug.comments',
226
                         params   => ['ids', 'comment_ids'] });
227 228
    }

229
    my $bug_ids = $params->{ids} || [];
230 231
    my $comment_ids = $params->{comment_ids} || [];

232
    my $dbh  = Bugzilla->switch_to_shadow_db();
233 234 235 236 237 238
    my $user = Bugzilla->user;

    my %bugs;
    foreach my $bug_id (@$bug_ids) {
        my $bug = Bugzilla::Bug->check($bug_id);
        # We want the API to always return comments in the same order.
239 240 241
   
        my $comments = $bug->comments({ order => 'oldest_to_newest',
                                        after => $params->{new_since} });
242 243
        my @result;
        foreach my $comment (@$comments) {
244
            next if $comment->is_private && !$user->is_insider;
245 246 247 248 249 250 251 252
            push(@result, $self->_translate_comment($comment, $params));
        }
        $bugs{$bug->id}{'comments'} = \@result;
    }

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

        # See if we were passed any invalid comment ids.
256
        my %got_ids = map { $_->id => 1 } @$comment_data;
257 258 259 260 261 262 263
        foreach my $comment_id (@ids) {
            if (!$got_ids{$comment_id}) {
                ThrowUserError('comment_id_invalid', { id => $comment_id });
            }
        }
 
        # Now make sure that we can see all the associated bugs.
264
        my %got_bug_ids = map { $_->bug_id => 1 } @$comment_data;
265 266 267
        Bugzilla::Bug->check($_) foreach (keys %got_bug_ids);

        foreach my $comment (@$comment_data) {
268 269
            if ($comment->is_private && !$user->is_insider) {
                ThrowUserError('comment_is_private', { id => $comment->id });
270
            }
271
            $comments{$comment->id} =
272 273 274 275 276 277 278 279 280 281
                $self->_translate_comment($comment, $params);
        }
    }

    return { bugs => \%bugs, comments => \%comments };
}

# Helper for Bug.comments
sub _translate_comment {
    my ($self, $comment, $filters) = @_;
282 283
    my $attach_id = $comment->is_about_attachment ? $comment->extra_data
                                                  : undef;
284
    return filter $filters, {
285 286
        id         => $self->type('int', $comment->id),
        bug_id     => $self->type('int', $comment->bug_id),
287
        creator    => $self->type('string', $comment->author->login),
288 289 290 291
        author     => $self->type('string', $comment->author->login),
        time       => $self->type('dateTime', $comment->creation_ts),
        is_private => $self->type('boolean', $comment->is_private),
        text       => $self->type('string', $comment->body_full),
292
        attachment_id => $self->type('int', $attach_id),
293
        count      => $self->type('int', $comment->count),
294 295 296
    };
}

297
sub get {
298 299
    my ($self, $params) = validate(@_, 'ids');

300 301
    Bugzilla->switch_to_shadow_db();

302 303 304
    my $ids = $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

305 306
    my @bugs;
    my @faults;
307
    foreach my $bug_id (@$ids) {
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
        my $bug;
        if ($params->{permissive}) {
            eval { $bug = Bugzilla::Bug->check($bug_id); };
            if ($@) {
                push(@faults, {id => $bug_id,
                               faultString => $@->faultstring,
                               faultCode => $@->faultcode,
                              }
                    );
                undef $@;
                next;
            }
        }
        else {
            $bug = Bugzilla::Bug->check($bug_id);
        }
324
        push(@bugs, $self->_bug_to_hash($bug, $params));
325
    }
326

327
    return { bugs => \@bugs, faults => \@faults };
328 329
}

330 331
# this is a function that gets bug activity for list of bug ids 
# it can be called as the following:
332 333
# $call = $rpc->call( 'Bug.history', { ids => [1,2] });
sub history {
334
    my ($self, $params) = validate(@_, 'ids');
335

336 337
    Bugzilla->switch_to_shadow_db();

338 339 340 341
    my $ids = $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

    my @return;
342

343 344
    foreach my $bug_id (@$ids) {
        my %item;
345 346
        my $bug = Bugzilla::Bug->check($bug_id);
        $bug_id = $bug->id;
347
        $item{id} = $self->type('int', $bug_id);
348

349
        my ($activity) = $bug->get_activity;
350

351
        my @history;
352 353
        foreach my $changeset (@$activity) {
            my %bug_history;
354
            $bug_history{when} = $self->type('dateTime', $changeset->{when});
355
            $bug_history{who}  = $self->type('string', $changeset->{who});
356 357 358 359
            $bug_history{changes} = [];
            foreach my $change (@{ $changeset->{changes} }) {
                my $attach_id = delete $change->{attachid};
                if ($attach_id) {
360
                    $change->{attachment_id} = $self->type('int', $attach_id);
361
                }
362 363 364
                $change->{removed} = $self->type('string', $change->{removed});
                $change->{added}   = $self->type('string', $change->{added});
                $change->{field_name} = $self->type('string',
365 366 367 368
                    delete $change->{fieldname});
                push (@{$bug_history{changes}}, $change);
            }
            
369 370 371 372
            push (@history, \%bug_history);
        }

        $item{history} = \@history;
373 374 375 376

        # alias is returned in case users passes a mixture of ids and aliases
        # then they get to know which bug activity relates to which value  
        # they passed
377
        $item{alias} = $self->type('string', $bug->alias);
378 379 380 381 382 383

        push(@return, \%item);
    }

    return { bugs => \@return };
}
384

385 386
sub search {
    my ($self, $params) = @_;
387 388 389
   
    Bugzilla->switch_to_shadow_db();

390 391 392
    if ( defined($params->{offset}) and !defined($params->{limit}) ) {
        ThrowCodeError('param_required', 
                       { param => 'limit', function => 'Bug.search()' });
393 394
    }
    
395
    $params = Bugzilla::Bug::map_fields($params);
396
    delete $params->{WHERE};
397 398 399 400 401

    unless (Bugzilla->user->is_timetracker) {
        delete $params->{$_} foreach qw(estimated_time remaining_time deadline);
    }

402
    # Do special search types for certain fields.
403
    if ( my $bug_when = delete $params->{delta_ts} ) {
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
        $params->{WHERE}->{'delta_ts >= ?'} = $bug_when;
    }
    if (my $when = delete $params->{creation_ts}) {
        $params->{WHERE}->{'creation_ts >= ?'} = $when;
    }
    if (my $summary = delete $params->{short_desc}) {
        my @strings = ref $summary ? @$summary : ($summary);
        my @likes = ("short_desc LIKE ?") x @strings;
        my $clause = join(' OR ', @likes);
        $params->{WHERE}->{"($clause)"} = [map { "\%$_\%" } @strings];
    }
    if (my $whiteboard = delete $params->{status_whiteboard}) {
        my @strings = ref $whiteboard ? @$whiteboard : ($whiteboard);
        my @likes = ("status_whiteboard LIKE ?") x @strings;
        my $clause = join(' OR ', @likes);
        $params->{WHERE}->{"($clause)"} = [map { "\%$_\%" } @strings];
420
    }
421 422 423 424 425 426 427 428 429
   
    # We want include_fields and exclude_fields to be passed to
    # _bug_to_hash but not to Bugzilla::Bug->match so we copy the 
    # params and delete those before passing to Bugzilla::Bug->match.
    my %match_params = %{ $params };
    delete $match_params{'include_fields'};
    delete $match_params{'exclude_fields'};

    my $bugs = Bugzilla::Bug->match(\%match_params);
430
    my $visible = Bugzilla->user->visible_bugs($bugs);
431 432 433 434 435 436 437 438
    my @hashes = map { $self->_bug_to_hash($_, $params) } @$visible;
    return { bugs => \@hashes };
}

sub possible_duplicates {
    my ($self, $params) = validate(@_, 'product');
    my $user = Bugzilla->user;

439 440
    Bugzilla->switch_to_shadow_db();

441 442 443 444 445 446 447 448 449 450 451 452 453 454
    # Undo the array-ification that validate() does, for "summary".
    $params->{summary} || ThrowCodeError('param_required',
        { function => 'Bug.possible_duplicates', param => 'summary' });

    my @products;
    foreach my $name (@{ $params->{'product'} || [] }) {
        my $object = $user->can_enter_product($name, THROW_ERROR);
        push(@products, $object);
    }

    my $possible_dupes = Bugzilla::Bug->possible_duplicates(
        { summary => $params->{summary}, products => \@products,
          limit   => $params->{limit} });
    my @hashes = map { $self->_bug_to_hash($_, $params) } @$possible_dupes;
455 456 457
    return { bugs => \@hashes };
}

458 459 460 461 462 463
sub update {
    my ($self, $params) = validate(@_, 'ids');

    my $user = Bugzilla->login(LOGIN_REQUIRED);
    my $dbh = Bugzilla->dbh;

464 465 466 467
    # We skip certain fields because their set_ methods actually use
    # the external names instead of the internal names.
    $params = Bugzilla::Bug::map_fields($params, 
        { summary => 1, platform => 1, severity => 1, url => 1 });
468 469 470 471

    my $ids = delete $params->{ids};
    defined $ids || ThrowCodeError('param_required', { param => 'ids' });

472
    my @bugs = map { Bugzilla::Bug->check_for_edit($_) } @$ids;
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517

    my %values = %$params;
    $values{other_bugs} = \@bugs;

    if (exists $values{comment} and exists $values{comment}{comment}) {
        $values{comment}{body} = delete $values{comment}{comment};
    }

    # Prevent bugs that could be triggered by specifying fields that
    # have valid "set_" functions in Bugzilla::Bug, but shouldn't be
    # called using those field names.
    delete $values{dependencies};
    delete $values{flags};

    foreach my $bug (@bugs) {
        $bug->set_all(\%values);
    }

    my %all_changes;
    $dbh->bz_start_transaction();
    foreach my $bug (@bugs) {
        $all_changes{$bug->id} = $bug->update();
    }
    $dbh->bz_commit_transaction();
    
    foreach my $bug (@bugs) {
        $bug->send_changes($all_changes{$bug->id});
    }

    my %api_name = 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_name{'bug_group'} = 'groups';

    my @result;
    foreach my $bug (@bugs) {
        my %hash = (
            id               => $self->type('int', $bug->id),
            last_change_time => $self->type('dateTime', $bug->delta_ts),
            changes          => {},
        );

        # alias is returned in case users pass a mixture of ids and aliases,
        # so that they can know which set of changes relates to which value
        # they passed.
518
        $hash{alias} = $self->type('string', $bug->alias);
519 520 521 522 523

        my %changes = %{ $all_changes{$bug->id} };
        foreach my $field (keys %changes) {
            my $change = $changes{$field};
            my $api_field = $api_name{$field} || $field;
524 525 526 527 528
            # We normalize undef to an empty string, so that the API
            # stays consistent for things like Deadline that can become
            # empty.
            $change->[0] = '' if !defined $change->[0];
            $change->[1] = '' if !defined $change->[1];
529 530 531 532 533 534 535 536 537 538 539 540
            $hash{changes}->{$api_field} = {
                removed => $self->type('string', $change->[0]),
                added   => $self->type('string', $change->[1]) 
            };
        }

        push(@result, \%hash);
    }

    return { bugs => \@result };
}

541 542 543
sub create {
    my ($self, $params) = @_;
    Bugzilla->login(LOGIN_REQUIRED);
544
    $params = Bugzilla::Bug::map_fields($params);
545
    my $bug = Bugzilla::Bug->create($params);
546
    Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter });
547
    return { id => $self->type('int', $bug->bug_id) };
548 549
}

550 551
sub legal_values {
    my ($self, $params) = @_;
552

553 554
    Bugzilla->switch_to_shadow_db();

555 556 557
    defined $params->{field} 
        or ThrowCodeError('param_required', { param => 'field' });

558 559
    my $field = Bugzilla::Bug::FIELD_MAP->{$params->{field}} 
                || $params->{field};
560

561 562
    my @global_selects =
        @{ Bugzilla->fields({ is_select => 1, is_abnormal => 0 }) };
563 564

    my $values;
565
    if (grep($_->name eq $field, @global_selects)) {
566 567
        # The field is a valid one.
        trick_taint($field);
568 569 570 571 572 573 574
        $values = get_legal_field_values($field);
    }
    elsif (grep($_ eq $field, PRODUCT_SPECIFIC_FIELDS)) {
        my $id = $params->{product_id};
        defined $id || ThrowCodeError('param_required',
            { function => 'Bug.legal_values', param => 'product_id' });
        grep($_->id eq $id, @{Bugzilla->user->get_accessible_products})
575
            || ThrowUserError('product_access_denied', { id => $id });
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596

        my $product = new Bugzilla::Product($id);
        my @objects;
        if ($field eq 'version') {
            @objects = @{$product->versions};
        }
        elsif ($field eq 'target_milestone') {
            @objects = @{$product->milestones};
        }
        elsif ($field eq 'component') {
            @objects = @{$product->components};
        }

        $values = [map { $_->name } @objects];
    }
    else {
        ThrowCodeError('invalid_field_name', { field => $params->{field} });
    }

    my @result;
    foreach my $val (@$values) {
597
        push(@result, $self->type('string', $val));
598 599 600 601 602
    }

    return { values => \@result };
}

603 604 605 606 607 608 609 610 611 612
sub add_attachment {
    my ($self, $params) = validate(@_, 'ids');
    my $dbh = Bugzilla->dbh;

    Bugzilla->login(LOGIN_REQUIRED);
    defined $params->{ids}
        || ThrowCodeError('param_required', { param => 'ids' });
    defined $params->{data}
        || ThrowCodeError('param_required', { param => 'data' });

613
    my @bugs = map { Bugzilla::Bug->check_for_edit($_) } @{ $params->{ids} };
614 615 616

    my @created;
    $dbh->bz_start_transaction();
617 618
    my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');

619 620 621
    foreach my $bug (@bugs) {
        my $attachment = Bugzilla::Attachment->create({
            bug         => $bug,
622
            creation_ts => $timestamp,
623 624 625 626 627 628 629 630 631 632 633 634 635 636
            data        => $params->{data},
            description => $params->{summary},
            filename    => $params->{file_name},
            mimetype    => $params->{content_type},
            ispatch     => $params->{is_patch},
            isprivate   => $params->{is_private},
        });
        my $comment = $params->{comment} || '';
        $attachment->bug->add_comment($comment, 
            { isprivate  => $attachment->isprivate,
              type       => CMT_ATTACHMENT_CREATED,
              extra_data => $attachment->id });
        push(@created, $attachment);
    }
637
    $_->bug->update($timestamp) foreach @created;
638 639 640 641 642 643 644 645 646 647
    $dbh->bz_commit_transaction();

    $_->send_changes() foreach @bugs;

    my %attachments = map { $_->id => $self->_attachment_to_hash($_, $params) }
                          @created;

    return { attachments => \%attachments };
}

648 649
sub add_comment {
    my ($self, $params) = @_;
650 651 652 653

    # The user must login in order add a comment
    my $user = Bugzilla->login(LOGIN_REQUIRED);

654 655
    # Check parameters
    defined $params->{id} 
656
        || ThrowCodeError('param_required', { param => 'id' }); 
657
    my $comment = $params->{comment}; 
658
    (defined $comment && trim($comment) ne '')
659 660
        || ThrowCodeError('param_required', { param => 'comment' });
    
661
    my $bug = Bugzilla::Bug->check_for_edit($params->{id});
662

663 664 665 666
    # Backwards-compatibility for versions before 3.6    
    if (defined $params->{private}) {
        $params->{is_private} = delete $params->{private};
    }
667
    # Append comment
668
    $bug->add_comment($comment, { isprivate => $params->{is_private},
669
                                  work_time => $params->{work_time} });
670 671 672 673 674 675 676
    
    # Capture the call to bug->update (which creates the new comment) in 
    # a transaction so we're sure to get the correct comment_id.
    
    my $dbh = Bugzilla->dbh;
    $dbh->bz_start_transaction();
    
677 678
    $bug->update();
    
679 680 681 682
    my $new_comment_id = $dbh->bz_last_key('longdescs', 'comment_id');
    
    $dbh->bz_commit_transaction();
    
683
    # Send mail.
684 685
    Bugzilla::BugMail::Send($bug->bug_id, { changer => $user });

686
    return { id => $self->type('int', $new_comment_id) };
687 688
}

689 690 691 692 693 694 695 696 697 698 699 700 701 702
sub update_see_also {
    my ($self, $params) = @_;

    my $user = Bugzilla->login(LOGIN_REQUIRED);

    # Check parameters
    $params->{ids}
        || ThrowCodeError('param_required', { param => 'id' });
    my ($add, $remove) = @$params{qw(add remove)};
    ($add || $remove)
        or ThrowCodeError('params_required', { params => ['add', 'remove'] });

    my @bugs;
    foreach my $id (@{ $params->{ids} }) {
703
        my $bug = Bugzilla::Bug->check_for_edit($id);
704 705 706 707 708 709 710 711 712 713 714 715 716
        push(@bugs, $bug);
        if ($remove) {
            $bug->remove_see_also($_) foreach @$remove;
        }
        if ($add) {
            $bug->add_see_also($_) foreach @$add;
        }
    }
    
    my %changes;
    foreach my $bug (@bugs) {
        my $change = $bug->update();
        if (my $see_also = $change->{see_also}) {
717
            $changes{$bug->id}->{see_also} = {
718 719 720 721 722 723
                removed => [split(', ', $see_also->[0])],
                added   => [split(', ', $see_also->[1])],
            };
        }
        else {
            # We still want a changes entry, for API consistency.
724
            $changes{$bug->id}->{see_also} = { added => [], removed => [] };
725 726
        }

727
        Bugzilla::BugMail::Send($bug->id, { changer => $user });
728 729 730 731 732
    }

    return { changes => \%changes };
}

733
sub attachments {
734
    my ($self, $params) = validate(@_, 'ids', 'attachment_ids');
735

736 737
    Bugzilla->switch_to_shadow_db();

738
    if (!(defined $params->{ids}
739
          or defined $params->{attachment_ids}))
740 741 742 743 744 745 746 747 748 749
    {
        ThrowCodeError('param_required',
                       { function => 'Bug.attachments', 
                         params   => ['ids', 'attachment_ids'] });
    }

    my $ids = $params->{ids} || [];
    my $attach_ids = $params->{attachment_ids} || [];

    my %bugs;
750 751
    foreach my $bug_id (@$ids) {
        my $bug = Bugzilla::Bug->check($bug_id);
752
        $bugs{$bug->id} = [];
753
        foreach my $attach (@{$bug->attachments}) {
754
            push @{$bugs{$bug->id}},
755 756 757
                $self->_attachment_to_hash($attach, $params);
        }
    }
758 759 760 761 762 763 764 765 766 767 768 769 770

    my %attachments;
    foreach my $attach (@{Bugzilla::Attachment->new_from_list($attach_ids)}) {
        Bugzilla::Bug->check($attach->bug_id);
        if ($attach->isprivate && !Bugzilla->user->is_insider) {
            ThrowUserError('auth_failure', {action    => 'access',
                                            object    => 'attachment',
                                            attach_id => $attach->id});
        }
        $attachments{$attach->id} =
            $self->_attachment_to_hash($attach, $params);
    }

771
    return { bugs => \%bugs, attachments => \%attachments };
772 773
}

774 775 776 777
##############################
# Private Helper Subroutines #
##############################

778 779 780 781 782
# A helper for get() and search(). This is done in this fashion in order
# to produce a stable API and to explicitly type return values.
# The internals of Bugzilla::Bug are not stable enough to just
# return them directly.

783
sub _bug_to_hash {
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
    my ($self, $bug, $params) = @_;

    # All the basic bug attributes are here, in alphabetical order.
    # A bug attribute is "basic" if it doesn't require an additional
    # database call to get the info.
    my %item = (
        alias            => $self->type('string', $bug->alias),
        classification   => $self->type('string', $bug->classification),
        component        => $self->type('string', $bug->component),
        creation_time    => $self->type('dateTime', $bug->creation_ts),
        id               => $self->type('int', $bug->bug_id),
        is_confirmed     => $self->type('boolean', $bug->everconfirmed),
        last_change_time => $self->type('dateTime', $bug->delta_ts),
        op_sys           => $self->type('string', $bug->op_sys),
        platform         => $self->type('string', $bug->rep_platform),
        priority         => $self->type('string', $bug->priority),
        product          => $self->type('string', $bug->product),
        resolution       => $self->type('string', $bug->resolution),
        severity         => $self->type('string', $bug->bug_severity),
        status           => $self->type('string', $bug->bug_status),
        summary          => $self->type('string', $bug->short_desc),
        target_milestone => $self->type('string', $bug->target_milestone),
        url              => $self->type('string', $bug->bug_file_loc),
        version          => $self->type('string', $bug->version),
        whiteboard       => $self->type('string', $bug->status_whiteboard),
    );


    # First we handle any fields that require extra SQL calls.
    # We don't do the SQL calls at all if the filter would just
    # eliminate them anyway.
    if (filter_wants $params, 'assigned_to') {
        $item{'assigned_to'} = $self->type('string', $bug->assigned_to->login);
    }
    if (filter_wants $params, 'blocks') {
        my @blocks = map { $self->type('int', $_) } @{ $bug->blocked };
        $item{'blocks'} = \@blocks;
    }
    if (filter_wants $params, 'cc') {
        my @cc = map { $self->type('string', $_) } @{ $bug->cc || [] };
        $item{'cc'} = \@cc;
    }
    if (filter_wants $params, 'creator') {
        $item{'creator'} = $self->type('string', $bug->reporter->login);
    }
    if (filter_wants $params, 'depends_on') {
        my @depends_on = map { $self->type('int', $_) } @{ $bug->dependson };
        $item{'depends_on'} = \@depends_on;
    }
    if (filter_wants $params, 'dupe_of') {
        $item{'dupe_of'} = $self->type('int', $bug->dup_id);
    }
    if (filter_wants $params, 'groups') {
        my @groups = map { $self->type('string', $_->name) }
                     @{ $bug->groups_in };
        $item{'groups'} = \@groups;
    }
    if (filter_wants $params, 'is_open') {
        $item{'is_open'} = $self->type('boolean', $bug->status->is_open);
    }
    if (filter_wants $params, 'keywords') {
        my @keywords = map { $self->type('string', $_->name) }
                       @{ $bug->keyword_objects };
        $item{'keywords'} = \@keywords;
    }
    if (filter_wants $params, 'qa_contact') {
        my $qa_login = $bug->qa_contact ? $bug->qa_contact->login : '';
        $item{'qa_contact'} = $self->type('string', $qa_login);
    }
    if (filter_wants $params, 'see_also') {
854 855
        my @see_also = map { $self->type('string', $_->name) }
                       @{ $bug->see_also };
856 857
        $item{'see_also'} = \@see_also;
    }
858 859 860
    if (filter_wants $params, 'flags') {
        $item{'flags'} = [ map { $self->_flag_to_hash($_) } @{$bug->flags} ];
    }
861

862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
    # And now custom fields
    my @custom_fields = Bugzilla->active_custom_fields;
    foreach my $field (@custom_fields) {
        my $name = $field->name;
        next if !filter_wants $params, $name;
        if ($field->type == FIELD_TYPE_BUG_ID) {
            $item{$name} = $self->type('int', $bug->$name);
        }
        elsif ($field->type == FIELD_TYPE_DATETIME) {
            $item{$name} = $self->type('dateTime', $bug->$name);
        }
        elsif ($field->type == FIELD_TYPE_MULTI_SELECT) {
            my @values = map { $self->type('string', $_) } @{ $bug->$name };
            $item{$name} = \@values;
        }
        else {
            $item{$name} = $self->type('string', $bug->$name);
        }
880 881
    }

882 883 884 885
    # Timetracking fields are only sent if the user can see them.
    if (Bugzilla->user->is_timetracker) {
        $item{'estimated_time'} = $self->type('double', $bug->estimated_time);
        $item{'remaining_time'} = $self->type('double', $bug->remaining_time);
886 887 888
        # No need to format $bug->deadline specially, because Bugzilla::Bug
        # already does it for us.
        $item{'deadline'} = $self->type('string', $bug->deadline);
889
        $item{'actual_time'} = $self->type('double', $bug->actual_time);
890
    }
891

892 893 894 895 896
    if (Bugzilla->user->id) {
        my $token = issue_hash_token([$bug->id, $bug->delta_ts]);
        $item{'update_token'} = $self->type('string', $token);
    }

897 898 899 900 901 902
    # The "accessible" bits go here because they have long names and it
    # makes the code look nicer to separate them out.
    $item{'is_cc_accessible'} = $self->type('boolean', 
                                            $bug->cclist_accessible);
    $item{'is_creator_accessible'} = $self->type('boolean',
                                                 $bug->reporter_accessible);
903

904
    return filter $params, \%item;
905 906
}

907 908 909
sub _attachment_to_hash {
    my ($self, $attach, $filters) = @_;

910
    my $item = filter $filters, {
911 912 913
        creation_time    => $self->type('dateTime', $attach->attached),
        last_change_time => $self->type('dateTime', $attach->modification_time),
        id               => $self->type('int', $attach->id),
914
        bug_id           => $self->type('int', $attach->bug_id),
915
        file_name        => $self->type('string', $attach->filename),
916
        summary          => $self->type('string', $attach->description),
917 918 919 920 921 922
        description      => $self->type('string', $attach->description),
        content_type     => $self->type('string', $attach->contenttype),
        is_private       => $self->type('int', $attach->isprivate),
        is_obsolete      => $self->type('int', $attach->isobsolete),
        is_patch         => $self->type('int', $attach->ispatch),
    };
923 924 925

    # creator/attacher require an extra lookup, so we only send them if
    # the filter wants them.
926
    foreach my $field (qw(creator attacher)) {
927 928 929 930 931 932 933 934 935
        if (filter_wants $filters, $field) {
            $item->{$field} = $self->type('string', $attach->attacher->login);
        }
    }

    if (filter_wants $filters, 'data') {
        $item->{'data'} = $self->type('base64', $attach->data);
    }

936 937 938 939
    if (filter_wants $filters, 'size') {
        $item->{'size'} = $self->type('int', $attach->datasize);
    }

940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
    if (filter_wants $filters, 'flags') {
        $item->{'flags'} = [ map { $self->_flag_to_hash($_) } @{$attach->flags} ];
    }

    return $item;
}

sub _flag_to_hash {
    my ($self, $flag) = @_;

    my $item = {
        id                => $self->type('int', $flag->id),
        name              => $self->type('string', $flag->name),
        type_id           => $self->type('int', $flag->type_id),
        creation_date     => $self->type('dateTime', $flag->creation_date), 
        modification_date => $self->type('dateTime', $flag->modification_date), 
        status            => $self->type('string', $flag->status)
    };

    foreach my $field (qw(setter requestee)) {
        my $field_id = $field . "_id";
        $item->{$field} = $self->type('string', $flag->$field->login)
            if $flag->$field_id;
    }

965
    return $item;
966 967
}

968
1;
969 970 971 972 973 974 975 976 977 978

__END__

=head1 NAME

Bugzilla::Webservice::Bug - The API for creating, changing, and getting the
details of bugs.

=head1 DESCRIPTION

979 980
This part of the Bugzilla API allows you to file a new bug in Bugzilla,
or get information about bugs that have already been filed.
981 982 983

=head1 METHODS

984 985
See L<Bugzilla::WebService> for a description of how parameters are passed,
and what B<STABLE>, B<UNSTABLE>, and B<EXPERIMENTAL> mean.
986

987
=head1 Utility Functions
988

989
=head2 fields
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027

B<UNSTABLE>

=over

=item B<Description>

Get information about valid bug fields, including the lists of legal values
for each field.

=item B<Params>

You can pass either field ids or field names.

B<Note>: If neither C<ids> nor C<names> is specified, then all 
non-obsolete fields will be returned.

In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

=over

=item C<ids>   (array) - An array of integer field ids.

=item C<names> (array) - An array of strings representing field names.

=back

=item B<Returns>

A hash containing a single element, C<fields>. This is an array of hashes,
containing the following keys:

=over

=item C<id>

Matt Selsky's avatar
Matt Selsky committed
1028
C<int> An integer id uniquely identifying this field in this installation only.
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067

=item C<type>

C<int> The number of the fieldtype. The following values are defined:

=over

=item C<0> Unknown

=item C<1> Free Text

=item C<2> Drop Down

=item C<3> Multiple-Selection Box

=item C<4> Large Text Box

=item C<5> Date/Time

=item C<6> Bug Id

=item C<7> Bug URLs ("See Also")

=back

=item C<is_custom>

C<boolean> True when this is a custom field, false otherwise.

=item C<name>

C<string> The internal name of this field. This is a unique identifier for
this field. If this is not a custom field, then this name will be the same
across all Bugzilla installations.

=item C<display_name>

C<string> The name of the field, as it is shown in the user interface.

1068 1069 1070 1071 1072 1073
=item C<is_mandatory>

C<boolean> True if the field must have a value when filing new bugs.
Also, mandatory fields cannot have their value cleared when updating
bugs.

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
=item C<is_on_bug_entry>

C<boolean> For custom fields, this is true if the field is shown when you
enter a new bug. For standard fields, this is currently always false,
even if the field shows up when entering a bug. (To know whether or not
a standard field is valid on bug entry, see L</create>.)

=item C<visibility_field>

C<string>  The name of a field that controls the visibility of this field
in the user interface. This field only appears in the user interface when
the named field is equal to one of the values in C<visibility_values>.
Can be null.

=item C<visibility_values>

C<array> of C<string>s This field is only shown when C<visibility_field>
matches one of these values. When C<visibility_field> is null,
then this is an empty array.

=item C<value_field>

C<string>  The name of the field that controls whether or not particular
values of the field are shown in the user interface. Can be null.

=item C<values>

This is an array of hashes, representing the legal values for
select-type (drop-down and multiple-selection) fields. This is also
populated for the C<component>, C<version>, and C<target_milestone>
fields, but not for the C<product> field (you must use
L<Product.get_accessible_products|Bugzilla::WebService::Product/get_accessible_products>
for that.

For fields that aren't select-type fields, this will simply be an empty
array.

Each hash has the following keys:

=over 

=item C<name>

C<string> The actual value--this is what you would specify for this
field in L</create>, etc.

1120
=item C<sort_key>
1121 1122 1123 1124

C<int> Values, when displayed in a list, are sorted first by this integer
and then secondly by their name.

1125 1126 1127 1128
=item C<sortkey>

B<DEPRECATED> - Use C<sort_key> instead.

1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
=item C<visibility_values>

If C<value_field> is defined for this field, then this value is only shown
if the C<value_field> is set to one of the values listed in this array.
Note that for per-product fields, C<value_field> is set to C<'product'>
and C<visibility_values> will reflect which product(s) this value appears in.

=item C<is_open>

C<boolean> For C<bug_status> values, determines whether this status
specifies that the bug is "open" (true) or "closed" (false). This item
is only included for the C<bug_status> field.

=item C<can_change_to>

For C<bug_status> values, this is an array of hashes that determines which
statuses you can transition to from this status. (This item is only included
for the C<bug_status> field.)

Each hash contains the following items:

=over

=item C<name>

the name of the new status

=item C<comment_required>

this C<boolean> True if a comment is required when you change a bug into
this status using this transition.

=back

=back

=back

=item B<Errors>

=over

=item 51 (Invalid Field Name or Id)

You specified an invalid field name or id.

=back

=item B<History>

=over

=item Added in Bugzilla B<3.6>.

1183 1184
=item The C<is_mandatory> return value was added in Bugzilla B<4.0>.

1185 1186
=item C<sortkey> was renamed to C<sort_key> in Bugzilla B<4.2>.

1187 1188 1189 1190 1191
=back

=back


1192
=head2 legal_values
1193

1194
B<DEPRECATED> - Use L</fields> instead.
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235

=over

=item B<Description>

Tells you what values are allowed for a particular field.

=item B<Params>

=over

=item C<field> - The name of the field you want information about.
This should be the same as the name you would use in L</create>, below.

=item C<product_id> - If you're picking a product-specific field, you have
to specify the id of the product you want the values for.

=back

=item B<Returns> 

C<values> - An array of strings: the legal values for this field.
The values will be sorted as they normally would be in Bugzilla.

=item B<Errors>

=over

=item 106 (Invalid Product)

You were required to specify a product, and either you didn't, or you
specified an invalid product (or a product that you can't access).

=item 108 (Invalid Field Name)

You specified a field that doesn't exist or isn't a drop-down field.

=back

=back

1236
=head1 Bug Information
1237

1238
=head2 attachments
1239 1240 1241 1242 1243 1244 1245

B<EXPERIMENTAL>

=over

=item B<Description>

1246 1247
It allows you to get data about attachments, given a list of bugs
and/or attachment ids.
1248 1249 1250 1251 1252 1253

B<Note>: Private attachments will only be returned if you are in the 
insidergroup or if you are the submitter of the attachment.

=item B<Params>

1254 1255
B<Note>: At least one of C<ids> or C<attachment_ids> is required.

1256 1257
=over

1258
=item C<ids>
1259

1260
See the description of the C<ids> parameter in the L</get> method.
1261

1262 1263 1264 1265
=item C<attachment_ids>

C<array> An array of integer attachment ids.

1266 1267
=back

1268 1269 1270
Also accepts the L<include_fields|Bugzilla::WebService/include_fields>,
and L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

1271 1272
=item B<Returns>

1273 1274 1275 1276 1277
A hash containing two elements: C<bugs> and C<attachments>. The return
value looks like this:

 {
     bugs => {
1278 1279 1280 1281 1282 1283 1284 1285
         1345 => [
             { (attachment) },
             { (attachment) }
         ],
         9874 => [
             { (attachment) },
             { (attachment) }
         ],
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
     },

     attachments => {
         234 => { (attachment) },
         123 => { (attachment) },
     }
 }

The attachments of any bugs that you specified in the C<ids> argument in
input are returned in C<bugs> on output. C<bugs> is a hash that has integer
1296 1297
bug IDs for keys and the values are arrayrefs that contain hashes as attachments.
(Fields for attachments are described below.)
1298 1299 1300 1301 1302 1303 1304

For any attachments that you specified directly in C<attachment_ids>, they
are returned in C<attachments> on output. This is a hash where the attachment
ids point directly to hashes describing the individual attachment.

The fields for each attachment (where it says C<(attachment)> in the
diagram above) are:
1305 1306 1307

=over

1308 1309 1310 1311
=item C<data>

C<base64> The raw data of the attachment, encoded as Base64.

1312 1313 1314 1315
=item C<size>

C<int> The length (in bytes) of the attachment.

1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
=item C<creation_time>

C<dateTime> The time the attachment was created.

=item C<last_change_time>

C<dateTime> The last time the attachment was modified.

=item C<id>

C<int> The numeric id of the attachment.

=item C<bug_id>

C<int> The numeric id of the bug that the attachment is attached to.

=item C<file_name>

C<string> The file name of the attachment.

1336 1337 1338
=item C<summary>

C<string> A short string describing the attachment.
1339

1340 1341 1342
Also returned as C<description>, for backwards-compatibility with older
Bugzillas. (However, this backwards-compatibility will go away in Bugzilla
5.0.)
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360

=item C<content_type>

C<string> The MIME type of the attachment.

=item C<is_private>

C<boolean> True if the attachment is private (only visible to a certain
group called the "insidergroup"), False otherwise.

=item C<is_obsolete>

C<boolean> True if the attachment is obsolete, False otherwise.

=item C<is_patch>

C<boolean> True if the attachment is a patch, False otherwise.

1361
=item C<creator>
1362 1363 1364

C<string> The login name of the user that created the attachment.

1365 1366 1367 1368
Also returned as C<attacher>, for backwards-compatibility with older
Bugzillas. (However, this backwards-compatibility will go away in Bugzilla
5.0.)

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
=item C<flags>

An array of hashes containing the information about flags currently set
for each attachment. Each flag hash contains the following items:

=over

=item C<id> 

C<int> The id of the flag.

=item C<name>

C<string> The name of the flag.

=item C<type_id>

C<int> The type id of the flag.

=item C<creation_date>

C<dateTime> The timestamp when this flag was originally created.

=item C<modification_date>

C<dateTime> The timestamp when the flag was last modified.

=item C<status>

C<string> The current status of the flag.

=item C<setter>

C<string> The login name of the user who created or last modified the flag.

=item C<requestee>

C<string> The login name of the user this flag has been requested to be granted or denied.
Note, this field is only returned if a requestee is set.

=back

1411 1412 1413 1414
=back

=item B<Errors>

1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
This method can throw all the same errors as L</get>. In addition,
it can also throw the following error:

=over

=item 304 (Auth Failure, Attachment is Private)

You specified the id of a private attachment in the C<attachment_ids>
argument, and you are not in the "insider group" that can see
private attachments.

=back
1427 1428 1429 1430 1431 1432 1433

=item B<History>

=over

=item Added in Bugzilla B<3.6>.

1434 1435 1436
=item In Bugzilla B<4.0>, the C<attacher> return value was renamed to
C<creator>.

1437 1438 1439
=item In Bugzilla B<4.0>, the C<description> return value was renamed to
C<summary>.

1440 1441
=item The C<data> return value was added in Bugzilla B<4.0>.

1442 1443 1444
=item In Bugzilla B<4.2>, the C<is_url> return value was removed
(this attribute no longer exists for attachments).

1445
=item The C<size> return value was added in Bugzilla B<4.4>.
1446

1447 1448
=item The C<flags> array was added in Bugzilla B<4.4>.

1449 1450 1451 1452 1453
=back

=back


1454
=head2 comments
1455

1456
B<STABLE>
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466

=over

=item B<Description>

This allows you to get data about comments, given a list of bugs 
and/or comment ids.

=item B<Params>

1467
B<Note>: At least one of C<ids> or C<comment_ids> is required.
1468 1469 1470 1471 1472 1473 1474

In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

=over

1475
=item C<ids>
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486

C<array> An array that can contain both bug IDs and bug aliases.
All of the comments (that are visible to you) will be returned for the
specified bugs.

=item C<comment_ids> 

C<array> An array of integer comment_ids. These comments will be
returned individually, separate from any other comments in their
respective bugs.

1487 1488 1489
=item C<new_since>

C<dateTime> If specified, the method will only return comments I<newer>
1490
than this time. This only affects comments returned from the C<ids>
1491 1492 1493
argument. You will always be returned all comments you request in the
C<comment_ids> argument, even if they are older than this date.

1494 1495 1496 1497 1498 1499 1500 1501 1502 1503
=back

=item B<Returns>

Two items are returned:

=over

=item C<bugs>

1504
This is used for bugs specified in C<ids>. This is a hash,
1505 1506 1507 1508 1509
where the keys are the numeric ids of the bugs, and the value is
a hash with a single key, C<comments>, which is an array of comments.
(The format of comments is described below.)

Note that any individual bug will only be returned once, so if you
1510
specify an id multiple times in C<ids>, it will still only be
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533
returned once.

=item C<comments>

Each individual comment requested in C<comment_ids> is returned here,
in a hash where the numeric comment id is the key, and the value
is the comment. (The format of comments is described below.) 

=back

A "comment" as described above is a hash that contains the following
keys:

=over

=item id

C<int> The globally unique ID for the comment.

=item bug_id

C<int> The ID of the bug that this comment is on.

1534 1535 1536 1537 1538
=item attachment_id

C<int> If the comment was made on an attachment, this will be the
ID of that attachment. Otherwise it will be null.

1539 1540 1541 1542 1543
=item count

C<int> The number of the comment local to the bug. The Description is 0,
comments start with 1.

1544 1545 1546 1547
=item text

C<string> The actual text of the comment.

1548
=item creator
1549 1550 1551

C<string> The login name of the comment's author.

1552 1553 1554 1555
Also returned as C<author>, for backwards-compatibility with older
Bugzillas. (However, this backwards-compatibility will go away in Bugzilla
5.0.)

1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
=item time

C<dateTime> The time (in Bugzilla's timezone) that the comment was added.

=item is_private

C<boolean> True if this comment is private (only visible to a certain
group called the "insidergroup"), False otherwise.

=back

=item B<Errors>

This method can throw all the same errors as L</get>. In addition,
it can also throw the following errors:

=over

=item 110 (Comment Is Private)

You specified the id of a private comment in the C<comment_ids>
argument, and you are not in the "insider group" that can see
private comments.

=item 111 (Invalid Comment ID)

You specified an id in the C<comment_ids> argument that is invalid--either
you specified something that wasn't a number, or there is no comment with
that id.

=back

1588 1589 1590 1591 1592 1593 1594 1595
=item B<History>

=over

=item Added in Bugzilla B<3.4>.

=item C<attachment_id> was added to the return value in Bugzilla B<3.6>.

1596 1597 1598
=item In Bugzilla B<4.0>, the C<author> return value was renamed to
C<creator>.

1599
=item C<count> was added to the return value in Bugzilla B<4.4>.
1600

1601 1602
=back

1603 1604 1605
=back


1606
=head2 get
1607

1608
B<STABLE>
1609 1610 1611 1612 1613 1614 1615

=over

=item B<Description>

Gets information about particular bugs in the database.

1616 1617
Note: Can also be called as "get_bugs" for compatibilty with Bugzilla 3.0 API.

1618 1619
=item B<Params>

1620 1621 1622 1623
In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.

1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
=over

=item C<ids>

An array of numbers and strings.

If an element in the array is entirely numeric, it represents a bug_id
from the Bugzilla database to fetch. If it contains any non-numeric 
characters, it is considered to be a bug alias instead, and the bug with 
that alias will be loaded. 

1635
=item C<permissive> B<EXPERIMENTAL>
1636 1637 1638 1639 1640 1641 1642

C<boolean> Normally, if you request any inaccessible or invalid bug ids,
Bug.get will throw an error. If this parameter is True, instead of throwing an
error we return an array of hashes with a C<id>, C<faultString> and C<faultCode> 
for each bug that fails, and return normal information for the other bugs that 
were accessible.

1643 1644 1645 1646
=back

=item B<Returns>

1647 1648 1649 1650 1651 1652 1653 1654
Two items are returned:

=over

=item C<bugs>

An array of hashes that contains information about the bugs with 
the valid ids. Each hash contains the following items:
1655 1656 1657

=over

1658 1659 1660 1661 1662 1663 1664
=item C<actual_time>

C<double> The total number of hours that this bug has taken (so far).

If you are not in the time-tracking group, this field will not be included
in the return value.

1665
=item C<alias>
1666

1667
C<string> The unique alias of this bug.
1668

1669
=item C<assigned_to>
1670

1671 1672
C<string> The login name of the user to whom the bug is assigned.

1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
=item C<blocks>

C<array> of C<int>s. The ids of bugs that are "blocked" by this bug.

=item C<cc>

C<array> of C<string>s. The login names of users on the CC list of this
bug.

=item C<classification>

C<string> The name of the current classification the bug is in.

=item C<component>
1687 1688

C<string> The name of the current component of this bug.
1689

1690
=item C<creation_time>
1691 1692 1693

C<dateTime> When the bug was created.

1694 1695 1696 1697 1698 1699
=item C<creator>

C<string> The login name of the person who filed this bug (the reporter).

=item C<deadline>

1700 1701
C<string> The day that this bug is due to be completed, in the format
C<YYYY-MM-DD>.
1702 1703 1704 1705 1706 1707 1708 1709 1710

If you are not in the time-tracking group, this field will not be included
in the return value.

=item C<depends_on>

C<array> of C<int>s. The ids of bugs that this bug "depends on".

=item C<dupe_of>
1711

1712
C<int> The bug ID of the bug that this bug is a duplicate of. If this bug 
1713
isn't a duplicate of any bug, this will be null.
1714

1715
=item C<estimated_time>
1716

1717 1718 1719 1720 1721 1722
C<double> The number of hours that it was estimated that this bug would
take.

If you are not in the time-tracking group, this field will not be included
in the return value.

1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
=item C<flags>

An array of hashes containing the information about flags currently set
for the bug. Each flag hash contains the following items:

=over

=item C<id> 

C<int> The id of the flag.

=item C<name>

C<string> The name of the flag.

=item C<type_id>

C<int> The type id of the flag.

=item C<creation_date>

C<dateTime> The timestamp when this flag was originally created.

=item C<modification_date>

C<dateTime> The timestamp when the flag was last modified.

=item C<status>

C<string> The current status of the flag.

=item C<setter>

C<string> The login name of the user who created or last modified the flag.

=item C<requestee>

C<string> The login name of the user this flag has been requested to be granted or denied.
Note, this field is only returned if a requestee is set.

=back

1765
=item C<groups>
1766

1767
C<array> of C<string>s. The names of all the groups that this bug is in.
1768

1769 1770 1771
=item C<id>

C<int> The unique numeric id of this bug.
1772

1773
=item C<is_cc_accessible>
1774

1775 1776
C<boolean> If true, this bug can be accessed by members of the CC list,
even if they are not in the groups the bug is restricted to.
1777

1778
=item C<is_confirmed>
1779

1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
C<boolean> True if the bug has been confirmed. Usually this means that
the bug has at some point been moved out of the C<UNCONFIRMED> status
and into another open status.

=item C<is_open>

C<boolean> True if this bug is open, false if it is closed.

=item C<is_creator_accessible>

C<boolean> If true, this bug can be accessed by the creator (reporter)
of the bug, even if he or she is not a member of the groups the bug
is restricted to.

=item C<keywords>

C<array> of C<string>s. Each keyword that is on this bug.

=item C<last_change_time>
1799 1800 1801

C<dateTime> When the bug was last changed.

1802 1803 1804 1805 1806 1807 1808 1809 1810
=item C<op_sys>

C<string> The name of the operating system that the bug was filed against.

=item C<platform>

C<string> The name of the platform (hardware) that the bug was filed against.

=item C<priority>
1811 1812 1813

C<string> The priority of the bug.

1814
=item C<product>
1815 1816 1817

C<string> The name of the product this bug is in.

1818
=item C<qa_contact>
1819

1820
C<string> The login name of the current QA Contact on the bug.
1821

1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
=item C<remaining_time>

C<double> The number of hours of work remaining until work on this bug
is complete.

If you are not in the time-tracking group, this field will not be included
in the return value.

=item C<resolution>

C<string> The current resolution of the bug, or an empty string if the bug
is open.

=item C<see_also>

B<UNSTABLE>

C<array> of C<string>s. The URLs in the See Also field on the bug.

=item C<severity>
1842 1843 1844

C<string> The current severity of the bug.

1845
=item C<status>
1846 1847 1848

C<string> The current status of the bug.

1849
=item C<summary>
1850 1851 1852

C<string> The summary of this bug.

1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
=item C<target_milestone>

C<string> The milestone that this bug is supposed to be fixed by, or for
closed bugs, the milestone that it was fixed for.

=item C<update_token>

C<string> The token that you would have to pass to the F<process_bug.cgi>
page in order to update this bug. This changes every time the bug is
updated.

This field is not returned to logged-out users.

=item C<url>

B<UNSTABLE>

C<string> A URL that demonstrates the problem described in
the bug, or is somehow related to the bug report.

=item C<version>

C<string> The version the bug was reported against.

=item C<whiteboard>

C<string> The value of the "status whiteboard" field on the bug.

=item I<custom fields>

Every custom field in this installation will also be included in the
return value. Most fields are returned as C<string>s. However, some
field types have different return values:

=over

=item Bug ID Fields - C<int>

=item Multiple-Selection Fields - C<array> of C<string>s.

=item Date/Time Fields - C<dateTime>

=back 

1897 1898
=back

1899
=item C<faults> B<EXPERIMENTAL>
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925

An array of hashes that contains invalid bug ids with error messages
returned for them. Each hash contains the following items:

=over

=item id

C<int> The numeric bug_id of this bug.

=item faultString 

c<string> This will only be returned for invalid bugs if the C<permissive>
argument was set when calling Bug.get, and it is an error indicating that 
the bug id was invalid.

=item faultCode

c<int> This will only be returned for invalid bugs if the C<permissive>
argument was set when calling Bug.get, and it is the error code for the 
invalid bug error.

=back

=back

1926 1927 1928 1929 1930 1931
=item B<Errors>

=over

=item 100 (Invalid Bug Alias)

1932
If you specified an alias and there is no bug with that alias.
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943

=item 101 (Invalid Bug ID)

The bug_id you specified doesn't exist in the database.

=item 102 (Access Denied)

You do not have access to the bug_id you specified.

=back

1944 1945 1946 1947
=item B<History>

=over

1948 1949 1950
=item C<permissive> argument added to this method's params in Bugzilla B<3.4>. 

=item The following properties were added to this method's return values
1951 1952 1953 1954
in Bugzilla B<3.4>:

=over

1955 1956 1957 1958
=item For C<bugs>

=over

1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
=item assigned_to

=item component 

=item dupe_of

=item is_open

=item priority

=item product

=item resolution

=item severity

=item status

1977 1978 1979 1980 1981 1982
=back 

=item C<faults>

=back 

1983 1984 1985 1986 1987 1988 1989 1990
=item In Bugzilla B<4.0>, the following items were added to the C<bugs>
return value: C<blocks>, C<cc>, C<classification>, C<creator>,
C<deadline>, C<depends_on>, C<estimated_time>, C<is_cc_accessible>, 
C<is_confirmed>, C<is_creator_accessible>, C<groups>, C<keywords>,
C<op_sys>, C<platform>, C<qa_contact>, C<remaining_time>, C<see_also>,
C<target_milestone>, C<update_token>, C<url>, C<version>, C<whiteboard>,
and all custom fields.

1991
=item The C<flags> array was added in Bugzilla B<4.4>.
1992

1993 1994 1995
=item The C<actual_time> item was added to the C<bugs> return value
in Bugzilla B<4.4>.

1996
=back
1997

1998 1999
=back

2000
=head2 history
2001

2002
B<EXPERIMENTAL>
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016

=over

=item B<Description>

Gets the history of changes for particular bugs in the database.

=item B<Params>

=over

=item C<ids>

An array of numbers and strings.
2017

2018 2019 2020 2021 2022 2023 2024 2025 2026
If an element in the array is entirely numeric, it represents a bug_id 
from the Bugzilla database to fetch. If it contains any non-numeric 
characters, it is considered to be a bug alias instead, and the data bug 
with that alias will be loaded. 

=back

=item B<Returns>

2027 2028
A hash containing a single element, C<bugs>. This is an array of hashes,
containing the following keys:
2029 2030 2031

=over

2032 2033 2034 2035
=item id

C<int> The numeric id of the bug.

2036 2037
=item alias

2038
C<string> The alias of this bug. If there is no alias, this will be undef.
2039

2040 2041 2042 2043 2044 2045
=item history

C<array> An array of hashes, each hash having the following keys:

=over

2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
=item when

C<dateTime> The date the bug activity/change happened.

=item who

C<string> The login name of the user who performed the bug change.

=item changes

C<array> An array of hashes which contain all the changes that happened
to the bug at this time (as specified by C<when>). Each hash contains 
the following items:

=over

=item field_name

C<string> The name of the bug field that has changed.

=item removed

C<string> The previous value of the bug field which has been deleted 
by the change.

=item added

C<string> The new value of the bug field which has been added by the change.

=item attachment_id

C<int> The id of the attachment that was changed. This only appears if 
the change was to an attachment, otherwise C<attachment_id> will not be
present in this hash.

=back

=back

2085 2086
=back

2087 2088 2089 2090
=item B<Errors>

The same as L</get>.

2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
=item B<History>

=over

=item Added in Bugzilla B<3.4>.

=back

=back

2101

2102
=head2 search
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113

B<UNSTABLE>

=over

=item B<Description>

Allows you to search for bugs based on particular criteria.

=item B<Params>

2114 2115 2116 2117 2118
Unless otherwise specified in the description of a parameter, bugs are
returned if they match I<exactly> the criteria you specify in these 
parameters. That is, we don't match against substrings--if a bug is in
the "Widgets" product and you ask for bugs in the "Widg" product, you
won't get anything.
2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139

Criteria are joined in a logical AND. That is, you will be returned
bugs that match I<all> of the criteria, not bugs that match I<any> of
the criteria.

Each parameter can be either the type it says, or an array of the types
it says. If you pass an array, it means "Give me bugs with I<any> of
these values." For example, if you wanted bugs that were in either
the "Foo" or "Bar" products, you'd pass:

 product => ['Foo', 'Bar']

Some Bugzillas may treat your arguments case-sensitively, depending
on what database system they are using. Most commonly, though, Bugzilla is 
not case-sensitive with the arguments passed (because MySQL is the 
most-common database to use with Bugzilla, and MySQL is not case sensitive).

=over

=item C<alias>

2140
C<string> The unique alias for this bug.
2141 2142 2143 2144 2145 2146 2147 2148

=item C<assigned_to>

C<string> The login name of a user that a bug is assigned to.

=item C<component>

C<string> The name of the Component that the bug is in. Note that
timeless's avatar
timeless committed
2149
if there are multiple Components with the same name, and you search
2150 2151 2152 2153 2154
for that name, bugs in I<all> those Components will be returned. If you
don't want this, be sure to also specify the C<product> argument.

=item C<creation_time>

2155 2156
C<dateTime> Searches for bugs that were created at this time or later.
May not be an array.
2157

2158 2159 2160 2161
=item C<creator>

C<string> The login name of the user who created the bug.

2162 2163 2164
You can also pass this argument with the name C<reporter>, for
backwards compatibility with older Bugzillas.

2165 2166 2167 2168 2169 2170
=item C<id>

C<int> The numeric id of the bug.

=item C<last_change_time>

2171 2172
C<dateTime> Searches for bugs that were modified at this time or later.
May not be an array.
2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183

=item C<limit>

C<int> Limit the number of results returned to C<int> records.

=item C<offset>

C<int> Used in conjunction with the C<limit> argument, C<offset> defines 
the starting position for the search. For example, given a search that 
would return 100 bugs, setting C<limit> to 10 and C<offset> to 10 would return 
bugs 11 through 20 from the set of 100.
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216

=item C<op_sys>

C<string> The "Operating System" field of a bug.

=item C<platform>

C<string> The Platform (sometimes called "Hardware") field of a bug.

=item C<priority>

C<string> The Priority field on a bug.

=item C<product>

C<string> The name of the Product that the bug is in.

=item C<resolution>

C<string> The current resolution--only set if a bug is closed. You can
find open bugs by searching for bugs with an empty resolution.

=item C<severity>

C<string> The Severity field on a bug.

=item C<status>

C<string> The current status of a bug (not including its resolution,
if it has one, which is a separate field above).

=item C<summary>

2217 2218 2219 2220 2221 2222 2223 2224
C<string> Searches for substrings in the single-line Summary field on
bugs. If you specify an array, then bugs whose summaries match I<any> of the
passed substrings will be returned.

Note that unlike searching in the Bugzilla UI, substrings are not split
on spaces. So searching for C<foo bar> will match "This is a foo bar"
but not "This foo is a bar". C<['foo', 'bar']>, would, however, match
the second item.
2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250

=item C<target_milestone>

C<string> The Target Milestone field of a bug. Note that even if this
Bugzilla does not have the Target Milestone field enabled, you can
still search for bugs by Target Milestone. However, it is likely that
in that case, most bugs will not have a Target Milestone set (it
defaults to "---" when the field isn't enabled).

=item C<qa_contact>

C<string> The login name of the bug's QA Contact. Note that even if
this Bugzilla does not have the QA Contact field enabled, you can
still search for bugs by QA Contact (though it is likely that no bug
will have a QA Contact set, if the field is disabled).

=item C<url>

C<string> The "URL" field of a bug.

=item C<version>

C<string> The Version field of a bug.

=item C<whiteboard>

2251 2252 2253
C<string> Search the "Status Whiteboard" field on bugs for a substring.
Works the same as the C<summary> field described above, but searches the
Status Whiteboard field.
2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278

=back

=item B<Returns>

The same as L</get>.

Note that you will only be returned information about bugs that you
can see. Bugs that you can't see will be entirely excluded from the
results. So, if you want to see private bugs, you will have to first 
log in and I<then> call this method.

=item B<Errors>

Currently, this function doesn't throw any special errors (other than
the ones that all webservice functions can throw). If you specify
an invalid value for a particular field, you just won't get any results
for that value.

=item B<History>

=over

=item Added in Bugzilla B<3.4>.

2279
=item Searching by C<votes> was removed in Bugzilla B<4.0>.
2280

2281 2282 2283
=item The C<reporter> input parameter was renamed to C<creator>
in Bugzilla B<4.0>.

2284 2285 2286 2287 2288
=back

=back


2289
=head1 Bug Creation and Modification
2290

2291
=head2 create
2292

2293
B<STABLE>
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364

=over

=item B<Description>

This allows you to create a new bug in Bugzilla. If you specify any
invalid fields, they will be ignored. If you specify any fields you
are not allowed to set, they will just be set to their defaults or ignored.

You cannot currently set all the items here that you can set on enter_bug.cgi.

The WebService interface may allow you to set things other than those listed
here, but realize that anything undocumented is B<UNSTABLE> and will very
likely change in the future.

=item B<Params>

Some params must be set, or an error will be thrown. These params are
marked B<Required>. 

Some parameters can have defaults set in Bugzilla, by the administrator.
If these parameters have defaults set, you can omit them. These parameters
are marked B<Defaulted>.

Clients that want to be able to interact uniformly with multiple
Bugzillas should always set both the params marked B<Required> and those 
marked B<Defaulted>, because some Bugzillas may not have defaults set
for B<Defaulted> parameters, and then this method will throw an error
if you don't specify them.

The descriptions of the parameters below are what they mean when Bugzilla is
being used to track software bugs. They may have other meanings in some
installations.

=over

=item C<product> (string) B<Required> - The name of the product the bug
is being filed against.

=item C<component> (string) B<Required> - The name of a component in the
product above.

=item C<summary> (string) B<Required> - A brief description of the bug being
filed.

=item C<version> (string) B<Required> - A version of the product above;
the version the bug was found in.

=item C<description> (string) B<Defaulted> - The initial description for 
this bug. Some Bugzilla installations require this to not be blank.

=item C<op_sys> (string) B<Defaulted> - The operating system the bug was
discovered on.

=item C<platform> (string) B<Defaulted> - What type of hardware the bug was
experienced on.

=item C<priority> (string) B<Defaulted> - What order the bug will be fixed
in by the developer, compared to the developer's other bugs.

=item C<severity> (string) B<Defaulted> - How severe the bug is.

=item C<alias> (string) - A brief alias for the bug that can be used 
instead of a bug number when accessing this bug. Must be unique in
all of this Bugzilla.

=item C<assigned_to> (username) - A user to assign this bug to, if you
don't want it to be assigned to the component owner.

=item C<cc> (array) - An array of usernames to CC on this bug.

2365 2366 2367
=item C<comment_is_private> (boolean) - If set to true, the description
is private, otherwise it is assumed to be public.

2368 2369 2370
=item C<groups> (array) - An array of group names to put this
bug into. You can see valid group names on the Permissions
tab of the Preferences screen, or, if you are an administrator,
2371 2372
in the Groups control panel.
If you don't specify this argument, then the bug will be added into
2373 2374 2375
all the groups that are set as being "Default" for this product. (If
you want to avoid that, you should specify C<groups> as an empty array.)

2376 2377 2378 2379 2380 2381 2382
=item C<qa_contact> (username) - If this installation has QA Contacts
enabled, you can set the QA Contact here if you don't want to use
the component's default QA Contact.

=item C<status> (string) - The status that this bug should start out as.
Note that only certain statuses can be set on bug creation.

2383 2384 2385 2386 2387
=item C<resolution> (string) - If you are filing a closed bug, then
you will have to specify a resolution. You cannot currently specify
a resolution of C<DUPLICATE> for new bugs, though. That must be done
with L</update>.

2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404
=item C<target_milestone> (string) - A valid target milestone for this
product.

=back

In addition to the above parameters, if your installation has any custom
fields, you can set them just by passing in the name of the field and
its value as a string.

=item B<Returns>

A hash with one element, C<id>. This is the id of the newly-filed bug.

=item B<Errors>

=over

2405 2406
=item 51 (Invalid Object)

2407 2408
You specified a field value that is invalid. The error message will have
more details.
2409

2410 2411 2412 2413 2414 2415 2416
=item 103 (Invalid Alias)

The alias you specified is invalid for some reason. See the error message
for more details.

=item 104 (Invalid Field)

2417 2418
One of the drop-down fields has an invalid value, or a value entered in a
text field is too long. The error message will have more detail.
2419 2420 2421

=item 105 (Invalid Component)

2422
You didn't specify a component.
2423 2424 2425 2426 2427 2428 2429 2430 2431 2432

=item 106 (Invalid Product)

Either you didn't specify a product, this product doesn't exist, or
you don't have permission to enter bugs in this product.

=item 107 (Invalid Summary)

You didn't specify a summary for the bug.

2433 2434 2435 2436 2437
=item 116 (Dependency Loop)

You specified values in the C<blocks> or C<depends_on> fields
that would cause a circular dependency between bugs.

2438 2439 2440 2441 2442
=item 120 (Group Restriction Denied)

You tried to restrict the bug to a group which does not exist, or which
you cannot use with this product.

2443 2444 2445 2446 2447 2448 2449
=item 504 (Invalid User)

Either the QA Contact, Assignee, or CC lists have some invalid user
in them. The error message will have more details.

=back

2450 2451 2452 2453 2454 2455 2456
=item B<History>

=over

=item Before B<3.0.4>, parameters marked as B<Defaulted> were actually
B<Required>, due to a bug in Bugzilla.

2457 2458
=item The C<groups> argument was added in Bugzilla B<4.0>. Before
Bugzilla 4.0, bugs were only added into Mandatory groups by this
2459 2460 2461
method. Since Bugzilla B<4.0.2>, passing an illegal group name will
throw an error. In Bugzilla 4.0 and 4.0.1, illegal group names were
silently ignored.
2462

2463 2464 2465 2466
=item The C<comment_is_private> argument was added in Bugzilla B<4.0>.
Before Bugzilla 4.0, you had to use the undocumented C<commentprivacy>
argument.

2467 2468 2469
=item Error 116 was added in Bugzilla B<4.0>. Before that, dependency
loop errors had a generic code of C<32000>.

2470
=item The ability to file new bugs with a C<resolution> was added in
2471
Bugzilla B<4.4>.
2472

2473 2474
=back

2475 2476
=back

2477

2478
=head2 add_attachment
2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524

B<UNSTABLE>

=over

=item B<Description>

This allows you to add an attachment to a bug in Bugzilla.

=item B<Params>

=over

=item C<ids>

B<Required> C<array> An array of ints and/or strings--the ids
or aliases of bugs that you want to add this attachment to.
The same attachment and comment will be added to all
these bugs.

=item C<data>

B<Required> C<base64> The content of the attachment.

=item C<file_name>

B<Required> C<string> The "file name" that will be displayed
in the UI for this attachment.

=item C<summary>

B<Required> C<string> A short string describing the
attachment.

=item C<content_type>

B<Required> C<string> The MIME type of the attachment, like
C<text/plain> or C<image/png>.

=item C<comment>

C<string> A comment to add along with this attachment.

=item C<is_patch>

C<boolean> True if Bugzilla should treat this attachment as a patch.
2525
If you specify this, you do not need to specify a C<content_type>.
2526
The C<content_type> of the attachment will be forced to C<text/plain>.
2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567

Defaults to False if not specified.

=item C<is_private>

C<boolean> True if the attachment should be private (restricted
to the "insidergroup"), False if the attachment should be public.

Defaults to False if not specified.

=back

=item B<Returns>

A single item C<attachments>, which contains the created
attachments in the same format as the C<attachments> return
value from L</attachments>.

=item B<Errors>

This method can throw all the same errors as L</get>, plus:

=over

=item 600 (Attachment Too Large)

You tried to attach a file that was larger than Bugzilla will accept.

=item 601 (Invalid MIME Type)

You specified a C<content_type> argument that was blank, not a valid
MIME type, or not a MIME type that Bugzilla accepts for attachments.

=item 603 (File Name Not Specified)

You did not specify a valid for the C<file_name> argument.

=item 604 (Summary Required)

You did not specify a value for the C<summary> argument.

2568 2569 2570 2571
=item 606 (Empty Data)

You set the "data" field to an empty string.

2572 2573 2574 2575 2576 2577 2578
=back

=item B<History>

=over

=item Added in Bugzilla B<4.0>.
2579

2580
=item The C<is_url> parameter was removed in Bugzilla B<4.2>.
2581 2582 2583 2584 2585 2586

=back

=back


2587
=head2 add_comment
2588

2589
B<STABLE>
2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600

=over

=item B<Description>

This allows you to add a comment to a bug in Bugzilla.

=item B<Params>

=over

2601
=item C<id> (int or string) B<Required> - The id or alias of the bug to append a 
2602 2603 2604
comment to.

=item C<comment> (string) B<Required> - The comment to append to the bug.
2605 2606
If this is empty or all whitespace, an error will be thrown saying that
you did not set the C<comment> parameter.
2607

2608 2609
=item C<is_private> (boolean) - If set to true, the comment is private, 
otherwise it is assumed to be public.
2610 2611 2612 2613 2614 2615 2616 2617

=item C<work_time> (double) - Adds this many hours to the "Hours Worked"
on the bug. If you are not in the time tracking group, this value will
be ignored.


=back

2618 2619 2620 2621
=item B<Returns>

A hash with one element, C<id> whose value is the id of the newly-created comment.

2622 2623 2624 2625
=item B<Errors>

=over

2626 2627 2628 2629 2630
=item 54 (Hours Worked Too Large)

You specified a C<work_time> larger than the maximum allowed value of
C<99999.99>.

2631 2632
=item 100 (Invalid Bug Alias) 

2633
If you specified an alias and there is no bug with that alias.
2634 2635 2636 2637 2638

=item 101 (Invalid Bug ID)

The id you specified doesn't exist in the database.

2639
=item 109 (Bug Edit Denied)
2640 2641 2642

You did not have the necessary rights to edit the bug.

2643 2644 2645 2646
=item 113 (Can't Make Private Comments)

You tried to add a private comment, but don't have the necessary rights.

2647 2648 2649 2650 2651
=item 114 (Comment Too Long)

You tried to add a comment longer than the maximum allowed length
(65,535 characters).

2652 2653
=back

2654 2655 2656 2657 2658 2659
=item B<History>

=over

=item Added in Bugzilla B<3.2>.

2660 2661
=item Modified to return the new comment's id in Bugzilla B<3.4>

2662 2663 2664
=item Modified to throw an error if you try to add a private comment
but can't, in Bugzilla B<3.4>.

2665 2666 2667 2668
=item Before Bugzilla B<3.6>, the C<is_private> argument was called
C<private>, and you can still call it C<private> for backwards-compatibility
purposes if you wish.

2669 2670 2671
=item Before Bugzilla B<3.6>, error 54 and error 114 had a generic error
code of 32000.

2672 2673
=back

2674 2675
=back

2676

2677
=head2 update
2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751

B<UNSTABLE>

=over

=item B<Description>

Allows you to update the fields of a bug. Automatically sends emails
out about the changes.

=item B<Params>

=over

=item C<ids>

Array of C<int>s or C<string>s. The ids or aliases of the bugs that
you want to modify.

=back

B<Note>: All following fields specify the values you want to set on the
bugs you are updating.

=over

=item C<alias>

(string) The alias of the bug. You can only set this if you are modifying 
a single bug. If there is more than one bug specified in C<ids>, passing in
a value for C<alias> will cause an error to be thrown.

=item C<assigned_to>

C<string> The full login name of the user this bug is assigned to.

=item C<blocks>

=item C<depends_on>

C<hash> These specify the bugs that this bug blocks or depends on,
respectively. To set these, you should pass a hash as the value. The hash
may contain the following fields:

=over

=item C<add> An array of C<int>s. Bug ids to add to this field.

=item C<remove> An array of C<int>s. Bug ids to remove from this field.
If the bug ids are not already in the field, they will be ignored.

=item C<set> An array of C<int>s. An exact set of bug ids to set this
field to, overriding the current value. If you specify C<set>, then C<add>
and  C<remove> will be ignored.

=back

=item C<cc>

C<hash> The users on the cc list. To modify this field, pass a hash, which
may have the following fields:

=over

=item C<add> Array of C<string>s. User names to add to the CC list.
They must be full user names, and an error will be thrown if you pass
in an invalid user name.

=item C<remove> Array of C<string>s. User names to remove from the CC
list. They must be full user names, and an error will be thrown if you
pass in an invalid user name.

=back

2752
=item C<is_cc_accessible>
2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790

C<boolean> Whether or not users in the CC list are allowed to access
the bug, even if they aren't in a group that can normally access the bug.

=item C<comment>

C<hash>. A comment on the change. The hash may contain the following fields:

=over

=item C<body> C<string> The actual text of the comment.
B<Note>: For compatibility with the parameters to L</add_comment>,
you can also call this field C<comment>, if you want.

=item C<is_private> C<boolean> Whether the comment is private or not.
If you try to make a comment private and you don't have the permission
to, an error will be thrown.

=back

=item C<comment_is_private>

C<hash> This is how you update the privacy of comments that are already
on a bug. This is a hash, where the keys are the C<int> id of comments (not
their count on a bug, like #1, #2, #3, but their globally-unique id,
as returned by L</comments>) and the value is a C<boolean> which specifies
whether that comment should become private (C<true>) or public (C<false>).

The comment ids must be valid for the bug being updated. Thus, it is not
practical to use this while updating multiple bugs at once, as a single
comment id will never be valid on multiple bugs.

=item C<component>

C<string> The Component the bug is in.

=item C<deadline>

2791 2792
C<string> The Deadline field--a date specifying when the bug must
be completed by, in the format C<YYYY-MM-DD>.
2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880

=item C<dupe_of>

C<int> The bug that this bug is a duplicate of. If you want to mark
a bug as a duplicate, the safest thing to do is to set this value
and I<not> set the C<status> or C<resolution> fields. They will
automatically be set by Bugzilla to the appropriate values for
duplicate bugs.

=item C<estimated_time>

C<double> The total estimate of time required to fix the bug, in hours.
This is the I<total> estimate, not the amount of time remaining to fix it.

=item C<groups>

C<hash> The groups a bug is in. To modify this field, pass a hash, which
may have the following fields:

=over

=item C<add> Array of C<string>s. The names of groups to add. Passing
in an invalid group name or a group that you cannot add to this bug will
cause an error to be thrown.

=item C<remove> Array of C<string>s. The names of groups to remove. Passing
in an invalid group name or a group that you cannot remove from this bug
will cause an error to be thrown.

=back

=item C<keywords>

C<hash> Keywords on the bug. To modify this field, pass a hash, which
may have the following fields:

=over

=item C<add> An array of C<strings>s. The names of keywords to add to
the field on the bug. Passing something that isn't a valid keyword name
will cause an error to be thrown. 

=item C<remove> An array of C<string>s. The names of keywords to remove
from the field on the bug. Passing something that isn't a valid keyword
name will cause an error to be thrown.

=item C<set> An array of C<strings>s. An exact set of keywords to set the
field to, on the bug. Passing something that isn't a valid keyword name
will cause an error to be thrown. Specifying C<set> overrides C<add> and
C<remove>.

=back

=item C<op_sys>

C<string> The Operating System ("OS") field on the bug.

=item C<platform>

C<string> The Platform or "Hardware" field on the bug.

=item C<priority>

C<string> The Priority field on the bug.

=item C<product>

C<string> The name of the product that the bug is in. If you change
this, you will probably also want to change C<target_milestone>,
C<version>, and C<component>, since those have different legal
values in every product. 

If you cannot change the C<target_milestone> field, it will be reset to
the default for the product, when you move a bug to a new product.

You may also wish to add or remove groups, as which groups are
valid on a bug depends on the product. Groups that are not valid
in the new product will be automatically removed, and groups which
are mandatory in the new product will be automaticaly added, but no
other automatic group changes will be done.

Note that users can only move a bug into a product if they would
normally have permission to file new bugs in that product.

=item C<qa_contact>

C<string> The full login name of the bug's QA Contact.

2881
=item C<is_creator_accessible>
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989

C<boolean> Whether or not the bug's reporter is allowed to access
the bug, even if he or she isn't in a group that can normally access
the bug.

=item C<remaining_time>

C<double> How much work time is remaining to fix the bug, in hours.
If you set C<work_time> but don't explicitly set C<remaining_time>,
then the C<work_time> will be deducted from the bug's C<remaining_time>.

=item C<reset_assigned_to>

C<boolean> If true, the C<assigned_to> field will be reset to the
default for the component that the bug is in. (If you have set the
component at the same time as using this, then the component used
will be the new component, not the old one.)

=item C<reset_qa_contact>

C<boolean> If true, the C<qa_contact> field will be reset  to the
default for the component that the bug is in. (If you have set the
component at the same time as using this, then the component used
will be the new component, not the old one.)

=item C<resolution>

C<string> The current resolution. May only be set if you are closing
a bug or if you are modifying an already-closed bug. Attempting to set
the resolution to I<any> value (even an empty or null string) on an
open bug will cause an error to be thrown.

If you change the C<status> field to an open status, the resolution
field will automatically be cleared, so you don't have to clear it
manually.

=item C<see_also>

C<hash> The See Also field on a bug, specifying URLs to bugs in other
bug trackers. To modify this field, pass a hash, which may have the
following fields:

=over

=item C<add> An array of C<strings>s. URLs to add to the field.
Each URL must be a valid URL to a bug-tracker, or an error will
be thrown.

=item C<remove> An array of C<string>s. URLs to remove from the field.
Invalid URLs will be ignored.

=back

=item C<severity>

C<string> The Severity field of a bug.

=item C<status>

C<string> The status you want to change the bug to. Note that if
a bug is changing from open to closed, you should also specify
a C<resolution>.

=item C<summary>

C<string> The Summary field of the bug.

=item C<target_milestone>

C<string> The bug's Target Milestone.

=item C<url>

C<string> The "URL" field of a bug.

=item C<version>

C<string> The bug's Version field.

=item C<whiteboard>

C<string> The Status Whiteboard field of a bug.

=item C<work_time>

C<double> The number of hours worked on this bug as part of this change.
If you set C<work_time> but don't explicitly set C<remaining_time>,
then the C<work_time> will be deducted from the bug's C<remaining_time>.

=back

You can also set the value of any custom field by passing its name as
a parameter, and the value to set the field to. For multiple-selection
fields, the value should be an array of strings.

=item B<Returns>

A C<hash> with a single field, "bugs". This points to an array of hashes
with the following fields:

=over

=item C<id>

C<int> The id of the bug that was updated.

=item C<alias>

2990
C<string> The alias of the bug that was updated, if this bug has an alias.
2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039

=item C<last_change_time>

C<dateTime> The exact time that this update was done at, for this bug.
If no update was done (that is, no fields had their values changed and
no comment was added) then this will instead be the last time the bug
was updated.

=item C<changes>

C<hash> The changes that were actually done on this bug. The keys are
the names of the fields that were changed, and the values are a hash
with two keys:

=over

=item C<added> (C<string>) The values that were added to this field,
possibly a comma-and-space-separated list if multiple values were added.

=item C<removed> (C<string>) The values that were removed from this
field, possibly a comma-and-space-separated list if multiple values were
removed.

=back

=back

Here's an example of what a return value might look like:

 { 
   bugs => [
     {
       id    => 123,
       alias => 'foo',
       last_change_time => '2010-01-01T12:34:56',
       changes => {
         status => {
           removed => 'NEW',
           added   => 'ASSIGNED'
         },
         keywords => {
           removed => 'bar',
           added   => 'qux, quo, qui', 
         }
       },
     }
   ]
 }

3040 3041 3042 3043 3044
Currently, some fields are not tracked in changes: C<comment>,
C<comment_is_private>, and C<work_time>. This means that they will not
show up in the return value even if they were successfully updated.
This may change in a future version of Bugzilla.

3045 3046
=item B<Errors>

3047 3048
This function can throw all of the errors that L</get>, L</create>,
and L</add_comment> can throw, plus:
3049 3050 3051

=over

3052
=item 50 (Empty Field)
3053

3054 3055
You tried to set some field to be empty, but that field cannot be empty.
The error message will have more details.
3056

3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083
=item 52 (Input Not A Number)

You tried to set a numeric field to a value that wasn't numeric.

=item 54 (Number Too Large)

You tried to set a numeric field to a value larger than that field can
accept.

=item 55 (Number Too Small)

You tried to set a negative value in a numeric field that does not accept
negative values.

=item 56 (Bad Date/Time)

You specified an invalid date or time in a date/time field (such as
the C<deadline> field or a custom date/time field).

=item 112 (See Also Invalid)

You attempted to add an invalid value to the C<see_also> field.

=item 115 (Permission Denied)

You don't have permission to change a particular field to a particular value.
The error message will have more detail.
3084

3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124
=item 116 (Dependency Loop)

You specified a value in the C<blocks> or C<depends_on> fields that causes
a dependency loop.

=item 117 (Invalid Comment ID)

You specified a comment id in C<comment_is_private> that isn't on this bug.

=item 118 (Duplicate Loop)

You specified a value for C<dupe_of> that causes an infinite loop of
duplicates.

=item 119 (dupe_of Required)

You changed the resolution to C<DUPLICATE> but did not specify a value
for the C<dupe_of> field.

=item 120 (Group Add/Remove Denied)

You tried to add or remove a group that you don't have permission to modify
for this bug, or you tried to add a group that isn't valid in this product.

=item 121 (Resolution Required)

You tried to set the C<status> field to a closed status, but you didn't
specify a resolution.

=item 122 (Resolution On Open Status)

This bug has an open status, but you specified a value for the C<resolution>
field.

=item 123 (Invalid Status Transition)

You tried to change from one status to another, but the status workflow
rules don't allow that change.

=back
3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136

=item B<History>

=over

=item Added in Bugzilla B<4.0>.

=back

=back


3137
=head2 update_see_also
3138

3139
B<EXPERIMENTAL>
3140 3141 3142 3143 3144 3145

=over

=item B<Description>

Adds or removes URLs for the "See Also" field on bugs. These URLs must
3146
point to some valid bug in some Bugzilla installation or in Launchpad.
3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159

=item B<Params>

=over

=item C<ids>

Array of C<int>s or C<string>s. The ids or aliases of bugs that you want
to modify.

=item C<add>

Array of C<string>s. URLs to Bugzilla bugs. These URLs will be added to
3160 3161 3162 3163 3164
the See Also field. They must be valid URLs to C<show_bug.cgi> in a
Bugzilla installation or to a bug filed at launchpad.net.

If the URLs don't start with C<http://> or C<https://>, it will be assumed
that C<http://> should be added to the beginning of the string.
3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197

It is safe to specify URLs that are already in the "See Also" field on
a bug--they will just be silently ignored.

=item C<remove>

Array of C<string>s. These URLs will be removed from the See Also field.
You must specify the full URL that you want removed. However, matching
is done case-insensitively, so you don't have to specify the URL in
exact case, if you don't want to.

If you specify a URL that is not in the See Also field of a particular bug,
it will just be silently ignored. Invaild URLs are currently silently ignored,
though this may change in some future version of Bugzilla.

=back

NOTE: If you specify the same URL in both C<add> and C<remove>, it will
be I<added>. (That is, C<add> overrides C<remove>.)

=item B<Returns>

C<changes>, a hash where the keys are numeric bug ids and the contents
are a hash with one key, C<see_also>. C<see_also> points to a hash, which
contains two keys, C<added> and C<removed>. These are arrays of strings,
representing the actual changes that were made to the bug.

Here's a diagram of what the return value looks like for updating
bug ids 1 and 2:

 {
   changes => {
       1 => {
3198 3199 3200 3201
           see_also => {
               added   => (an array of bug URLs),
               removed => (an array of bug URLs),
           }
3202 3203
       },
       2 => {
3204 3205 3206 3207
           see_also => {
               added   => (an array of bug URLs),
               removed => (an array of bug URLs),
           }
3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221
       }
   }
 }

This return value allows you to tell what this method actually did. It is in
this format to be compatible with the return value of a future C<Bug.update>
method.

=item B<Errors>

This method can throw all of the errors that L</get> throws, plus:

=over

3222
=item 109 (Bug Edit Denied)
3223 3224 3225 3226 3227 3228 3229

You did not have the necessary rights to edit the bug.

=item 112 (Invalid Bug URL)

One of the URLs you provided did not look like a valid bug URL.

3230 3231 3232 3233 3234
=item 115 (See Also Edit Denied)

You did not have the necessary rights to edit the See Also field for
this bug.

3235 3236 3237 3238 3239 3240 3241 3242
=back

=item B<History>

=over

=item Added in Bugzilla B<3.4>.

3243 3244
=item Before Bugzilla B<3.6>, error 115 had a generic error code of 32000.

3245 3246 3247
=back

=back