From 704a256160f2ed177dcc2f3f2780c0210bcac830 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Aug 2022 17:06:39 +0100 Subject: [PATCH] Bug 31028: Add notice trigger for catalog concerns This patch adds a new system prefernce, `CatalogerEmails`. If set with a valid email address adding a new catalog concern should produce a notification email sent to that address. --- C4/Letters.pm | 9 +++- Koha/Catalog/Concern.pm | 47 ++++++++++++++++++- .../data/mysql/atomicupdate/bug_31028.pl | 15 ++++++ .../mysql/en/mandatory/sample_notices.yml | 16 +++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/cataloguing.pref | 6 +++ 6 files changed, 91 insertions(+), 3 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 7c136f32f9..69c4a46e19 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -737,6 +737,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 'catalog_concerns' ) ? "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 = ?" : @@ -1608,7 +1609,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; @@ -1644,6 +1645,12 @@ sub _get_tt_params { plural => 'biblios', pk => 'biblionumber', }, + catalog_concerns => { + module => 'Koha::Catalog::Concerns', + singular => 'catalog_concern', + plural => 'catalog_concerns', + pk => 'id', + }, biblioitems => { module => 'Koha::Biblioitems', singular => 'biblioitem', diff --git a/Koha/Catalog/Concern.pm b/Koha/Catalog/Concern.pm index a4ab05615e..8c2f75767b 100644 --- a/Koha/Catalog/Concern.pm +++ b/Koha/Catalog/Concern.pm @@ -17,16 +17,17 @@ package Koha::Catalog::Concern; use Modern::Perl; - use base qw(Koha::Object); +use C4::Letters; + =head1 NAME Koha::Catalog::Concern - Koha Catalog::Concern Object class =head1 API -=head2 Class methods +=head2 Relations =cut @@ -69,6 +70,8 @@ sub biblio { return Koha::Biblio->_new_from_dbic( $rs ); } +=head2 Actions + =head3 resolve $concern = $concern->resolve( @@ -105,6 +108,46 @@ sub resolve { return $self; } +=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 && C4::Context->preference('CatalogerEmails') ) { + + # notify the library if a notice exists + my $letter = C4::Letters::GetPreparedLetter( + module => 'catalog', + letter_code => 'CONCERN_NOTIFY', + branchcode => $self->reporter->branchcode, + tables => { catalog_concerns => $self->id } + ); + + if ($letter) { + my $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + message_transport_type => 'email', + to_address => C4::Preference('CatalogerEmails'), + reply_address => $self->reporter->notice_email_address, + } + ); + C4::Letters::SendQueuedMessages( { message_id => $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 276d14835a..f2f80b501e 100644 --- a/installer/data/mysql/atomicupdate/bug_31028.pl +++ b/installer/data/mysql/atomicupdate/bug_31028.pl @@ -40,5 +40,20 @@ return { ('OpacCatalogConcerns', '0', NULL, 'Allow logged in OPAC users to report catalog concerns', 'YesNo') } ); + + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('CatalogerEmails', '', '', 'Notify these catalogers by email when a catalog concern is submitted', 'free') + } + ); + + $dbh->do( + q{ + INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type) + VALUES ( 'catalog', 'CONCERN_NOTIFY', '', 'Catalog concern notification', '1', 'Catalog concern reported', "Dear cataloger,\r\n\r\n[% INCLUDE 'patron-title.inc' patron => catalog_concern.reporter %] reported the following concern with [% INCLUDE 'biblio-title.inc' biblio=catalog_concern.biblio link = 1 %]\r\n\r\n\r\n\r\n[% catalog_concern.message %]\r\n\r\n\r\n\r\nYou can mark this concern as resolved from the concern management page.", 'email' ); + } + ); + }, } diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml index 95852015f5..8a52bce7ba 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ b/installer/data/mysql/en/mandatory/sample_notices.yml @@ -43,6 +43,22 @@ tables: - "" - "Your library." + - module: catalog + code: CONCERN_NOTIFY + branchcode: "" + name: "Concern notification" + is_html: 1 + title: "Catalog concern reported" + message_transport_type: email + lang: default + content: + - "Dear cataloger," + - "[% INCLUDE 'patron-title.inc' patron => catalog_concern.reporter %] reported the following concern with [% INCLUDE 'biblio-title.inc' biblio=catalog_concern.biblio link = 1 %]" + - "" + - "[% catalog_concern.message %]" + - "" + - "You can mark this concern as resolved from the concern management page." + - module: circulation code: ACCOUNT_CREDIT branchcode: "" diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 93a6d89923..c9c56f2b8a 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -128,6 +128,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('casServerUrl','https://localhost:8443/cas','','URL of the cas server','Free'), ('casServerVersion','2', '2|3','Version of the CAS server Koha will connect to.','Choice'), ('CatalogConcerns', '0', NULL, 'Allow users to report catalog concerns', 'YesNo'), +('CatalogerEmails', '', '', 'Notify these catalogers by email when a catalog concern is submitted', 'free'), ('CatalogModuleRelink','0',NULL,'If OFF the linker will never replace the authids that are set in the cataloging module.','YesNo'), ('CataloguingLog','1',NULL,'If ON, log edit/create/delete actions on bibliographic data. WARNING: this feature is very resource consuming.','YesNo'), ('ChargeFinesOnClosedDays','0',NULL,'Charge fines on days the library is closed.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index bda3fca9c5..f5f253aec2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -50,6 +50,12 @@ Cataloging: 1: Allow - "staff to report concerns about catalog records." - 'Note: You can also enable `OpacCatalogConcerns` to allow OPAC users the same option.' + - + - "Use " + - pref: CatalogerEmails + default: '' + class: email + - " as the notification address for catalog concerns." Spine labels: - -- 2.20.1