Bugzilla – Attachment 170366 Details for
Bug 10190
Overdue notice triggers based on item type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10190: Update overdue_notices script to refer to circ rules
Bug-10190-Update-overduenotices-script-to-refer-to.patch (text/plain), 11.00 KB, created by
Martin Renvoize (ashimema)
on 2024-08-15 11:36:58 UTC
(
hide
)
Description:
Bug 10190: Update overdue_notices script to refer to circ rules
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-08-15 11:36:58 UTC
Size:
11.00 KB
patch
obsolete
>From 51e215c0a1c1b6c7cc9f9b1cd0324be81b3b5a4b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 8 Aug 2024 11:44:35 +0100 >Subject: [PATCH] Bug 10190: Update overdue_notices script to refer to circ > rules > >This patch updates the overdue_notices cron script to refer to the new >location for overdue rules found in the circulation rules table now. > >Sponsored-by: Glasgow Colleges Library Group >--- > misc/cronjobs/overdue_notices.pl | 111 +++++++++++++++++-------------- > 1 file changed, 60 insertions(+), 51 deletions(-) > >diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl >index 6f78b2838a1..2d7f5dd3ccd 100755 >--- a/misc/cronjobs/overdue_notices.pl >+++ b/misc/cronjobs/overdue_notices.pl >@@ -29,7 +29,7 @@ use DateTime::Duration; > use Koha::Script -cron; > use C4::Context; > use C4::Letters; >-use C4::Overdues qw( GetOverdueMessageTransportTypes parse_overdues_letter ); >+use C4::Overdues qw( parse_overdues_letter ); > use C4::Log qw( cronlogaction ); > use Koha::Patron::Debarments qw( AddUniqueDebarment ); > use Koha::DateUtils qw( dt_from_string output_pref ); >@@ -488,43 +488,52 @@ END_SQL > } > my $sth2 = $dbh->prepare($sql2); > >- my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? "; >- $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat); >- $query .= " AND categorycode NOT IN (".join( ',' , ('?') x @myborcatout ).") " if (@myborcatout); >- >- my $rqoverduerules = $dbh->prepare($query); >- $rqoverduerules->execute($branchcode, @myborcat, @myborcatout); >- >- # We get default rules if there is no rule for this branch >- if($rqoverduerules->rows == 0){ >- $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' "; >- $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat); >- $query .= " AND categorycode NOT IN (".join( ',' , ('?') x @myborcatout ).") " if (@myborcatout); >- >- $rqoverduerules = $dbh->prepare($query); >- $rqoverduerules->execute(@myborcat, @myborcatout); >+ my @categories; >+ if (@myborcat) { >+ @categories = @myborcat; >+ } elsif (@myborcatout) { >+ @categories = Koha::Patron::Categories->search( { catagorycode => { 'not_in' => \@myborcatout } } ) >+ ->get_column('categorycode'); >+ } else { >+ @categories = Koha::Patron::Categories->search()->get_column('categorycode'); > } > >- # my $outfile = 'overdues_' . ( $mybranch || $branchcode || 'default' ); >- while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) { >- PERIOD: foreach my $i ( 1 .. 3 ) { >+ for my $category (@categories) { >+ my $i = 0; >+ PERIOD: while (1) { >+ $i++; >+ my $j = $i + 1; >+ my $overdue_rules = Koha::CirculationRules->get_effective_rules( >+ { >+ rules => [ >+ "overdue_$i" . '_delay', "overdue_$i" . '_notice', "overdue_$i" . '_mtt', >+ "overdue_$i" . '_restrict', "overdue_$j" . '_delay' >+ ], >+ categorycode => $category, >+ branchcode => $branchcode >+ } >+ ); >+ $verbose and warn "branch '$branchcode', categorycode = $category pass $i\n"; > >- $verbose and warn "branch '$branchcode', categorycode = $overdue_rules->{categorycode} pass $i\n"; >+ if (!$overdue_rules->{"overdue_$i".'_delay'}) { >+ last PERIOD; >+ } > >- my $mindays = $overdue_rules->{"delay$i"}; # the notice will be sent after mindays days (grace period) >+ my $mindays = >+ $overdue_rules->{ "overdue_$i" . '_delay' }; # the notice will be sent after mindays days (grace period) > my $maxdays = ( >- $overdue_rules->{ "delay" . ( $i + 1 ) } >- ? $overdue_rules->{ "delay" . ( $i + 1 ) } - 1 >+ $overdue_rules->{ "overdue_$j" . '_delay' } >+ ? $overdue_rules->{ "overdue_$j" . '_delay' } - 1 > : ($MAX) >- ); # issues being more than maxdays late are managed somewhere else. (borrower probably suspended) >+ ); # issues being more than maxdays late are managed somewhere else. (borrower probably suspended) > > next unless defined $mindays; > >- if ( !$overdue_rules->{"letter$i"} ) { >+ if ( !$overdue_rules->{"overdue_$i".'_notice'} ) { > $verbose and warn sprintf "No letter code found for pass %s\n", $i; > next PERIOD; > } >- $verbose and warn sprintf "Using letter code '%s' for pass %s\n", $overdue_rules->{"letter$i"}, $i; >+ $verbose and warn sprintf "Using letter code '%s' for pass %s\n", $overdue_rules->{"overdue_$i".'_notice'}, $i; > > # $letter->{'content'} is the text of the mail that is sent. > # this text contains fields that are replaced by their value. Those fields must be written between brackets >@@ -550,9 +559,9 @@ END_SQL > } > push @borrower_parameters, $branchcode; > } >- if ( $overdue_rules->{categorycode} ) { >+ if ( $category ) { > $borrower_sql .= ' AND borrowers.categorycode=? '; >- push @borrower_parameters, $overdue_rules->{categorycode}; >+ push @borrower_parameters, $category; > } > $borrower_sql .= ' AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber'; > >@@ -562,7 +571,7 @@ END_SQL > > if ( $verbose > 1 ){ > warn sprintf "--------Borrower SQL------\n"; >- warn $borrower_sql . "\n $branchcode | " . $overdue_rules->{'categorycode'} . "\n ($mindays, $maxdays, ". $date_to_run->datetime() .")\n"; >+ warn $borrower_sql . "\n $branchcode | " . $category . "\n ($mindays, $maxdays, ". $date_to_run->datetime() .")\n"; > warn sprintf "--------------------------\n"; > } > $verbose and warn sprintf "Found %s borrowers with overdues\n", $sth->rows; >@@ -632,21 +641,21 @@ END_SQL > my $letter = Koha::Notice::Templates->find_effective_template( > { > module => 'circulation', >- code => $overdue_rules->{"letter$i"}, >+ code => $overdue_rules->{"overdue_$i".'_notice'}, > branchcode => $branchcode, > lang => $patron->lang > } > ); > > unless ($letter) { >- $verbose and warn qq|Message '$overdue_rules->{"letter$i"}' content not found|; >+ $verbose and warn qq|Message '$overdue_rules->{"overdue_$i"."_notice"}' content not found|; > > # might as well skip while PERIOD, no other borrowers are going to work. > # FIXME : Does this mean a letter must be defined in order to trigger a debar ? > next PERIOD; > } > >- if ( $overdue_rules->{"debarred$i"} ) { >+ if ( $overdue_rules->{"overdue_$i".'_restrict'} ) { > > #action taken is debarring > AddUniqueDebarment( >@@ -712,10 +721,7 @@ END_SQL > } > $sth2->finish; > >- my @message_transport_types = @{ GetOverdueMessageTransportTypes( $branchcode, $overdue_rules->{categorycode}, $i) }; >- @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) } >- unless @message_transport_types; >- >+ my @message_transport_types = split( /,/, $overdue_rules->{ "overdue_$i" . '_mtt' } ); > > my $print_sent = 0; # A print notice is not yet sent for this patron > for my $mtt ( @message_transport_types ) { >@@ -730,31 +736,34 @@ END_SQL > > my $letter_exists = Koha::Notice::Templates->find_effective_template( > { >- module => 'circulation', >- code => $overdue_rules->{"letter$i"}, >+ module => 'circulation', >+ code => $overdue_rules->{ "overdue_$i" . '_notice' }, > message_transport_type => $effective_mtt, >- branchcode => $branchcode, >- lang => $patron->lang >+ branchcode => $branchcode, >+ lang => $patron->lang > } > ); > > my $letter = parse_overdues_letter( >- { letter_code => $overdue_rules->{"letter$i"}, >- borrowernumber => $borrowernumber, >- branchcode => $branchcode, >- items => \@items, >- substitute => { # this appears to be a hack to overcome incomplete features in this code. >- bib => $library->branchname, # maybe 'bib' is a typo for 'lib<rary>'? >- 'items.content' => $titles, >- 'count' => $itemcount, >- }, >+ { >+ letter_code => $overdue_rules->{ "overdue_$i" . '_notice' }, >+ borrowernumber => $borrowernumber, >+ branchcode => $branchcode, >+ items => \@items, >+ substitute => { # this appears to be a hack to overcome incomplete features in this code. >+ bib => $library->branchname, # maybe 'bib' is a typo for 'lib<rary>'? >+ 'items.content' => $titles, >+ 'count' => $itemcount, >+ }, >+ > # If there is no template defined for the requested letter > # Fallback on the original type > message_transport_type => $letter_exists ? $effective_mtt : $mtt, > } > ); >- unless ($letter && $letter->{content}) { >- $verbose and warn qq|Message '$overdue_rules->{"letter$i"}' content not found|; >+ unless ( $letter && $letter->{content} ) { >+ $verbose and warn qq|Message '$overdue_rules->{"overdue_$i"."_notice"}' content not found|; >+ > # this transport doesn't have a configured notice, so try another > next; > } >-- >2.46.0
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 10190
:
170357
|
170358
|
170359
|
170360
|
170361
|
170362
|
170363
|
170364
|
170365
|
170366
|
170367
|
170368
|
170369
|
170370
|
170371
|
170372
|
170373
|
170374
|
170375
|
170376
|
170380
|
170449
|
171727
|
171728
|
171729
|
171730
|
171731
|
171732
|
171733
|
171734
|
171735
|
171736
|
171737
|
171738
|
171739
|
171740
|
171741
|
171742
|
171743
|
171744
|
171745
|
171746
|
171747
|
171748
|
171749
|
171750
|
171751
|
171752
|
171753
|
171754
|
171755
|
172588
|
172589
|
172590
|
172591
|
172592
|
172593
|
172594
|
172595
|
172596
|
172597
|
172598
|
172599
|
172600
|
172601
|
172602
|
172603
|
172604
|
172605
|
172606
|
172607
|
172608
|
172609
|
172612
|
172614
|
172617
|
172619
|
172621
|
172622
|
172623
|
172624
|
172625
|
172626
|
172630
|
172631
|
172632
|
172633
|
172634
|
172635
|
172636
|
172637
|
172638
|
172639
|
172640
|
172641
|
172642
|
172643
|
172644
|
172645
|
172646
|
172647
|
172648
|
172649
|
172650
|
172651
|
172652
|
172653
|
172654
|
172655
|
172656
|
172657
|
172658
|
172659
|
172660
|
172661
|
172662
|
172663