Bug 17698: Do not send pending_checkout_notes from all circ scripts
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 13 Jun 2018 13:52:33 +0000 (10:52 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 23 Jul 2018 15:23:44 +0000 (15:23 +0000)
It's safer to send what we need from C4::Auth it's needed from a whole
module.
The SELECT COUNT(*) query will only be done when needed (so not made
from scripts outside of circ)

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

15 files changed:
C4/Auth.pm
circ/branchoverdues.pl
circ/branchtransfers.pl
circ/checkout-notes.pl
circ/circulation.pl
circ/on-site_checkouts.pl
circ/renew.pl
circ/returns.pl
circ/selectbranchprinter.pl
circ/transferstoreceive.pl
circ/view_holdsqueue.pl
circ/waitingreserves.pl
koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc
koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt
mainpage.pl

index 2731ff2..e27b1b3 100644 (file)
@@ -32,6 +32,7 @@ use C4::Search::History;
 use Koha;
 use Koha::Caches;
 use Koha::AuthUtils qw(get_script_name hash_password);
+use Koha::Checkouts;
 use Koha::DateUtils qw(dt_from_string);
 use Koha::Library::Groups;
 use Koha::Libraries;
@@ -498,7 +499,8 @@ sub get_template_and_user {
             EnableBorrowerFiles                                                        => C4::Context->preference('EnableBorrowerFiles'),
             UseKohaPlugins                                                             => C4::Context->preference('UseKohaPlugins'),
             UseCourseReserves                                                          => C4::Context->preference("UseCourseReserves"),
-            useDischarge                                                               => C4::Context->preference('useDischarge')
+            useDischarge                                                               => C4::Context->preference('useDischarge'),
+            pending_checkout_notes                                                     => scalar Koha::Checkouts->search({ noteseen => 0 }),
         );
     }
     else {
index ed4b855..d4c20cb 100755 (executable)
@@ -27,7 +27,6 @@ use C4::Koha;
 use C4::Debug;
 use Koha::DateUtils;
 use Koha::BiblioFrameworks;
-use Koha::Checkouts;
 use Data::Dumper;
 
 =head1 branchoverdues.pl
@@ -99,13 +98,10 @@ foreach my $num (@getoverdues) {
     push( @overduesloop, \%overdueforbranch );
 }
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
 # initiate the templates for the overdueloop
 $template->param(
     overduesloop => \@overduesloop,
     location     => $location,
-    pending_checkout_notes => $pending_checkout_notes,
 );
 
 # Checking if there is a Fast Cataloging Framework
index 7de588c..3e15cdf 100755 (executable)
@@ -35,7 +35,6 @@ use Koha::AuthorisedValues;
 use Koha::Holds;
 use Koha::Items;
 use Koha::Patrons;
-use Koha::Checkouts;
 
 ###############################################
 #  Getting state
@@ -222,8 +221,6 @@ foreach my $code ( keys %$messages ) {
 # use Data::Dumper;
 # warn "FINAL ============= ".Dumper(@trsfitemloop);
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
 $template->param(
     found                   => $found,
     reserved                => $reserved,
@@ -239,7 +236,6 @@ $template->param(
     trsfitemloop            => \@trsfitemloop,
     errmsgloop              => \@errmsgloop,
     CircAutocompl           => C4::Context->preference("CircAutocompl"),
-    pending_checkout_notes  => $pending_checkout_notes,
 );
 
 # Checking if there is a Fast Cataloging Framework
index 5bad39a..97fb925 100755 (executable)
@@ -37,12 +37,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
-$template->param(
-    pending_checkout_notes => $pending_checkout_notes,
-);
-
 my $action;
 foreach (qw( seen notseen )) {
     $action = $_ if ( $query->param("mark_selected-$_") );
index e0de5d0..1617584 100755 (executable)
@@ -56,7 +56,6 @@ use Koha::Patron::Messages;
 use Koha::SearchEngine;
 use Koha::SearchEngine::Search;
 use Koha::Patron::Modifications;
-use Koha::Checkouts;
 
 use Date::Calc qw(
   Today
@@ -146,9 +145,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
 );
 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-$template->param( pending_checkout_notes => $pending_checkout_notes );
-
 my $force_allow_issue = $query->param('forceallow') || 0;
 if (!C4::Auth::haspermission( C4::Context->userenv->{id} , { circulate => 'force_checkout' } )) {
     $force_allow_issue = 0;
index 05eef2c..96cea5a 100755 (executable)
@@ -23,7 +23,6 @@ use C4::Circulation qw( GetPendingOnSiteCheckouts );
 use C4::Output;
 use C4::Koha;
 use Koha::BiblioFrameworks;
-use Koha::Checkouts;
 
 my $cgi = new CGI;
 
@@ -40,12 +39,10 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
 # Checking if there is a Fast Cataloging Framework
 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
 my $pending_onsite_checkouts = C4::Circulation::GetPendingOnSiteCheckouts();
 
 $template->param(
     pending_onsite_checkouts => $pending_onsite_checkouts,
-    pending_checkout_notes   => $pending_checkout_notes,
 );
 
 output_html_with_http_headers $cgi, $cookie, $template->output;
index 01c37cd..246c266 100755 (executable)
@@ -28,7 +28,6 @@ use C4::Koha;
 use Koha::DateUtils;
 use Koha::Database;
 use Koha::BiblioFrameworks;
-use Koha::Checkouts;
 
 my $cgi = new CGI;
 
@@ -122,7 +121,4 @@ if ($barcode) {
 # Checking if there is a Fast Cataloging Framework
 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-$template->param( pending_checkout_notes => $pending_checkout_notes );
-
 output_html_with_http_headers( $cgi, $cookie, $template->output );
index 103d290..a82bdc1 100755 (executable)
@@ -52,7 +52,6 @@ use Koha::BiblioFrameworks;
 use Koha::Holds;
 use Koha::Items;
 use Koha::Patrons;
-use Koha::Checkouts;
 
 my $query = new CGI;
 
@@ -580,8 +579,6 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
     push @riloop, \%ri;
 }
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
 $template->param(
     riloop         => \@riloop,
     printer        => $printer,
@@ -592,7 +589,6 @@ $template->param(
     forgivemanualholdsexpire => $forgivemanualholdsexpire,
     overduecharges => $overduecharges,
     AudioAlerts        => C4::Context->preference("AudioAlerts"),
-    pending_checkout_notes => $pending_checkout_notes,
 );
 
 $itemnumber = GetItemnumberFromBarcode( $barcode );
index 935cb4e..03fa65b 100755 (executable)
@@ -27,7 +27,6 @@ use C4::Print;  # GetPrinters
 use C4::Koha;
 use Koha::BiblioFrameworks;
 use Koha::Libraries;
-use Koha::Checkouts;
 
 # this will be the script that chooses branch and printer settings....
 
@@ -127,14 +126,11 @@ if (scalar @updated and not scalar @recycle_loop) {
     print $query->redirect($referer || '/cgi-bin/koha/circ/circulation.pl');
 }
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
 $template->param(
     referer     => $referer,
     printerloop => \@printerloop,
     branch      => $branch,
     recycle_loop=> \@recycle_loop,
-    pending_checkout_notes => $pending_checkout_notes,
 );
 
 # Checking if there is a Fast Cataloging Framework
index cf43499..a727dda 100755 (executable)
@@ -40,7 +40,6 @@ use Koha::Libraries;
 use Koha::DateUtils;
 use Koha::BiblioFrameworks;
 use Koha::Patrons;
-use Koha::Checkouts;
 
 my $input = new CGI;
 my $itemnumber = $input->param('itemnumber');
@@ -126,14 +125,11 @@ while ( my $library = $libraries->next ) {
     push( @branchesloop, \%branchloop ) if %branchloop;
 }
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
 $template->param(
     branchesloop => \@branchesloop,
     show_date    => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
     TransfersMaxDaysWarning => C4::Context->preference('TransfersMaxDaysWarning'),
     latetransfers => $latetransfers ? 1 : 0,
-    pending_checkout_notes => $pending_checkout_notes,
 );
 
 # Checking if there is a Fast Cataloging Framework
index d471476..f7dbbc2 100755 (executable)
@@ -30,7 +30,6 @@ use C4::Biblio;
 use C4::Items;
 use C4::HoldsQueue qw(GetHoldsQueueItems);
 use Koha::BiblioFrameworks;
-use Koha::Checkouts;
 use Koha::ItemTypes;
 
 my $query = new CGI;
@@ -64,9 +63,6 @@ if ( $run_report ) {
     );
 }
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-$template->param( pending_checkout_notes => $pending_checkout_notes );
-
 # Checking if there is a Fast Cataloging Framework
 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
 
index 93ca0e9..aae9cbe 100755 (executable)
@@ -39,7 +39,6 @@ use Koha::BiblioFrameworks;
 use Koha::Items;
 use Koha::ItemTypes;
 use Koha::Patrons;
-use Koha::Checkouts;
 
 my $input = new CGI;
 
@@ -151,8 +150,6 @@ while ( my $hold = $holds->next ) {
 
 $template->param(cancel_result => \@cancel_result) if @cancel_result;
 
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
-
 $template->param(
     reserveloop => \@reservloop,
     reservecount => $reservcount,
@@ -161,7 +158,6 @@ $template->param(
     show_date   => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
     ReservesMaxPickUpDelay => $max_pickup_delay,
     tab => $tab,
-    pending_checkout_notes => $pending_checkout_notes,
 );
 
 # Checking if there is a Fast Cataloging Framework
index 0c69790..b686fbb 100644 (file)
@@ -21,7 +21,7 @@
                 <li><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=FA">Fast cataloging</a></li>
             [% END %][% END %]
             [% IF Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes %]
-                <li><a href="/cgi-bin/koha/circ/checkout-notes.pl">Checkout notes</a> [% IF pending_checkout_notes %]<span class="number_box"><a href="/cgi-bin/koha/circ/checkout-notes.pl">[% pending_checkout_notes %]</span>[% END %]</li>
+                <li><a href="/cgi-bin/koha/circ/checkout-notes.pl">Checkout notes</a> [% IF pending_checkout_notes.count %]<span class="number_box"><a href="/cgi-bin/koha/circ/checkout-notes.pl">[% pending_checkout_notes.count %]</span>[% END %]</li>
             [% END %]
         </ul>
 
index 55048c0..7cb0632 100644 (file)
                 <div class="row">
                     <div class="col-sm-12">
                         [%# Following statement must be in one line for translatability %]
-                        [% IF ( ( CAN_user_tools_moderate_comments  && pendingcomments ) || ( CAN_user_tools_moderate_tags && pendingtags ) || ( CAN_user_borrowers_edit_borrowers && pending_borrower_modifications ) || ( CAN_user_acquisition && pendingsuggestions ) || ( CAN_user_borrowers_edit_borrowers && pending_discharge_requests ) || pending_article_requests) || ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes ) %]
+                        [% IF ( ( CAN_user_tools_moderate_comments  && pendingcomments ) || ( CAN_user_tools_moderate_tags && pendingtags ) || ( CAN_user_borrowers_edit_borrowers && pending_borrower_modifications ) || ( CAN_user_acquisition && pendingsuggestions ) || ( CAN_user_borrowers_edit_borrowers && pending_discharge_requests ) || pending_article_requests) || ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes.count ) %]
                             <div id="area-pending">
                                 [% IF pending_article_requests %]
                                 <div class="pending-info" id="article_requests_pending">
                                 </div>
                                 [% END %]
 
-                                [% IF Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes %]
+                                [% IF Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes.count %]
                                     <div class="pending-info" id="checkout_notes_pending">
                                         <a href="/cgi-bin/koha/circ/checkout-notes.pl">Checkout notes pending</a>:
-                                        <span class="pending-number-link">[% pending_checkout_notes %]</span>
+                                        <span class="pending-number-link">[% pending_checkout_notes.count %]</span>
                                     </div>
                                 [% END %]
 
index 34cd3a4..da6aaee 100755 (executable)
@@ -31,7 +31,6 @@ use Koha::Patron::Modifications;
 use Koha::Patron::Discharge;
 use Koha::Reviews;
 use Koha::ArticleRequests;
-use Koha::Checkouts;
 
 my $query = new CGI;
 
@@ -75,7 +74,6 @@ my $pending_article_requests = Koha::ArticleRequests->search_limited(
         $branch ? ( branchcode => $branch ) : (),
     }
 )->count;
-my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
 
 $template->param(
     pendingcomments                => $pendingcomments,
@@ -84,7 +82,6 @@ $template->param(
     pending_borrower_modifications => $pending_borrower_modifications,
     pending_discharge_requests     => $pending_discharge_requests,
     pending_article_requests       => $pending_article_requests,
-    pending_checkout_notes         => $pending_checkout_notes,
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;