From 479b0704eca4993142cca758759b9a6ca30aca84 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Mon, 28 Jun 2021 11:38:00 +0100 Subject: [PATCH] Bug 28634: Fix notice borrowernumber This commit fixes the bug described in this bug. - When a partner is selected, pass their borrowernumber rather than email to the receiving script - Iterate all selected partners, send a notice to each, using the recipient's borrowernumber in the notice, the recipient's email is derived from their patron object TEST PLAN: 1. DO NOT apply the patch. 2. Follow the following setup: *** Setup start *** - Create a report using the following SQL in order to verify that notices are being generated: SELECT borrowernumber, subject, content, message_transport_type, to_address, from_address FROM message_queue WHERE letter_code LIKE 'ILL%' ORDER BY message_id DESC - Create two "partners". These are patrons that belong to a patron category that has a code that matches the value in your koha-conf.xml (default is ILLLIBS). Patrons in this category must have a primary email defined. Patrons defined in this way are offered as request partners within the ILL interface. - Go to "Koha administration", search for "ILLModule" syspref, ensure it is set to "Enable" - Go to "Koha administration", search for "IllLog" syspref, ensure it is set to "Log" BRANCH CONFIG - Go to "Koha administration" > "Libraries" - Choose a library and "Edit" it - Ensure the "Email" field for the library is populated SENDING REQUEST TO PARTNERS - Go to the "Manage ILL request" screen for a request, create a request if one does not exist - Choose "Place request with partners" - Select both partners that were defined earlier, then click "Send email" - Run the report created earlier => TEST: Observe that a notice was created and the borrowernumber is that of the request creator, not the recipient *** Setup end *** 3. Apply the patch a. Go to the "Manage ILL request" screen for a request, create a request if one does not exist b. Choose "Place request with partners" c. Select both partners that were defined earlier, then click "Send email" d. Run the report created earlier => TEST: Observe that once notice per partner is created, the borrowernumber column for each notice contains the borrower number of the recipient, not the request creator Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- Koha/Illrequest.pm | 46 +++++++++++++------ .../prog/en/modules/ill/ill-requests.tt | 2 +- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 4f50a425df..d667f9764a 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -1346,11 +1346,17 @@ sub generic_confirm { my $to = $params->{partners}; if ( defined $to ) { $to =~ s/^\x00//; # Strip leading NULLs - $to =~ s/\x00/; /; # Replace others with '; ' } Koha::Exceptions::Ill::NoTargetEmail->throw( "No target email addresses found. Either select at least one partner or check your ILL partner library records.") if ( !$to ); + + # Take the null delimited string that we receive and create + # an array of associated patron objects + my @to_patrons = map { + Koha::Patrons->find({ borrowernumber => $_ }) + } split(/\x00/, $to); + # Create the from, replyto and sender headers my $from = $branch->from_email_address; my $replyto = $branch->inbound_ill_address; @@ -1367,25 +1373,36 @@ sub generic_confirm { $letter->{title} = $params->{subject}; $letter->{content} = $params->{body}; - # Queue the notice - my $params = { - letter => $letter, - borrowernumber => $self->borrowernumber, - message_transport_type => 'email', - to_address => $to, - from_address => $from, - reply_address => $replyto - }; - if ($letter) { - my $result = C4::Letters::EnqueueLetter($params); - if ( $result ) { + + # Keep track of who received this notice + my @queued = (); + # Iterate our array of recipient patron objects + foreach my $patron(@to_patrons) { + # Create the params we pass to the notice + my $params = { + letter => $letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'email', + to_address => $patron->email, + from_address => $from, + reply_address => $replyto + }; + my $result = C4::Letters::EnqueueLetter($params); + if ( $result ) { + push @queued, $patron->email; + } + } + + # If all notices were queued successfully, + # store that + if (scalar @queued == scalar @to_patrons) { $self->status("GENREQ")->store; $self->_backend_capability( 'set_requested_partners', { request => $self, - to => $to + to => join("; ", @queued) } ); return { @@ -1397,6 +1414,7 @@ sub generic_confirm { next => 'illview', }; } + } return { error => 1, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt index c27fe0e1a4..0cc91c19ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -323,7 +323,7 @@