aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2011-02-20 13:46:15 +0100
committerChristian Ruppert <idl0r@gentoo.org>2011-02-20 13:46:15 +0100
commit180f7a828d5484d0b3f56367352b317dfd053e5f (patch)
tree66f132a5f9982c14642bfeb5f5bee5ab2c467038 /custom_userhistory.cgi
parentAdd runstats.sh (diff)
downloadbugzilla-180f7a828d5484d0b3f56367352b317dfd053e5f.tar.gz
bugzilla-180f7a828d5484d0b3f56367352b317dfd053e5f.tar.bz2
bugzilla-180f7a828d5484d0b3f56367352b317dfd053e5f.zip
Add custom_* scripts
Diffstat (limited to 'custom_userhistory.cgi')
-rwxr-xr-xcustom_userhistory.cgi125
1 files changed, 125 insertions, 0 deletions
diff --git a/custom_userhistory.cgi b/custom_userhistory.cgi
new file mode 100755
index 000000000..902003eca
--- /dev/null
+++ b/custom_userhistory.cgi
@@ -0,0 +1,125 @@
+#!/usr/bin/perl -wT
+use strict;
+
+use lib qw(. lib);
+
+use Data::Dumper;
+use Bugzilla;
+use Bugzilla::Constants;
+use Bugzilla::Util;
+
+my $cgi = Bugzilla->cgi;
+my $vars = {};
+my $dbh = Bugzilla->switch_to_shadow_db();
+my $myuser = Bugzilla->login(LOGIN_REQUIRED);
+my @bindValues;
+my $query;
+
+print $cgi->header();
+my $matchstr = $cgi->param('matchstr');
+exit 0 if !defined($matchstr);
+my $limit = $cgi->param('limit');
+$limit = 50 unless defined($limit) and $limit =~ /^\d+$/;
+$query = 'SELECT DISTINCT userid '.
+ 'FROM profiles '.
+ 'WHERE profiles.login_name = ?';
+trick_taint($matchstr);
+trick_taint($limit);
+push(@bindValues, $matchstr);
+$vars->{'users'} = $dbh->selectall_arrayref($query, {'Slice' => {}}, @bindValues);
+
+if(!defined($vars->{'users'}[0])) {
+ print "Bad user!<br>";
+ exit 0;
+}
+my $userid = $vars->{'users'}[0]->{'userid'};
+
+my @bindValues2;
+$query = sprintf
+ '(SELECT bug_id,bug_when,fielddefs.name AS field '.
+ 'FROM bugs_activity JOIN fielddefs ON bugs_activity.fieldid=fielddefs.id '.
+ 'WHERE who=? '.
+ 'ORDER BY bug_when DESC '.
+ 'LIMIT %d) '.
+ 'UNION '.
+ '(SELECT bug_id, bug_when, \'ZZcomment\' AS field '.
+ 'FROM longdescs '.
+ 'WHERE who=? '.
+ 'ORDER BY bug_when DESC '.
+ 'LIMIT %d) '.
+ 'ORDER BY bug_when DESC '.
+ 'LIMIT %d',
+ $limit,$limit,$limit;
+
+push(@bindValues2, $userid);
+push(@bindValues2, $userid);
+
+#print Dumper($vars);
+printf "%s<br>",$matchstr;
+my $actions = $dbh->selectall_arrayref(
+ $query,
+ { Slice => {} },
+ @bindValues2
+);
+
+my $counter = 0;
+foreach my $row (@$actions) {
+ printf "<a href=\"%9d\">%9d</a>: %s %s<br>", $row->{'bug_id'}, $row->{'bug_id'}, $row->{'bug_when'}, $row->{'field'};
+ $counter++;
+}
+printf "History Done. Limit=%d Count=%d<br><br>",$limit,$counter;
+
+$query = 'SELECT
+p2.userid AS grantor_id, p1.userid AS grantee_id,
+p2.login_name AS grantor, p1.login_name AS grantee,profiles_when,oldvalue,newvalue
+FROM profiles p1
+JOIN profiles_activity ON p1.userid=profiles_activity.userid
+JOIN profiles p2 ON p2.userid=who
+WHERE p1.userid = ? OR p2.userid = ?
+ORDER BY profiles_when';
+my @bindValues3;
+push(@bindValues3, $userid);
+push(@bindValues3, $userid);
+$actions = $dbh->selectall_arrayref(
+ $query,
+ { Slice => {} },
+ @bindValues3
+);
+
+printf "Applied to %s:<br>",$matchstr;
+foreach my $row (@$actions) {
+ printf "%s: by %s: %s%s %s%s<br>", $row->{'profiles_when'}, $row->{'grantor'}, $row->{'oldvalue'} ? '-' : '', $row->{'oldvalue'}, $row->{'newvalue'}? '+' : '', $row->{'newvalue'} if $row->{'grantee_id'} == $userid;
+}
+printf "<br>";
+
+printf "Applied by %s:<br>",$matchstr;
+foreach my $row (@$actions) {
+ printf "%s: to %s: %s%s %s%s<br>", $row->{'profiles_when'}, $row->{'grantee'}, $row->{'oldvalue'} ? '-' : '', $row->{'oldvalue'}, $row->{'newvalue'}? '+' : '', $row->{'newvalue'} if $row->{'grantor_id'} == $userid;
+}
+printf "<br>";
+
+$query = 'SELECT
+p1.userid AS watcher_id, p2.userid AS watched_id,
+p1.login_name AS watcher, p2.login_name AS watched
+FROM profiles p1
+JOIN watch ON p1.userid=watch.watcher
+JOIN profiles p2 ON p2.userid=watch.watched
+ORDER BY watcher,watched
+';
+$actions = $dbh->selectall_arrayref(
+ $query,
+ { Slice => {} },
+);
+printf "Watchers of %s:<br>", $matchstr;
+foreach my $row (@$actions) {
+printf "%s<br>", $row->{'watcher'} if $row->{'watched_id'} == $userid;
+}
+printf "<br>";
+
+printf "Watched by %s:<br>", $matchstr;
+foreach my $row (@$actions) {
+printf "%s<br>", $row->{'watched'} if $row->{'watcher_id'} == $userid;
+}
+printf "<br>";
+
+printf "Done.<br>";