summaryrefslogtreecommitdiffstats
path: root/extensions/RequestNagger/lib
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/RequestNagger/lib')
-rw-r--r--extensions/RequestNagger/lib/Constants.pm33
-rw-r--r--extensions/RequestNagger/lib/Settings.pm61
2 files changed, 87 insertions, 7 deletions
diff --git a/extensions/RequestNagger/lib/Constants.pm b/extensions/RequestNagger/lib/Constants.pm
index 899336a72..66780ad63 100644
--- a/extensions/RequestNagger/lib/Constants.pm
+++ b/extensions/RequestNagger/lib/Constants.pm
@@ -147,12 +147,22 @@ sub WATCHING_REQUESTEE_NAG_SQL {
LEFT JOIN nag_defer ON nag_defer.flag_id = flags.id
INNER JOIN nag_watch ON nag_watch.nagged_id = flags.requestee_id
INNER JOIN profiles AS watcher ON watcher.userid = nag_watch.watcher_id
+ LEFT JOIN nag_settings AS reviews_only ON reviews_only.user_id = nag_watch.watcher_id
+ AND reviews_only.setting_name = 'reviews_only'
+ LEFT JOIN nag_settings AS extended_period ON extended_period.user_id = nag_watch.watcher_id
+ AND extended_period.setting_name = 'extended_period'
WHERE
- " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
- AND flags.status = '?'
+ flags.status = '?'
AND products.nag_interval != 0
- AND TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
AND watcher.disable_mail = 0
+ AND CASE WHEN COALESCE(reviews_only.setting_value, 0) = 1
+ THEN flagtypes.name = 'review'
+ ELSE " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
+ END
+ AND CASE WHEN COALESCE(extended_period.setting_value, 0) = 1
+ THEN TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval + 24
+ ELSE TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
+ END
ORDER BY
nag_watch.watcher_id,
flags.requestee_id,
@@ -187,12 +197,22 @@ sub WATCHING_SETTER_NAG_SQL {
LEFT JOIN nag_defer ON nag_defer.flag_id = flags.id
INNER JOIN nag_watch ON nag_watch.nagged_id = flags.setter_id
INNER JOIN profiles AS watcher ON watcher.userid = nag_watch.watcher_id
+ LEFT JOIN nag_settings AS reviews_only ON reviews_only.user_id = nag_watch.watcher_id
+ AND reviews_only.setting_name = 'reviews_only'
+ LEFT JOIN nag_settings AS extended_period ON extended_period.user_id = nag_watch.watcher_id
+ AND extended_period.setting_name = 'extended_period'
WHERE
- " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
- AND flags.status = '?'
+ flags.status = '?'
AND products.nag_interval != 0
- AND TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
AND watcher.disable_mail = 0
+ AND CASE WHEN COALESCE(reviews_only.setting_value, 0) = 1
+ THEN flagtypes.name = 'review'
+ ELSE " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
+ END
+ AND CASE WHEN COALESCE(extended_period.setting_value, 0) = 1
+ THEN TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval + 24
+ ELSE TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
+ END
ORDER BY
nag_watch.watcher_id,
flags.requestee_id,
@@ -200,5 +220,4 @@ sub WATCHING_SETTER_NAG_SQL {
";
}
-
1;
diff --git a/extensions/RequestNagger/lib/Settings.pm b/extensions/RequestNagger/lib/Settings.pm
new file mode 100644
index 000000000..5407eac1d
--- /dev/null
+++ b/extensions/RequestNagger/lib/Settings.pm
@@ -0,0 +1,61 @@
+# 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::RequestNagger::Settings;
+use strict;
+use warnings;
+
+use Bugzilla;
+use List::MoreUtils qw( any );
+
+use constant FIELDS => qw( reviews_only extended_period no_encryption );
+
+sub new {
+ my ($class, $user_id) = @_;
+
+ my $dbh = Bugzilla->dbh;
+ my $self = { user_id => $user_id };
+ foreach my $row (@{ $dbh->selectall_arrayref(
+ "SELECT setting_name,setting_value FROM nag_settings WHERE user_id = ?",
+ { Slice => {} },
+ $user_id
+ ) }) {
+ $self->{$row->{setting_name}} = $row->{setting_value};
+ }
+
+ return bless($self, $class);
+}
+
+sub reviews_only { exists $_[0]->{reviews_only} ? $_[0]->{reviews_only} : 0 }
+sub extended_period { exists $_[0]->{extended_period} ? $_[0]->{extended_period} : 0 }
+sub no_encryption { exists $_[0]->{no_encryption} ? $_[0]->{no_encryption} : 0 }
+
+sub set {
+ my ($self, $field, $value) = @_;
+ return unless any { $_ eq $field } FIELDS;
+ $value = $value ? 1 : 0;
+
+ my $dbh = Bugzilla->dbh;
+ if (exists $self->{$field}) {
+ $dbh->do(
+ "UPDATE nag_settings SET setting_value=? WHERE user_id=? AND setting_name=?",
+ undef,
+ $value, $self->{user_id}, $field
+ );
+ }
+ else {
+ $dbh->do(
+ "INSERT INTO nag_settings(user_id, setting_name, setting_value) VALUES (?, ?, ?)",
+ undef,
+ $self->{user_id}, $field, $value
+ );
+ }
+
+ $self->{$field} = $value;
+}
+
+1;