From bf28d6b1c81bb9b5f38b268a236cd66f25679352 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 25 Oct 2022 13:50:58 +0100 Subject: [PATCH] Bug 31028: Add acknowledgement notice This patch adds an acknowledgement notice that will be sent to the opac user upon submission of a catalog concern report. Test plan 1) Confirm that a new notice template is added to the notices management page. 2) If using a sandbox, check the 'email log' from the management UI to see the resultant notice has been 'sent' Signed-off-by: David Nind Signed-off-by: Helen Oliver Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Letters.pm | 9 +++- Koha/Ticket.pm | 42 +++++++++++++++++++ .../data/mysql/atomicupdate/bug_31028.pl | 8 ++++ .../mysql/en/mandatory/sample_notices.yml | 18 ++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 3a58c7edcb..39818f4509 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -738,6 +738,7 @@ sub _parseletter_sth { ($table eq 'accountlines' ) ? "SELECT * FROM $table WHERE accountlines_id = ?" : ($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : ($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : + ($table eq 'tickets' ) ? "SELECT * FROM $table WHERE id = ?" : ($table eq 'credits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" : ($table eq 'debits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" : ($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : @@ -1619,7 +1620,7 @@ sub _process_tt { my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects }; $content = add_tt_filters( $content ); - $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|; + $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %][% PROCESS 'html_helpers.inc' %]$content|; my $output; my $schema = Koha::Database->new->schema; @@ -1738,6 +1739,12 @@ sub _get_tt_params { plural => 'suggestions', pk => 'suggestionid', }, + tickets => { + module => 'Koha::Tickets', + singular => 'ticket', + plural => 'tickets', + pk => 'id', + }, issues => { module => 'Koha::Checkouts', singular => 'checkout', diff --git a/Koha/Ticket.pm b/Koha/Ticket.pm index 55d177da2c..711bcd9e12 100644 --- a/Koha/Ticket.pm +++ b/Koha/Ticket.pm @@ -19,6 +19,8 @@ use Modern::Perl; use base qw(Koha::Object); +use C4::Letters; + use Koha::Ticket::Update; use Koha::Ticket::Updates; @@ -97,6 +99,46 @@ sub add_update { return Koha::Ticket::Update->_new_from_dbic($rs); } +=head2 Core methods + +=head3 store + +Overloaded I method to trigger notices as required + +=cut + +sub store { + my ($self) = @_; + + my $is_new = !$self->in_storage; + $self = $self->SUPER::store; + + if ($is_new) { + + # Send patron acknowledgement + my $acknowledgement_letter = C4::Letters::GetPreparedLetter( + module => 'catalog', + letter_code => 'TICKET_ACKNOWLEDGEMENT', + branchcode => $self->reporter->branchcode, + tables => { tickets => $self->id } + ); + + if ($acknowledgement_letter) { + my $acknowledgement_message_id = C4::Letters::EnqueueLetter( + { + letter => $acknowledgement_letter, + message_transport_type => 'email', + borrowernumber => $self->reporter_id, + } + ); + C4::Letters::SendQueuedMessages( + { message_id => $acknowledgement_message_id } ); + } + } + + return $self; +} + =head2 Internal methods =cut diff --git a/installer/data/mysql/atomicupdate/bug_31028.pl b/installer/data/mysql/atomicupdate/bug_31028.pl index 459eaeb99f..683c92003c 100644 --- a/installer/data/mysql/atomicupdate/bug_31028.pl +++ b/installer/data/mysql/atomicupdate/bug_31028.pl @@ -85,5 +85,13 @@ return { ); say $out "`CatalogConcernTemplate` block added to html_customization"; } + + $dbh->do( + q{ + INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type) + VALUES ( 'catalog', 'TICKET_ACKNOWLEDGEMENT', '', 'Concern acknowledgement', '1', 'Catalog concern acknowledgement', "Dear [% INCLUDE 'patron-title.inc' patron => ticket.reporter %],\r\n\r\nThankyou for your report concerning [% INCLUDE 'biblio-title.inc' biblio=ticket.biblio link = 0 %].\r\n\r\nYou reported: \r\n[% ticket.body %]\r\n\r\nThankyou", 'email' ); + } + ); + say $out "Added new notice 'TICKET_ACKNOWLEDGEMENT'"; } } diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml index 230338b12c..f5478f9a88 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ b/installer/data/mysql/en/mandatory/sample_notices.yml @@ -43,6 +43,24 @@ tables: - "" - "Your library." + - module: catalog + code: TICKET_ACKNOWLEDGEMENT + branchcode: "" + name: "Concern acknowledgement" + is_html: 1 + title: "Catalog concern acknowledgment" + message_transport_type: email + lang: default + content: + - "Dear [% INCLUDE 'patron-title.inc' patron => ticket.reporter %]," + - "" + - "Thankyou for your report concerning [% INCLUDE 'biblio-title.inc' biblio=ticket.biblio link = 0 %]." + - "" + - "You reported: " + - "[% ticket.body %]" + - "" + - "Thankyou" + - module: circulation code: ACCOUNT_CREDIT branchcode: "" -- 2.39.5