#!/usr/bin/perl -wT -I.
use CGI;
use Tinderbox3::Header;
use Tinderbox3::Actions;
use Tinderbox3::DB;
use strict;
#
# Init
#
my $p = new CGI;
my $dbh = get_dbh();
my $tree = update_tree($p, $dbh);
my $tree_str = "Edit $tree" || "Add Tree";
header($p, $tree_str);
process_actions($p, $dbh);
#
# Get the tree info to fill in the fields
#
my $tree_info;
if (!$tree) {
# XXX Pull these out into defaults elsewhere
$tree_info = [ '',
'refcount_leaks=Lk,refcount_bloat=Bl,trace_malloc_leaks=Lk,trace_malloc_maxheap=MH,trace_malloc_allocs=A,pageload=Tp,codesize=Z,xulwinopen=Txul,startup=Ts,binary_url=Binary,warnings=Warn',
'refcount_leaks=Graph,refcount_bloat=Graph,trace_malloc_leaks=Graph,trace_malloc_maxheap=Graph,trace_malloc_allocs=Graph,pageload=Graph,codesize=Graph,xulwinopen=Graph,startup=Graph,binary_url=URL,warnings=Warn',
];
} else {
$tree_info = $dbh->selectrow_arrayref("SELECT password, field_short_names, field_processors FROM tbox_tree WHERE tree_name = ?", undef, $tree);
}
#
# Edit / Add tree form
#
print "
\n";
}
footer($p);
$dbh->disconnect;
#
# Update / Insert the tree and perform other DB operations
#
sub update_tree {
my ($p, $dbh) = @_;
my $tree = $p->param('tree') || "";
my $action = $p->param('action') || "";
if ($action eq 'edit_tree') {
my $newtree = $p->param('_tree_name') || "";
my $password = $p->param('_password') || "";
my $field_short_names = $p->param('_field_short_names') || "";
my $field_processors = $p->param('_field_processors') || "";
if (!$newtree) { die "Must specify a non-blank tree!"; }
# Update or insert the tree
if ($tree) {
my $rows = $dbh->do("UPDATE tbox_tree SET tree_name = ?, password = ?, field_short_names = ?, field_processors = ? WHERE tree_name = ?", undef, $newtree, $password, $field_short_names, $field_processors, $tree);
if (!$rows) {
die "No tree named $tree!";
}
} else {
my $rows = $dbh->do("INSERT INTO tbox_tree (tree_name, password, field_short_names, field_processors) VALUES (?, ?, ?, ?)", undef, $newtree, $password, $field_short_names, $field_processors);
if (!$rows) {
die "Passing strange. Insert failed.";
}
$tree = $newtree;
}
$dbh->commit;
} elsif ($action eq 'delete_patch') {
my $patch_id = $p->param('_patch_id') || "";
if (!$patch_id) { die "Need patch id!" }
my $rows = $dbh->do("DELETE FROM tbox_patch WHERE tree_name = ? AND patch_id = ?", undef, $tree, $patch_id);
if (!$rows) {
die "Delete failed. No such tree / patch.";
}
$dbh->commit;
} elsif ($action eq 'obsolete_patch') {
my $patch_id = $p->param('_patch_id') || "";
if (!$patch_id) { die "Need patch id!" }
my $rows = $dbh->do("UPDATE tbox_patch SET obsolete = 'Y' WHERE tree_name = ? AND patch_id = ?", undef, $tree, $patch_id);
if (!$rows) {
die "Update failed. No such tree / patch.";
}
$dbh->commit;
}
return $tree;
}