summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-11-13 08:21:34 +0100
committerByron Jones <bjones@mozilla.com>2013-11-13 08:21:34 +0100
commitca8cbc67699faaf38038578ce7aee9439a245aac (patch)
tree96138ea90db116f8230a18ba386dd3c53ac7e248
parent31490aa96a5c9452f0315f6920e9171dae06049b (diff)
downloadbugzilla-ca8cbc67699faaf38038578ce7aee9439a245aac.tar.gz
bugzilla-ca8cbc67699faaf38038578ce7aee9439a245aac.tar.xz
Bug 932346: Simple bug-change push extension
-rw-r--r--Bugzilla/Bug.pm25
-rw-r--r--extensions/ZPushNotify/Config.pm15
-rw-r--r--extensions/ZPushNotify/Extension.pm110
-rw-r--r--extensions/ZPushNotify/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl13
4 files changed, 154 insertions, 9 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 9aa34b090..df2e4b637 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -694,21 +694,20 @@ sub create {
# Set up dependencies (blocked/dependson)
my $sth_deps = $dbh->prepare(
'INSERT INTO dependencies (blocked, dependson) VALUES (?, ?)');
- my $sth_bug_time = $dbh->prepare('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?');
foreach my $depends_on_id (@$depends_on) {
$sth_deps->execute($bug->bug_id, $depends_on_id);
# Log the reverse action on the other bug.
LogActivityEntry($depends_on_id, 'blocked', '', $bug->bug_id,
$bug->{reporter_id}, $timestamp);
- $sth_bug_time->execute($timestamp, $depends_on_id);
+ _update_delta_ts($depends_on_id, $timestamp);
}
foreach my $blocked_id (@$blocked) {
$sth_deps->execute($blocked_id, $bug->bug_id);
# Log the reverse action on the other bug.
LogActivityEntry($blocked_id, 'dependson', '', $bug->bug_id,
$bug->{reporter_id}, $timestamp);
- $sth_bug_time->execute($timestamp, $blocked_id);
+ _update_delta_ts($blocked_id, $timestamp);
}
# Insert the values into the multiselect value tables
@@ -891,8 +890,7 @@ sub update {
LogActivityEntry($removed_id, $other, $self->id, '',
$user->id, $delta_ts);
# Update delta_ts on the other bug so that we trigger mid-airs.
- $dbh->do('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?',
- undef, $delta_ts, $removed_id);
+ _update_delta_ts($removed_id, $delta_ts);
}
foreach my $added_id (@$added) {
$dbh->do("INSERT INTO dependencies ($type, $other) VALUES (?,?)",
@@ -902,8 +900,7 @@ sub update {
LogActivityEntry($added_id, $other, '', $self->id,
$user->id, $delta_ts);
# Update delta_ts on the other bug so that we trigger mid-airs.
- $dbh->do('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?',
- undef, $delta_ts, $added_id);
+ _update_delta_ts($added_id, $delta_ts);
}
if (scalar(@$removed) || scalar(@$added)) {
@@ -1035,8 +1032,7 @@ sub update {
if (scalar(keys %$changes) || $self->{added_comments}
|| $self->{comment_isprivate})
{
- $dbh->do('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?',
- undef, ($delta_ts, $self->id));
+ _update_delta_ts($self->id, $delta_ts);
$self->{delta_ts} = $delta_ts;
}
@@ -1145,6 +1141,17 @@ sub _sync_fulltext {
}
}
+# Update a bug's delta_ts without requiring the full object to be loaded.
+sub _update_delta_ts {
+ my ($bug_id, $timestamp) = @_;
+ Bugzilla->dbh->do(
+ "UPDATE bugs SET delta_ts = ? WHERE bug_id = ?",
+ undef,
+ $timestamp, $bug_id
+ );
+ Bugzilla::Hook::process('bug_end_of_update_delta_ts',
+ { bug_id => $bug_id, timestamp => $timestamp });
+}
# This is the correct way to delete bugs from the DB.
# No bug should be deleted from anywhere else except from here.
diff --git a/extensions/ZPushNotify/Config.pm b/extensions/ZPushNotify/Config.pm
new file mode 100644
index 000000000..e65169d41
--- /dev/null
+++ b/extensions/ZPushNotify/Config.pm
@@ -0,0 +1,15 @@
+# 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::Extension::ZPushNotify;
+use strict;
+
+use constant NAME => 'ZPushNotify';
+use constant REQUIRED_MODULES => [];
+use constant OPTIONAL_MODULES => [];
+
+__PACKAGE__->NAME;
diff --git a/extensions/ZPushNotify/Extension.pm b/extensions/ZPushNotify/Extension.pm
new file mode 100644
index 000000000..6e8ab4d27
--- /dev/null
+++ b/extensions/ZPushNotify/Extension.pm
@@ -0,0 +1,110 @@
+# 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::Extension::ZPushNotify;
+use strict;
+use warnings;
+
+use base qw(Bugzilla::Extension);
+our $VERSION = '1';
+
+use Bugzilla;
+
+#
+# insert into the notifications table
+#
+
+sub _notify {
+ my ($bug_id, $delta_ts) = @_;
+ Bugzilla->dbh->do(
+ "REPLACE INTO push_notify(bug_id, delta_ts) VALUES(?, ?)",
+ undef,
+ $bug_id, $delta_ts
+ );
+}
+
+#
+# object hooks
+#
+
+sub object_end_of_update {
+ my ($self, $args) = @_;
+ return unless Bugzilla->params->{enable_simple_push};
+ return unless scalar keys %{ $args->{changes} };
+ return unless my $object = $args->{object};
+ if ($object->isa('Bugzilla::Attachment')) {
+ _notify($object->bug->id, $object->bug->delta_ts);
+ }
+}
+
+sub object_before_delete {
+ my ($self, $args) = @_;
+ return unless Bugzilla->params->{enable_simple_push};
+ return unless my $object = $args->{object};
+ if ($object->isa('Bugzilla::Attachment')) {
+ _notify($object->bug->id, $object->bug->delta_ts);
+ }
+}
+
+sub bug_end_of_update_delta_ts {
+ my ($self, $args) = @_;
+ return unless Bugzilla->params->{enable_simple_push};
+ _notify($args->{bug_id}, $args->{timestamp});
+}
+
+sub bug_end_of_create {
+ my ($self, $args) = @_;
+ return unless Bugzilla->params->{enable_simple_push};
+ _notify($args->{bug}->id, $args->{timestamp});
+}
+
+#
+# schema / param
+#
+
+sub db_schema_abstract_schema {
+ my ($self, $args) = @_;
+ $args->{'schema'}->{'push_notify'} = {
+ FIELDS => [
+ id => {
+ TYPE => 'INTSERIAL',
+ NOTNULL => 1,
+ PRIMARYKEY => 1,
+ },
+ bug_id => {
+ TYPE => 'INT3',
+ NOTNULL => 1,
+ REFERENCES => {
+ TABLE => 'bugs',
+ COLUMN => 'bug_id',
+ DELETE => 'CASCADE'
+ },
+ },
+ delta_ts => {
+ TYPE => 'DATETIME',
+ NOTNULL => 1,
+ },
+ ],
+ INDEXES => [
+ push_notify_idx => {
+ FIELDS => [ 'bug_id' ],
+ TYPE => 'UNIQUE',
+ },
+ ],
+ };
+}
+
+sub config_modify_panels {
+ my ($self, $args) = @_;
+ push @{ $args->{panels}->{advanced}->{params} }, {
+ name => 'enable_simple_push',
+ type => 'b',
+ default => 0,
+ };
+}
+
+__PACKAGE__->NAME;
diff --git a/extensions/ZPushNotify/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl b/extensions/ZPushNotify/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl
new file mode 100644
index 000000000..e6c171916
--- /dev/null
+++ b/extensions/ZPushNotify/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl
@@ -0,0 +1,13 @@
+[%# 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.
+ #%]
+
+[% IF panel.name == "advanced" %]
+ [% panel.param_descs.enable_simple_push =
+ 'When enabled bug changes will result in an entry in the <code>push_notify</code> table'
+ %]
+[% END -%]