Bugzilla – Attachment 29441 Details for
Bug 12518
gather_print_notices.pl doesn't respect hold/reserve pickup location
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Initial commit from our issue tracker.
KD-150-Gather_print_notices_respect_hold_pickup_library.patch (text/plain), 5.77 KB, created by
Olli-Antti Kivilahti
on 2014-07-02 13:49:48 UTC
(
hide
)
Description:
Initial commit from our issue tracker.
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2014-07-02 13:49:48 UTC
Size:
5.77 KB
patch
obsolete
>From ec2f772cfe3fcf82f1fd4b5a3a1e91799fa6de90 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Wed, 2 Jul 2014 15:19:12 +0300 >Subject: [PATCH] KD-150 - Gather print notices respect hold pickup library > >gather_print_notices.pl gathers HOLD-letters based on the borrowers' homebranch. >Our librarians find it hard to send hold notices for Items present in other branches. > >This patch gathers print notices for HOLD-letter_code to the Items' reserves.branchcode (pickup location) instead. > >This is achieved by using a customizable regexp in the gather_print_notices-script, which picks the barcode from the letter content. > >--------------- >-- TEST PLAN -- >--------------- >0. Have a HOLD-letter template with each Items' barcodes somewhere, for ex. > Barcode: <<items.barcode>> >1. Create a reservation for a borrower with no other message delivery option than printing. Set the pickup location to other (branch P) than the borrowers homebranch (branch H). >2. Check the item in and confirm reservation. This enques a letter in the message_queue-table. >3. run the gather_print_notices.pl -cronjobs with the following parameters > gather_print_notices.pl <your_notices_directory> --split --holdbarcode 'Barcode: (\S+)<br />' >You will find the letter generated to the branch P, instead of the branch H if you hadn't used the --holdbarcode -parameter. >--- > C4/Letters.pm | 2 +- > misc/cronjobs/gather_print_notices.pl | 45 +++++++++++++++++++++++++++++++++-- > 2 files changed, 44 insertions(+), 3 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 5025c10..f8bed84 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -893,7 +893,7 @@ sub _get_unsent_messages { > > my $dbh = C4::Context->dbh(); > my $statement = << 'ENDSQL'; >-SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode >+SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, mq.letter_code, b.branchcode > FROM message_queue mq > LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber > WHERE status = ? >diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl >index 248716e..999fc14 100755 >--- a/misc/cronjobs/gather_print_notices.pl >+++ b/misc/cronjobs/gather_print_notices.pl >@@ -34,6 +34,8 @@ use C4::Dates; > use C4::Debug; > use C4::Letters; > use C4::Templates; >+use C4::Items; >+use C4::Reserves; > use File::Spec; > use Getopt::Long; > >@@ -44,15 +46,22 @@ Usage: $0 OUTPUT_DIRECTORY > OUTPUT_DIRECTORY/notices-CURRENT_DATE.html . > > -s --split Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html >+ >+ --holdbarcode If you want to separate HOLD-letters based on the reserve's pickup branch instead of the borrowers homebranch >+ Define this regexp to find the Item barcodes from the HOLD-letters. Items need to be found so the reservation >+ information can be found. Regexp could be like 'Item: (\\S+)<br />' or 'Barcode (\\S+)<br />'. Remember that >+ these letters are htmlized, so lines end/start with <br />! You must define a capture group between >+ parenthesis () to catch the barcode. > USAGE > exit $_[0]; > } > >-my ( $stylesheet, $help, $split ); >+my ( $stylesheet, $help, $split, $HOLDbarcodeParsingRegexp ); > > GetOptions( > 'h|help' => \$help, > 's|split' => \$split, >+ 'holdbarcode=s' => \$HOLDbarcodeParsingRegexp, > ) || usage(1); > > usage(0) if ($help); >@@ -80,9 +89,18 @@ foreach my $message (@all_messages) { > my $OUTPUT; > > if ($split) { >+ > my %messages_by_branch; > foreach my $message (@all_messages) { >- push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message ); >+ my $defaultBranch = $message->{'branchcode'}; >+ >+ #Catch HOLD print letters so we can direct them to branches which actually have the items waiting for pickup. >+ if (defined $HOLDbarcodeParsingRegexp && $message->{letter_code} eq 'HOLD') { >+ fetchPickupLocations( $defaultBranch, $message, \%messages_by_branch ); >+ } >+ else { >+ push( @{ $messages_by_branch{ $defaultBranch } }, $message ); >+ } > } > > foreach my $branchcode ( keys %messages_by_branch ) { >@@ -139,3 +157,26 @@ else { > close $OUTPUT; > > } >+ >+#Finds the barcodes using a regexp and then gets the reservations attached to them. >+#Sends the same letter to the branches from which there are Items' pickup locations inside this one letter. >+sub fetchPickupLocations { >+ my ($defaultBranch, $message, $messages_by_branch) = @_; >+ #Find out the barcodes >+ my @barcodes = $message->{content} =~ /$HOLDbarcodeParsingRegexp/mg; >+ my %targetBranches; #The same letter can have Items from multiple pickup locations so we need to send this letter to each separate pickup branch. >+ foreach my $barcode (@barcodes) { >+ my $itemnumber = C4::Items::GetItemnumberFromBarcode( $barcode ); >+ my ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $waitingdate ) = GetReservesFromItemnumber($itemnumber); >+ $targetBranches{ $branchcode } = 1 if $branchcode; #Set the branches which receives this print notification. >+ } >+ >+ if (%targetBranches) { #Send the same message to each branch from which there are pickup locations. >+ foreach my $branchcode (keys %targetBranches) { >+ push( @{ $messages_by_branch->{ $branchcode } }, $message ); >+ } >+ } >+ else { #Or default to the default! >+ push( @{ $messages_by_branch->{ $defaultBranch } }, $message ); >+ } >+} >\ No newline at end of file >-- >1.8.1.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12518
: 29441