From: Don Armstrong Date: Sun, 11 Aug 2019 17:06:38 +0000 (-0700) Subject: add exists to Debbugs::Bug to see if a bug exists or not X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=74ad3256eb0903bdaed5f58b892bbf7c2a5a9373;p=debbugs.git add exists to Debbugs::Bug to see if a bug exists or not --- diff --git a/lib/Debbugs/Bug.pm b/lib/Debbugs/Bug.pm index 21a26e3..bc5ec49 100644 --- a/lib/Debbugs/Bug.pm +++ b/lib/Debbugs/Bug.pm @@ -32,6 +32,7 @@ use List::AllUtils qw(max first min any); use Params::Validate qw(validate_with :types); use Debbugs::Config qw(:config); use Debbugs::Status qw(read_bug); +use Debbugs::Common qw(bug_status); use Debbugs::Bug::Tag; use Debbugs::Bug::Status; use Debbugs::Collection::Package; @@ -57,6 +58,24 @@ sub id { return $_[0]->bug; } +has exists => (is => 'ro', + isa => 'Bool', + builder => '_build_exists', + ); + +sub _build_exists { + my $self = shift; + if ($self->has_schema) { # check database to see if the bug exists + my $count = $self->schema->resultset('Bug')-> + search({id => $self->bug})-> + count(); + return $count; + } else { # check filesystem to see if the bug exists + return defined bug_status($self->bug); + } + return 0; +} + has saved => (is => 'ro', isa => 'Bool', default => 0, writer => '_set_saved',