diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-08-04 18:24:15 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-08-04 18:24:15 +0200 |
commit | f44392e8cdbea85ac308b2472f813ee605ebae4b (patch) | |
tree | 6e7adaf99a0e5a43eb1bf5a0d673d86b60f34f99 /extensions/ComponentWatching/Extension.pm | |
parent | 5be3a7fd0061aa0bc3059e09079741873b9b833f (diff) | |
parent | 4528b21bc922f8b1e0ba8581d230a492aa43c9cf (diff) | |
download | bugzilla-f44392e8cdbea85ac308b2472f813ee605ebae4b.tar.gz bugzilla-f44392e8cdbea85ac308b2472f813ee605ebae4b.tar.xz |
Merge branch 'mojo-poc'
Diffstat (limited to 'extensions/ComponentWatching/Extension.pm')
-rw-r--r-- | extensions/ComponentWatching/Extension.pm | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/extensions/ComponentWatching/Extension.pm b/extensions/ComponentWatching/Extension.pm index ed47e64c3..96eb877a6 100644 --- a/extensions/ComponentWatching/Extension.pm +++ b/extensions/ComponentWatching/Extension.pm @@ -469,15 +469,18 @@ sub bugmail_relationships { # sub _getWatches { - my ($user) = @_; + my ($user, $watch_id) = @_; my $dbh = Bugzilla->dbh; + $watch_id = (defined $watch_id && $watch_id =~ /^(\d+)$/) ? $1 : undef; + my $sth = $dbh->prepare(" SELECT id, product_id, component_id, component_prefix FROM component_watch - WHERE user_id = ? - "); - $sth->execute($user->id); + WHERE user_id = ?" . ($watch_id ? " AND id = ?" : "") + ); + $watch_id ? $sth->execute($user->id, $watch_id) : $sth->execute($user->id); + my @watches; while (my ($id, $productId, $componentId, $prefix) = $sth->fetchrow_array) { my $product = Bugzilla::Product->new({ id => $productId, cache => 1 }); @@ -500,6 +503,10 @@ sub _getWatches { push @watches, \%watch; } + if ($watch_id) { + return $watches[0] || {}; + } + @watches = sort { $a->{'product_name'} cmp $b->{'product_name'} || $a->{'component_name'} cmp $b->{'component_name'} @@ -565,6 +572,8 @@ sub _addProductWatch { VALUES (?, ?) "); $sth->execute($user->id, $product->id); + + return _getWatches($user, $dbh->bz_last_key()); } sub _addComponentWatch { @@ -585,6 +594,8 @@ sub _addComponentWatch { VALUES (?, ?, ?) "); $sth->execute($user->id, $component->product_id, $component->id); + + return _getWatches($user, $dbh->bz_last_key()); } sub _addPrefixWatch { @@ -620,8 +631,9 @@ sub _deleteWatch { my $dbh = Bugzilla->dbh; detaint_natural($id) || ThrowCodeError("component_watch_invalid_id"); - $dbh->do("DELETE FROM component_watch WHERE id=? AND user_id=?", - undef, $id, $user->id); + + return $dbh->do("DELETE FROM component_watch WHERE id=? AND user_id=?", + undef, $id, $user->id); } sub _addDefaultSettings { @@ -717,4 +729,13 @@ sub sanitycheck_repair { } } +# +# webservice +# + +sub webservice { + my ($self, $args) = @_; + $args->{dispatch}->{ComponentWatching} = "Bugzilla::Extension::ComponentWatching::WebService"; +} + __PACKAGE__->NAME; |