use warnings;
use strict;
+use Bugs::Message;
+
my $SELECT_FIELDS = "id,title";
sub new {
");
$sth ->execute($args{ID}) or die "Failed to lookup bug";
$row = $sth->fetchrow_arrayref;
+ return undef unless $row;
$sth->finish;
} else { die "Bugs::Bug->new needs ID or Fields"; }
my $bugid = $dbh->sqlite_last_insert_rowid();
- return $class->new($dbh, ID => $bugid, Title=>$subj);
+ my $self = $class->new($dbh, ID => $bugid);
+
+ my $msg = Bugs::Message->lookup_msgid($dbh, $msgid, Insert => 1);
+ print "Self is ".$msg->{id}."\n";
+ $self->add_subthread($msg);
+
+ return $self;
}
sub set {
my $add = shift;
my $m = shift;
+ print "addremove $add $m\n";
my $sth = $self->{dbh}->prepare(q{
INSERT INTO bug2message (include,bugid,messageid) VALUES (?,?,?)
});
sub messages {
my $self = shift;
- my %refs;
-
my $sth = $self->{dbh}->prepare(q{
- SELECT include,messageid FROM bug2message WHERE bugid = ?
+ SELECT include,messageid FROM bug2message WHERE bugid = ? ORDER BY id
});
$sth->execute($self->{id});
+ my %refs;
+
while ( defined(my $row = $sth->fetch) ) {
my ($inc,$msgid) = @$row;
- print "$msgid, $inc\n";
+ my $m = Bugs::Message->lookup_id($self->{dbh}, $msgid);
+ #print "Subthread ".$m->{msgid}."\n";
+ $m->subthread($inc, \%refs);
}
+ return \%refs;
}
sub listall ($$) {
}
sub _subthread {
- my ($self,$refs) = @_;
+ my ($self,$inc,$refs) = @_;
my $sth = $self->{dbh}->prepare(q{SELECT childid FROM refs WHERE parentid = ?});
- $sth->execute($self->{id});
- my $r;
- while ( defined($r = $sth->fetch) ) {
+ $sth->execute($self->{id}) or die "Lookup subthread";
+ while ( defined(my $r = $sth->fetch) ) {
my $id = $r->[0];
- next if exists $refs->{$id};
- $refs->{$id} = 1;
+ #print $refs->{$id} . " == $inc?\n" if exists $refs->{$id};
+ next if exists $refs->{$id} and $refs->{$id} eq $inc;
+ $refs->{$id} = $inc;
my $m = Bugs::Message->lookup_id($self->{dbh}, $id);
#print "REF: $id = " . $m->{msgid} . "\n";
- $m->_subthread($refs)
+ $m->_subthread($inc,$refs)
}
$sth->finish;
}
sub subthread {
my $self = shift;
#my %args = @_;
- my %refs;
- $refs{$self->{id}} = 1;
- $self->_subthread(\%refs);
- return keys %refs;
+ my $inc = shift;
+ my $refs = shift || {};
+
+ $refs->{$self->{id}} = $inc;
+ $self->_subthread($inc,$refs);
+ return keys %$refs;
}
1;
--- /dev/null
+#!/usr/bin/perl -I/home/ijc/devel/bugs
+
+use strict;
+use warnings;
+
+use CGI qw/:standard/;
+use CGI::Carp qw(fatalsToBrowser);
+
+use Bugs::Bug;
+use Bugs::Common;
+
+require 'common.pl';
+
+readconfig;
+my $dbh = opendb;
+
+my $bugid = param("id");
+my $bug = Bugs::Bug->new($dbh, ID => $bugid);
+
+if ( ! $bug ) {
+ print header;
+
+ print start_html(-title=>$c{TrackerName}.": #$bugid - Unknown Bug Number",
+ -style => { 'src' => '/css/style.css'});
+
+ print h1("#$bugid - Unknown Bug Number");
+ print p(["Ooops. This bug doesn't seem to exist."]);
+ print end_html;
+ exit (0);
+}
+
+print header;
+
+print start_html(-title=>$c{TrackerName}.": #$bugid - ".$bug->{title},
+ -style=>{'src' => '/css/style.css'});
+
+print h1("#$bugid - ".$bug->{title});
+
+print p(["Metadata goes here..."]),
+ hr;
+
+sub htmlsanit {
+ my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
+ my $in = shift || "";
+ $in =~ s/([<>&"])/\&$saniarray{$1};/g;
+ return $in;
+}
+
+our $msgs = $bug->messages;
+
+print "\n";
+foreach my $msgid ( keys $msgs ) {
+ my $m = Bugs::Message->lookup_id($dbh, $msgid);
+ my $body = $m->body;
+ my @body = <$body>;
+ print p({-class=>"message"},
+ [pre({-class=>"headers"},
+ join("\n", (b("From: ") . "Foo;",
+ b("To: ") . "Bar;",
+ b("Subject: ") . $m->{subject},
+ b("Date: ") . "Baz"))),
+ pre({-class=>"body"}, join("\n",@body)),
+ ]);
+ print hr . "\n";
+}
+
+#print ul_start;
+#foreach my $msgid ( keys $msgs ) {
+# my $m = Bugs::Message->lookup_id($dbh, $msgid);
+# print li("$msgid = ".$m->{subject} . " (".$msgs->{$msgid}.") = ".htmlsanit(#$m->{msgid}));
+#}
+#print ul_end;
+
+print end_html;
+
+
my $b = lookup_bugid $1;
my $m = lookup_msgid $2;
push @reply, "Prune `".$m->{msgid}."' from #".$b->{id};
- $b->add_subthread($m);
+ $b->remove_subthread($m);
return 1;
}
my $b = lookup_bugid $1;
my $m = lookup_msgid $2;
push @reply, "Graft `".$m->{msgid}."' onto #".$b->{id};
- $b->remove_subthread($m);
+ $b->add_subthread($m);
return 1;
}
--- /dev/null
+pre.headers {
+ font-family: sans-serif;
+ font-size: 95%;
+ color: #3c3c3c;
+ background-color: #f0f0f0;
+ padding: 2px;
+ border: #a7a7a7 1px solid;
+ line-height: 120%
+}
our $id = $msg->id;
print STDERR "Message is $id\n";
-our @msgs = $msg->subthread;
+our @msgs = $msg->subthread(1);
for my $r ( @msgs ) {
my $m = Bugs::Message->lookup_id($dbh, $r);