]> git.donarmstrong.com Git - debbugs.git/commitdiff
add exists to Debbugs::Bug to see if a bug exists or not
authorDon Armstrong <don@donarmstrong.com>
Sun, 11 Aug 2019 17:06:38 +0000 (10:06 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 11 Aug 2019 17:06:38 +0000 (10:06 -0700)
lib/Debbugs/Bug.pm

index 21a26e39af2c443e34c0b260887d29146f1fc225..bc5ec49f5bbd6e68fb6e49e27c13b58ac1d1d4b1 100644 (file)
@@ -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',