Skip to content

Commit

Permalink
Also insert the (relevant parts of the) comment into the database
Browse files Browse the repository at this point in the history
  • Loading branch information
yoe committed Feb 5, 2024
1 parent ab9a5a6 commit 198c0bd
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion scripts/sreview-reply
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $comment->execute($nonce) or die "Cannot fetch comments!";

my $formatter = Text::Format->new(firstIndent => 0);
open my $start, ">", "/tmp/reply-$nonce" or die "Cannot open reply file!";
my $instructions = $formatter->paragraphs("Please reply to this email with your comments. Any use of a '#' character introduces a comment; comments will be removed before sending. If you wish to abort, make sure the word 'ABORT' appears in the (uncommented part of the) reply.");
my $instructions = $formatter->paragraphs("Please reply to this email with your comments. Any use of a '#' character introduces a comment; comments will be removed before sending. If you wish to abort, make sure the word 'ABORT' appears in the (not-commented part of the) reply.\n\nAny (not-commented) lines that appear after the '#----' line will be entered as a comment in the database");
$instructions .= "\n";
$instructions =~ s/^/# /gm;
print $start "$instructions";
Expand All @@ -39,17 +39,30 @@ while(my $row = $comment->fetchrow_hashref()) {
$para =~ s/^/ /gm;
print $start "$para\n";
}
print $start "#----\n";
close $start;

system("sensible-editor", "/tmp/reply-$nonce");

my $reply = "";
my $dbcomment = "";
my $is_db = 0;
my $found_db = 0;
open my $reply_file, "<", "/tmp/reply-$nonce" or die "Cannot open reply file!";
LINE:
foreach my $line (<$reply_file>) {
if($line =~ /^#----$/) {
$is_db = 1;
}
next if $line =~ /^#/;
$line =~ s/#.*//;
$reply .= $line;
if($is_db) {
$dbcomment .= $line;
if($line =~ /^.+$/) {
$found_db = 1;
}
}
}
close $reply_file;
unlink "/tmp/reply-$nonce";
Expand All @@ -58,6 +71,15 @@ if($reply =~ /ABORT/) {
exit 0;
}

if($found_db) {
chomp $dbcomment;
my $add_comment = $dbh->prepare("WITH talkdata(comment, id, state) AS (SELECT ?, id, state FROM talks WHERE nonce = ?) INSERT INTO commentlog(comment, talk, state) SELECT * FROM talkdata");
$add_comment->execute($dbcomment, $nonce) or die $!;
$reply .= "\n\n(this comment was also entered into the system)";
} else {
$reply .= "\n\n(this comment was NOT entered into the system)";
}

my @recips;
my $title;
foreach my $mailer (@{$mailers->fetchall_arrayref({})}) {
Expand Down

0 comments on commit 198c0bd

Please sign in to comment.