]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1309487 - include longdescs.count in result for /rest/bug
authorDavid Lawrence <dkl@mozilla.com>
Fri, 14 Oct 2016 01:58:37 +0000 (01:58 +0000)
committerDavid Lawrence <dkl@mozilla.com>
Fri, 14 Oct 2016 01:58:49 +0000 (01:58 +0000)
Bugzilla/Bug.pm
Bugzilla/WebService/Bug.pm
docs/en/rst/api/core/v1/bug.rst

index 77d2e126a9a406eba75c1271bfc46b3ec5d7d849..69734e6c04336746b3c06f948e6bab81d57e5510 100644 (file)
@@ -265,6 +265,7 @@ use constant FIELD_MAP => {
     is_cc_accessible => 'cclist_accessible',
     is_creator_accessible => 'reporter_accessible',
     last_change_time => 'delta_ts',
+    comment_count    => 'longdescs.count',
     platform         => 'rep_platform',
     severity         => 'bug_severity',
     status           => 'bug_status',
@@ -3661,6 +3662,17 @@ sub comments {
     return \@comments;
 }
 
+sub comment_count {
+    my ($self) = @_;
+    return $self->{comment_count} if $self->{comment_count};
+    my $dbh = Bugzilla->dbh;
+    return $self->{comment_count} =
+        $dbh->selectrow_array('SELECT COUNT(longdescs.comment_id)
+                               FROM longdescs
+                               WHERE longdescs.bug_id = ?',
+                              undef, $self->id);
+}
+
 # This is needed by xt/search.t.
 sub percentage_complete {
     my $self = shift;
index 20a21147d4efe43eec8a332f255d52474fea78bb..bbab65137c6df734620fd51ff73b68a5a00b5a72 100644 (file)
@@ -1476,6 +1476,10 @@ sub _bug_to_hash {
           = [ map { $self->_user_to_hash($_, $params, undef, 'mentors') } @{ $bug->mentors } ];
     }
 
+    if (filter_wants $params, 'comment_count') {
+        $item{'comment_count'} = $self->type('int', $bug->comment_count);
+    }
+
     return \%item;
 }
 
index 137f832566105969a471e3b9c1f590ddf87f5858..3c7605527ced3473b0f765d9a41458067b9cfd8c 100644 (file)
@@ -115,7 +115,8 @@ name              type   description
            "email": "namachi@netscape.com"
          },
          "cf_free_text": "",
-         "blocks": []
+         "blocks": [],
+         "comment_count": 12
        }
      ]
    }
@@ -185,6 +186,7 @@ is_creator_accessible  boolean   If ``true``, this bug can be accessed by the
                                  member of the groups the bug is restricted to.
 keywords               array     Each keyword that is on this bug.
 last_change_time       datetime  When the bug was last changed.
+comment_count          int       Number of comments associated with the bug.
 op_sys                 string    The name of the operating system that the bug
                                  was filed against.
 platform               string    The name of the platform (hardware) that the bug