From 03fc791dbec7c767b1d3bbb2ae4ae1c6622f1682 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Mon, 26 Sep 2022 12:23:33 -0400 Subject: [PATCH] Bug 31627: Add ability to embed the letter id in outgoing email notices It can be useful to know exactly what template was used to generate a notice. To further this end, it would be useful be able to send the letter id as part of any emails sent out if there is a letter template associated with the message. Test Plan: 1) Apply this patch 2) Restart all the things! 3) Enable SendLetterIdInEmailNotices 4) Generate an email notice like a checkout notice 5) Note your email has the letter id at the bottom! --- C4/Letters.pm | 4 +++- installer/data/mysql/atomicupdate/bug_31627.pl | 14 ++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/patrons.pref | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_31627.pl diff --git a/C4/Letters.pm b/C4/Letters.pm index 42edb9c1e0..3f3804b43f 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1246,7 +1246,7 @@ sub _get_unsent_messages { my $dbh = C4::Context->dbh(); my $statement = qq{ - SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.reply_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code, mq.failure_code + SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.reply_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code, mq.failure_code, mq.letter_id FROM message_queue mq LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber WHERE status = ? @@ -1378,8 +1378,10 @@ sub _send_message_by_email { } else { $email = Koha::Email->create($params); if ($is_html) { + $content .= "
$message->{letter_id}" if $message->{id} && C4::Context->preference('SendLetterIdNotices'); $email->html_body( _wrap_html( $content, $subject ) ); } else { + $content .= "\n$message->{letter_id}" if $message->{id} && C4::Context->preference('SendLetterIdNotices'); $email->text_body($content); } } diff --git a/installer/data/mysql/atomicupdate/bug_31627.pl b/installer/data/mysql/atomicupdate/bug_31627.pl new file mode 100755 index 0000000000..52c5621dd8 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_31627.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "31627", + description => "Add syspref SendLetterIdInEmailNotices", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('SendLetterIdInEmailNotices','0',NULL,'Add template id to bottom of emailed notices','YesNo') + }); + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index db99d68f81..1d06d34ce9 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -640,6 +640,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'), ('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'), ('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free'), +('SendLetterIdInEmailNotices','0',NULL,'Add template id to bottom of emailed notices','YesNo'), ('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'), ('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'), ('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 15d3ccb74b..f8b1aafd4d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -160,6 +160,12 @@ Patrons: 0: "Don't send" - an email to newly created patrons. - '
NOTE: This uses the WELCOME notice.' + - + - pref: SendLetterIdInEmailNotices + choices: + 1: Add + 0: "Don't add" + - the template id for a notice to the bottom of any emailed notices. - - pref: UseEmailReceipts choices: -- 2.30.2