From 198c0bd9d219f761e77427c2041d98aeee55e996 Mon Sep 17 00:00:00 2001 From: Wouter Verhelst Date: Mon, 5 Feb 2024 10:51:39 +0200 Subject: [PATCH] Also insert the (relevant parts of the) comment into the database --- scripts/sreview-reply | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/sreview-reply b/scripts/sreview-reply index e839d75..8dc676b 100644 --- a/scripts/sreview-reply +++ b/scripts/sreview-reply @@ -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"; @@ -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"; @@ -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({})}) {