2b822ca2c2d2735f3e49ae46785b7e535628cc87
[buildfarm-server.git] / cgi-bin / show_history.pl
1 #!/usr/bin/perl
2
3 =comment
4
5 Copyright (c) 2003-2010, Andrew Dunstan
6
7 See accompanying License file for license details
8
9 =cut 
10
11 use strict;
12 use DBI;
13 use Template;
14 use CGI;
15
16 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
17
18
19 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
20 #require "BuildFarmWeb.pl";
21
22 die "no dbname" unless $dbname;
23 die "no dbuser" unless $dbuser;
24
25 my $dsn="dbi:Pg:dbname=$dbname";
26 $dsn .= ";host=$dbhost" if $dbhost;
27 $dsn .= ";port=$dbport" if $dbport;
28
29 my $db = DBI->connect($dsn,$dbuser,$dbpass);
30
31 die $DBI::errstr unless $db;
32
33 my $query = new CGI;
34 my $member = $query->param('nm'); $member =~ s/[^a-zA-Z0-9_ -]//g;
35 my $branch = $query->param('br'); $branch =~ s/[^a-zA-Z0-9_ -]//g;
36 my $hm = $query->param('hm');  $hm =~ s/[^a-zA-Z0-9_ -]//g;
37 $hm = '240' unless $hm =~ /^\d+$/;
38
39 my $latest_personality = $db->selectrow_arrayref(q{
40             select os_version, compiler_version
41             from personality
42             where name = ?
43             order by effective_date desc limit 1
44         }, undef, $member);
45
46 my $systemdata = q{
47     select operating_system, os_version, compiler, compiler_version, architecture,
48       owner_email, sys_notes_ts::date AS sys_notes_date, sys_notes
49     from buildsystems b
50     where b.status = 'approved'
51         and name = ?
52 };
53
54 my $statement = qq{
55    with x as 
56    (  select * 
57       from build_status_recent_500
58       where sysname = ? 
59          and branch = ?
60    ) 
61    select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago, 
62             sysname, snapshot, status, stage 
63    from x 
64    order by snapshot desc  
65    limit $hm
66 }
67 ;
68
69 my $sth = $db->prepare($systemdata);
70 $sth->execute($member);
71 my $sysrow = $sth->fetchrow_hashref;
72 my $statrows=[];
73 $sth=$db->prepare($statement);
74 $sth->execute($member,$branch);
75 while (my $row = $sth->fetchrow_hashref)
76 {
77     last unless $sysrow;
78     while (my($k,$v) = each %$sysrow) { $row->{$k} = $v; }
79     $row->{owner_email} =~ s/\@/ [ a t ] /;
80     if ($latest_personality)
81     {
82         $row->{os_version} = $latest_personality->[0];
83         $row->{compiler_version} = $latest_personality->[1];
84     }
85     push(@$statrows,$row);
86 }
87
88 $sth->finish;
89
90 $db->disconnect;
91
92 my $template_opts = { INCLUDE_PATH => $template_dir, EVAL_PERL => 1 };
93 my $template = new Template($template_opts);
94
95 print "Content-Type: text/html\n\n";
96
97 $template->process('history.tt',
98                    {statrows=>$statrows, 
99                     branch=>$branch, 
100                     member => $member,
101                     hm => $hm
102                     });
103
104 exit;