From 0a445289210878d02a4b3a3901c526ee4c086096 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 4d60753cc6..037f63a497 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1249,7 +1249,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 = ? @@ -1385,8 +1385,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('SendLetterIdInEmailNotices'); $email->html_body( _wrap_html( $content, $subject ) ); } else { + $content .= "\n$message->{letter_id}" if $message->{id} && C4::Context->preference('SendLetterIdInEmailNotices'); $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 c1ff4a2f38..06efa54b1c 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -645,6 +645,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 0edf57f6d9..4190ebe33b 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 @@ -166,6 +166,12 @@ Patrons: 1: Notify 0: "Don't notify" - patrons whenever their password is changed. + - + - 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