summaryrefslogtreecommitdiffstats
path: root/extensions/RequestNagger/lib
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-10-29 06:32:25 +0100
committerByron Jones <bjones@mozilla.com>2013-10-29 06:32:25 +0100
commit4c09622b4432820e49795345a747e530e5aa0764 (patch)
tree6fc3203ae7296de1fadadf1fce06d6644c4debfc /extensions/RequestNagger/lib
parent9b6f5d07a80ff630ed76108e0ca9689b4e2410f5 (diff)
downloadbugzilla-4c09622b4432820e49795345a747e530e5aa0764.tar.gz
bugzilla-4c09622b4432820e49795345a747e530e5aa0764.tar.xz
Bug 892615: Add a 24 hour nag to all requests (review, feedback and need-info) and make them follow-able
Diffstat (limited to 'extensions/RequestNagger/lib')
-rw-r--r--extensions/RequestNagger/lib/Constants.pm111
-rw-r--r--extensions/RequestNagger/lib/TimeAgo.pm186
2 files changed, 297 insertions, 0 deletions
diff --git a/extensions/RequestNagger/lib/Constants.pm b/extensions/RequestNagger/lib/Constants.pm
new file mode 100644
index 000000000..ff31b94e0
--- /dev/null
+++ b/extensions/RequestNagger/lib/Constants.pm
@@ -0,0 +1,111 @@
+# 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::Constants;
+
+use strict;
+use base qw(Exporter);
+
+our @EXPORT = qw(
+ FLAG_TYPES
+ REQUESTEE_NAG_SQL
+ WATCHING_NAG_SQL
+);
+
+# the order of this array determines the order used in email
+use constant FLAG_TYPES => (
+ {
+ type => 'review', # flag_type.name
+ group => 'everyone', # the user must be a member of this group to receive reminders
+ },
+ {
+ type => 'feedback',
+ group => 'everyone',
+ },
+ {
+ type => 'needinfo',
+ group => 'editbugs',
+ },
+);
+
+sub REQUESTEE_NAG_SQL {
+ my $dbh = Bugzilla->dbh;
+ my @flag_types_sql = map { $dbh->quote($_->{type}) } FLAG_TYPES;
+
+ return "
+ SELECT
+ flagtypes.name AS flag_type,
+ flags.id AS flag_id,
+ flags.bug_id,
+ flags.attach_id,
+ flags.modification_date,
+ requester.userid AS requester_id,
+ requestee.userid AS requestee_id
+ FROM
+ flags
+ INNER JOIN flagtypes ON flagtypes.id = flags.type_id
+ INNER JOIN profiles AS requester ON requester.userid = flags.setter_id
+ INNER JOIN profiles AS requestee ON requestee.userid = flags.requestee_id
+ INNER JOIN bugs ON bugs.bug_id = flags.bug_id
+ INNER JOIN products ON products.id = bugs.product_id
+ LEFT JOIN attachments ON attachments.attach_id = flags.attach_id
+ LEFT JOIN profile_setting ON profile_setting.setting_name = 'request_nagging'
+ LEFT JOIN nag_defer ON nag_defer.flag_id = flags.id
+ WHERE
+ " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
+ AND flags.status = '?'
+ AND products.nag_interval != 0
+ AND TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
+ AND (profile_setting.setting_value IS NULL OR profile_setting.setting_value = 'on')
+ AND requestee.disable_mail = 0
+ AND nag_defer.id IS NULL
+ ORDER BY
+ flags.requestee_id,
+ flagtypes.name,
+ flags.modification_date
+ ";
+}
+
+sub WATCHING_NAG_SQL {
+ my $dbh = Bugzilla->dbh;
+ my @flag_types_sql = map { $dbh->quote($_->{type}) } FLAG_TYPES;
+
+ return "
+ SELECT
+ nag_watch.watcher_id,
+ flagtypes.name AS flag_type,
+ flags.id AS flag_id,
+ flags.bug_id,
+ flags.attach_id,
+ flags.modification_date,
+ requester.userid AS requester_id,
+ requestee.userid AS requestee_id
+ FROM
+ flags
+ INNER JOIN flagtypes ON flagtypes.id = flags.type_id
+ INNER JOIN profiles AS requester ON requester.userid = flags.setter_id
+ INNER JOIN profiles AS requestee ON requestee.userid = flags.requestee_id
+ INNER JOIN bugs ON bugs.bug_id = flags.bug_id
+ INNER JOIN products ON products.id = bugs.product_id
+ LEFT JOIN attachments ON attachments.attach_id = flags.attach_id
+ 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
+ WHERE
+ " . $dbh->sql_in('flagtypes.name', \@flag_types_sql) . "
+ AND flags.status = '?'
+ AND products.nag_interval != 0
+ AND TIMESTAMPDIFF(HOUR, flags.modification_date, CURRENT_DATE()) >= products.nag_interval
+ AND watcher.disable_mail = 0
+ ORDER BY
+ nag_watch.watcher_id,
+ flags.requestee_id,
+ flags.modification_date
+ ";
+}
+
+1;
diff --git a/extensions/RequestNagger/lib/TimeAgo.pm b/extensions/RequestNagger/lib/TimeAgo.pm
new file mode 100644
index 000000000..3dfbbeaac
--- /dev/null
+++ b/extensions/RequestNagger/lib/TimeAgo.pm
@@ -0,0 +1,186 @@
+# 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::TimeAgo;
+
+use strict;
+use utf8;
+use DateTime;
+use Carp;
+use Exporter qw(import);
+
+use if $ENV{ARCH_64BIT}, 'integer';
+
+our @EXPORT_OK = qw(time_ago);
+
+our $VERSION = '0.06';
+
+my @ranges = (
+ [ -1, 'in the future' ],
+ [ 60, 'just now' ],
+ [ 900, 'a few minutes ago'], # 15*60
+ [ 3000, 'less than an hour ago'], # 50*60
+ [ 4500, 'about an hour ago'], # 75*60
+ [ 7200, 'more than an hour ago'], # 2*60*60
+ [ 21600, 'several hours ago'], # 6*60*60
+ [ 86400, 'today', sub { # 24*60*60
+ my $time = shift;
+ my $now = shift;
+ if ( $time->day < $now->day
+ or $time->month < $now->month
+ or $time->year < $now->year
+ ) {
+ return 'yesterday'
+ }
+ if ($time->hour < 5) {
+ return 'tonight'
+ }
+ if ($time->hour < 10) {
+ return 'this morning'
+ }
+ if ($time->hour < 15) {
+ return 'today'
+ }
+ if ($time->hour < 19) {
+ return 'this afternoon'
+ }
+ return 'this evening'
+ }],
+ [ 172800, 'yesterday'], # 2*24*60*60
+ [ 604800, 'this week'], # 7*24*60*60
+ [ 1209600, 'last week'], # 2*7*24*60*60
+ [ 2678400, 'this month', sub { # 31*24*60*60
+ my $time = shift;
+ my $now = shift;
+ if ($time->year == $now->year and $time->month == $now->month) {
+ return 'this month'
+ }
+ return 'last month'
+ }],
+ [ 5356800, 'last month'], # 2*31*24*60*60
+ [ 24105600, 'several months ago'], # 9*31*24*60*60
+ [ 31536000, 'about a year ago'], # 365*24*60*60
+ [ 34214400, 'last year'], # (365+31)*24*60*60
+ [ 63072000, 'more than a year ago'], # 2*365*24*60*60
+ [ 283824000, 'several years ago'], # 9*365*24*60*60
+ [ 315360000, 'about a decade ago'], # 10*365*24*60*60
+ [ 630720000, 'last decade'], # 20*365*24*60*60
+ [ 2838240000, 'several decades ago'], # 90*365*24*60*60
+ [ 3153600000, 'about a century ago'], # 100*365*24*60*60
+ [ 6307200000, 'last century'], # 200*365*24*60*60
+ [ 6622560000, 'more than a century ago'], # 210*365*24*60*60
+ [ 28382400000, 'several centuries ago'], # 900*365*24*60*60
+ [ 31536000000, 'about a millenium ago'], # 1000*365*24*60*60
+ [ 63072000000, 'more than a millenium ago'], # 2000*365*24*60*60
+);
+
+sub time_ago {
+ my ($time, $now) = @_;
+
+ if (not defined $time or not $time->isa('DateTime')) {
+ croak('DateTime::Duration::Fuzzy::time_ago needs a DateTime object as first parameter')
+ }
+ if (not defined $now) {
+ $now = DateTime->now();
+ }
+ if (not $now->isa('DateTime')) {
+ croak('Invalid second parameter provided to DateTime::Duration::Fuzzy::time_ago; it must be a DateTime object if provided')
+ }
+
+ my $dur = $now->subtract_datetime_absolute($time)->in_units('seconds');
+
+ foreach my $range ( @ranges ) {
+ if ( $dur <= $range->[0] ) {
+ if ( $range->[2] ) {
+ return $range->[2]->($time, $now)
+ }
+ return $range->[1]
+ }
+ }
+
+ return 'millenia ago'
+}
+
+1
+
+__END__
+
+=head1 NAME
+
+DateTime::Duration::Fuzzy -- express dates as fuzzy human-friendly strings
+
+=head1 SYNOPSIS
+
+ use DateTime::Duration::Fuzzy qw(time_ago);
+ use DateTime;
+
+ my $now = DateTime->new(
+ year => 2010, month => 12, day => 12,
+ hour => 19, minute => 59,
+ );
+ my $then = DateTime->new(
+ year => 2010, month => 12, day => 12,
+ hour => 15,
+ );
+ print time_ago($then, $now);
+ # outputs 'several hours ago'
+
+ print time_ago($then);
+ # $now taken from C<time> function
+
+=head1 DESCRIPTION
+
+DateTime::Duration::Fuzzy is inspired from the timeAgo jQuery module
+L<http://timeago.yarp.com/>.
+
+It takes two DateTime objects -- first one representing a moment in the past
+and second optional one representine the present, and returns a human-friendly
+fuzzy expression of the time gone.
+
+=head2 functions
+
+=over 4
+
+=item time_ago($then, $now)
+
+The only exportable function.
+
+First obligatory parameter is a DateTime object.
+
+Second optional parameter is also a DateTime object.
+If it's not provided, then I<now> as the C<time> function returns is
+substituted.
+
+Returns a string expression of the interval between the two DateTime
+objects, like C<several hours ago>, C<yesterday> or <last century>.
+
+=back
+
+=head2 performance
+
+On 64bit machines, it is asvisable to 'use integer', which makes
+the calculations faster. You can turn this on by setting the
+C<ARCH_64BIT> environmental variable to a true value.
+
+If you do this on a 32bit machine, you will get wrong results for
+intervals starting with "several decades ago".
+
+=head1 AUTHOR
+
+Jan Oldrich Kruza, C<< <sixtease at cpan.org> >>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2010 Jan Oldrich Kruza.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
+=cut