undo reorganization
[buildfarm-server.git] / cgi-bin / show_history.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7
8 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
9
10
11 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
12 #require "BuildFarmWeb.pl";
13
14 die "no dbname" unless $dbname;
15 die "no dbuser" unless $dbuser;
16
17 my $dsn="dbi:Pg:dbname=$dbname";
18 $dsn .= ";host=$dbhost" if $dbhost;
19 $dsn .= ";port=$dbport" if $dbport;
20
21 my $db = DBI->connect($dsn,$dbuser,$dbpass);
22
23 die $DBI::errstr unless $db;
24
25 my $query = new CGI;
26 my $member = $query->param('nm'); $member =~ s/[^a-zA-Z0-9_ -]//g;
27 my $branch = $query->param('br'); $branch =~ s/[^a-zA-Z0-9_ -]//g;
28 my $hm = $query->param('hm');  $hm =~ s/[^a-zA-Z0-9_ -]//g;
29 $hm = '240' unless $hm =~ /^\d+$/;
30
31 my $latest_personality = $db->selectrow_arrayref(q{
32             select os_version, compiler_version
33             from personality
34             where name = ?
35             order by effective_date desc limit 1
36         }, undef, $member);
37
38 # we don't really need to do this join, since we only want
39 # one row from buildsystems. but it means we only have to run one
40 # query. If it gets heavy we'll split it up and run two
41
42 my $statement = <<EOS;
43
44   select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago,
45       sysname, snapshot, b.status, stage,
46       operating_system, os_version, compiler, compiler_version, architecture,
47       owner_email,
48       sys_notes_ts::date AS sys_notes_date, sys_notes
49   from buildsystems s, 
50        build_status b 
51   where name = ?
52         and branch = ?
53         and s.status = 'approved'
54         and name = sysname
55   order by snapshot desc
56   limit $hm
57
58 EOS
59 ;
60
61 my $statrows=[];
62 my $sth=$db->prepare($statement);
63 $sth->execute($member,$branch);
64 while (my $row = $sth->fetchrow_hashref)
65 {
66     $row->{owner_email} =~ s/\@/ [ a t ] /;
67     if ($latest_personality)
68     {
69         $row->{os_version} = $latest_personality->[0];
70         $row->{compiler_version} = $latest_personality->[1];
71     }
72     push(@$statrows,$row);
73 }
74
75 $sth->finish;
76
77 $db->disconnect;
78
79 my $template_opts = { INCLUDE_PATH => $template_dir, EVAL_PERL => 1 };
80 my $template = new Template($template_opts);
81
82 print "Content-Type: text/html\n\n";
83
84 $template->process('history.tt',
85                    {statrows=>$statrows, 
86                     branch=>$branch, 
87                     member => $member,
88                     hm => $hm
89                     });
90
91 exit;