summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2003-02-17 10:35:00 +0000
committerFrancois Pons <fpons@mandriva.com>2003-02-17 10:35:00 +0000
commit93f81c509c67873a8f3e0e3e92f9bf951a20b5f8 (patch)
treef8e89dd4ebf72e31a7c062a8989f9f30edc47f05
parentf6201b8d82310c87b9ff984a30053627f7f3140c (diff)
downloadurpmi-93f81c509c67873a8f3e0e3e92f9bf951a20b5f8.tar
urpmi-93f81c509c67873a8f3e0e3e92f9bf951a20b5f8.tar.gz
urpmi-93f81c509c67873a8f3e0e3e92f9bf951a20b5f8.tar.bz2
urpmi-93f81c509c67873a8f3e0e3e92f9bf951a20b5f8.tar.xz
urpmi-93f81c509c67873a8f3e0e3e92f9bf951a20b5f8.zip
fixed typo.
-rwxr-xr-xurpmq2
1 files changed, 1 insertions, 1 deletions
diff --git a/urpmq b/urpmq
index c0ea0956..4985ebf4 100755
--- a/urpmq
+++ b/urpmq
@@ -62,7 +62,7 @@ usage:
") . _(" -v - verbose mode.
") . _(" -d - extend query to package dependencies.
") . _(" -u - remove package if a more recent version is already installed.
-") . _(" -c - complete output with package to remove.
+") . _(" -c - complete output with package to be removed.
") . _(" -P - do not search in provides to find package.
") . _(" -R - reverse search to what requires package.
") . _(" -y - impose fuzzy search (same as --fuzzy).
ef='#n190'>190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
# 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/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Component;

use 5.10.1;
use strict;

use parent qw(Bugzilla::Field::ChoiceInterface Bugzilla::Object);

use Bugzilla::Constants;
use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::User;
use Bugzilla::FlagType;
use Bugzilla::Series;

use Scalar::Util qw(blessed);

###############################
####    Initialization     ####
###############################

use constant DB_TABLE => 'components';
# This is mostly for the editfields.cgi case where ->get_all is called.
use constant LIST_ORDER => 'product_id, name';

use constant DB_COLUMNS => qw(
    id
    name
    product_id
    initialowner
    initialqacontact
    description
    isactive
);

use constant UPDATE_COLUMNS => qw(
    name
    initialowner
    initialqacontact
    description
    isactive
);

use constant REQUIRED_FIELD_MAP => {
    product_id => 'product',
};

use constant VALIDATORS => {
    create_series    => \&Bugzilla::Object::check_boolean,
    product          => \&_check_product,
    initialowner     => \&_check_initialowner,
    initialqacontact => \&_check_initialqacontact,
    description      => \&_check_description,
    initial_cc       => \&_check_cc_list,
    name             => \&_check_name,
    isactive         => \&Bugzilla::Object::check_boolean,
};

use constant VALIDATOR_DEPENDENCIES => {
    name => ['product'],
};

###############################

sub new {
    my $class = shift;
    my $param = shift;
    my $dbh = Bugzilla->dbh;

    my $product;
    if (ref $param and !defined $param->{id}) {
        $product = $param->{product};
        my $name = $param->{name};
        if (!defined $product) {
            ThrowCodeError('bad_arg',
                {argument => 'product',
                 function => "${class}::new"});
        }
        if (!defined $name) {
            ThrowCodeError('bad_arg',
                {argument => 'name',
                 function => "${class}::new"});
        }

        my $condition = 'product_id = ? AND name = ?';
        my @values = ($product->id, $name);
        $param = { condition => $condition, values => \@values };
    }

    unshift @_, $param;
    my $component = $class->SUPER::new(@_);
    # Add the product object as attribute only if the component exists.
    $component->{product} = $product if ($component && $product);
    return $component;
}

sub create {
    my $class = shift;
    my $dbh = Bugzilla->dbh;

    $dbh->bz_start_transaction();

    $class->check_required_create_fields(@_);
    my $params = $class->run_create_validators(@_);
    my $cc_list = delete $params->{initial_cc};
    my $create_series = delete $params->{create_series};
    my $product = delete $params->{product};
    $params->{product_id} = $product->id;

    my $component = $class->insert_create_data($params);
    $component->{product} = $product;

    # We still have to fill the component_cc table.
    $component->_update_cc_list($cc_list) if $cc_list;

    # Create series for the new component.
    $component->_create_series() if $create_series;

    $dbh->bz_commit_transaction();
    return $component;
}

sub update {
    my $self = shift;
    my $changes = $self->SUPER::update(@_);

    # Update the component_cc table if necessary.
    if (defined $self->{cc_ids}) {
        my $diff = $self->_update_cc_list($self->{cc_ids});
        $changes->{cc_list} = $diff if defined $diff;
    }
    return $changes;
}

sub remove_from_db {
    my $self = shift;
    my $dbh = Bugzilla->dbh;

    $self->_check_if_controller(); # From ChoiceInterface

    $dbh->bz_start_transaction();

    # Products must have at least one component.
    if (scalar(@{$self->product->components}) == 1) {
        ThrowUserError('component_is_last', { comp => $self });
    }

    if ($self->bug_count) {
        if (Bugzilla->params->{'allowbugdeletion'}) {
            require Bugzilla::Bug;
            foreach my $bug_id (@{$self->bug_ids}) {
                # Note: We allow admins to delete bugs even if they can't
                # see them, as long as they can see the product.
                my $bug = new Bugzilla::Bug($bug_id);
                $bug->remove_from_db();
            }
        } else {
            ThrowUserError('component_has_bugs', {nb => $self->bug_count});
        }
    }
    $self->SUPER::remove_from_db();

    $dbh->bz_commit_transaction();
}

################################
# Validators
################################

sub _check_name {
    my ($invocant, $name, undef, $params) = @_;
    my $product = blessed($invocant) ? $invocant->product : $params->{product};

    $name = trim($name);
    $name || ThrowUserError('component_blank_name');

    if (length($name) > MAX_COMPONENT_SIZE) {
        ThrowUserError('component_name_too_long', {'name' => $name});
    }

    my $component = new Bugzilla::Component({product => $product, name => $name});
    if ($component && (!ref $invocant || $component->id != $invocant->id)) {
        ThrowUserError('component_already_exists', { name    => $component->name,
                                                     product => $product });
    }
    return $name;
}

sub _check_description {
    my ($invocant, $description) = @_;

    $description = trim($description);
    $description || ThrowUserError('component_blank_description');
    return $description;
}

sub _check_initialowner {
    my ($invocant, $owner) = @_;

    $owner || ThrowUserError('component_need_initialowner');
    my $owner_id = Bugzilla::User->check($owner)->id;
    return $owner_id;
}

sub _check_initialqacontact {
    my ($invocant, $qa_contact) = @_;

    my $qa_contact_id;
    if (Bugzilla->params->{'useqacontact'}) {
        $qa_contact_id = Bugzilla::User->check($qa_contact)->id if $qa_contact;
    }
    elsif (ref $invocant) {
        $qa_contact_id = $invocant->{initialqacontact};
    }
    return $qa_contact_id;
}

sub _check_product {
    my ($invocant, $product) = @_;
    $product || ThrowCodeError('param_required', 
                    { function => "$invocant->create", param => 'product' });
    return Bugzilla->user->check_can_admin_product($product->name);
}

sub _check_cc_list {
    my ($invocant, $cc_list) = @_;

    my %cc_ids;
    foreach my $cc (@$cc_list) {
        my $id = login_to_id($cc, THROW_ERROR);
        $cc_ids{$id} = 1;
    }
    return [keys %cc_ids];
}

###############################
####       Methods         ####
###############################

sub _update_cc_list {
    my ($self, $cc_list) = @_;
    my $dbh = Bugzilla->dbh;

    my $old_cc_list =
      $dbh->selectcol_arrayref('SELECT user_id FROM component_cc
                                WHERE component_id = ?', undef, $self->id);

    my ($removed, $added) = diff_arrays($old_cc_list, $cc_list);
    my $diff;
    if (scalar @$removed || scalar @$added) {
        $diff = [join(', ', @$removed), join(', ', @$added)];
    }

    $dbh->do('DELETE FROM component_cc WHERE component_id = ?', undef, $self->id);

    my $sth = $dbh->prepare('INSERT INTO component_cc
                             (user_id, component_id) VALUES (?, ?)');
    $sth->execute($_, $self->id) foreach (@$cc_list);

    return $diff;
}

sub _create_series {
    my $self = shift;

    # Insert default charting queries for this product.
    # If they aren't using charting, this won't do any harm.
    my $prodcomp = "&product="   . url_quote($self->product->name) .
                   "&component=" . url_quote($self->name);

    my $open_query = 'field0-0-0=resolution&type0-0-0=notregexp&value0-0-0=.' .
                     $prodcomp;
    my $nonopen_query = 'field0-0-0=resolution&type0-0-0=regexp&value0-0-0=.' .
                        $prodcomp;

    my @series = ([get_text('series_all_open'), $open_query],
                  [get_text('series_all_closed'), $nonopen_query]);

    foreach my $sdata (@series) {
        my $series = new Bugzilla::Series(undef, $self->product->name,
                                          $self->name, $sdata->[0],
                                          Bugzilla->user->id, 1, $sdata->[1], 1);
        $series->writeToDatabase();
    }
}

sub set_name { $_[0]->set('name', $_[1]); }
sub set_description { $_[0]->set('description', $_[1]); }
sub set_is_active { $_[0]->set('isactive', $_[1]); }
sub set_default_assignee {
    my ($self, $owner) = @_;

    $self->set('initialowner', $owner);
    # Reset the default owner object.
    delete $self->{default_assignee};
}
sub set_default_qa_contact {
    my ($self, $qa_contact) = @_;

    $self->set('initialqacontact', $qa_contact);
    # Reset the default QA contact object.
    delete $self->{default_qa_contact};
}
sub set_cc_list {
    my ($self, $cc_list) = @_;

    $self->{cc_ids} = $self->_check_cc_list($cc_list);
    # Reset the list of CC user objects.
    delete $self->{initial_cc};
}

sub bug_count {
    my $self = shift;
    my $dbh = Bugzilla->dbh;

    if (!defined $self->{'bug_count'}) {
        $self->{'bug_count'} = $dbh->selectrow_array(q{
            SELECT COUNT(*) FROM bugs
            WHERE component_id = ?}, undef, $self->id) || 0;
    }
    return $self->{'bug_count'};
}

sub bug_ids {
    my $self = shift;
    my $dbh = Bugzilla->dbh;

    if (!defined $self->{'bugs_ids'}) {
        $self->{'bugs_ids'} = $dbh->selectcol_arrayref(q{
            SELECT bug_id FROM bugs
            WHERE component_id = ?}, undef, $self->id);
    }
    return $self->{'bugs_ids'};
}

sub default_assignee {
    my $self = shift;

    return $self->{'default_assignee'}
      ||= new Bugzilla::User({ id => $self->{'initialowner'}, cache => 1 });
}

sub default_qa_contact {
    my $self = shift;

    return unless $self->{'initialqacontact'};
    return $self->{'default_qa_contact'}
      ||= new Bugzilla::User({id => $self->{'initialqacontact'}, cache => 1 });
}

sub flag_types {
    my $self = shift;

    if (!defined $self->{'flag_types'}) {
        my $flagtypes = Bugzilla::FlagType::match({ product_id   => $self->product_id,
                                                    component_id => $self->id });

        $self->{'flag_types'} = {};
        $self->{'flag_types'}->{'bug'} =
          [grep { $_->target_type eq 'bug' } @$flagtypes];
        $self->{'flag_types'}->{'attachment'} =
          [grep { $_->target_type eq 'attachment' } @$flagtypes];
    }
    return $self->{'flag_types'};
}

sub initial_cc {
    my $self = shift;
    my $dbh = Bugzilla->dbh;

    if (!defined $self->{'initial_cc'}) {
        # If set_cc_list() has been called but data are not yet written
        # into the DB, we want the new values defined by it.
        my $cc_ids = $self->{cc_ids}
                     || $dbh->selectcol_arrayref('SELECT user_id FROM component_cc
                                                  WHERE component_id = ?',
                                                  undef, $self->id);

        $self->{'initial_cc'} = Bugzilla::User->new_from_list($cc_ids);
    }
    return $self->{'initial_cc'};
}

sub product {
    my $self = shift;
    if (!defined $self->{'product'}) {