From 6b861306cffc7a862697412c2939a352c1514f0e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 16 Oct 2019 14:53:48 +0200 Subject: [PATCH] Bug 23271: Replace search_limited with search_with_library_limits --- C4/ItemCirculationAlertPreference.pm | 2 +- Koha/Patron/Categories.pm | 13 +------------ Koha/Template/Plugin/Categories.pm | 2 +- acqui/add_user_search.pl | 2 +- admin/add_user_search.pl | 2 +- admin/item_circulation_alerts.pl | 2 +- admin/patron-attr-types.pl | 2 +- members/guarantor_search.pl | 2 +- members/memberentry.pl | 2 +- members/members-home.pl | 2 +- members/update-child.pl | 2 +- patroncards/add_user_search.pl | 2 +- reports/bor_issues_top.pl | 2 +- reports/borrowers_out.pl | 2 +- reports/cat_issues_top.pl | 2 +- reports/issues_stats.pl | 2 +- reports/reserves_stats.pl | 4 ++-- serials/add_user_search.pl | 2 +- t/db_dependent/Utils/Datatables_Virtualshelves.t | 2 +- tools/cleanborrowers.pl | 2 +- tools/import_borrowers.pl | 2 +- tools/modborrowers.pl | 2 +- 22 files changed, 23 insertions(+), 34 deletions(-) diff --git a/C4/ItemCirculationAlertPreference.pm b/C4/ItemCirculationAlertPreference.pm index 4eb263c196..c7935163f2 100644 --- a/C4/ItemCirculationAlertPreference.pm +++ b/C4/ItemCirculationAlertPreference.pm @@ -331,7 +331,7 @@ sub grid { my ($class, $where) = @_; my @branch_prefs = $class->find($where); my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} }); - my @cc = Koha::Patron::Categories->search_limited; + my @cc = Koha::Patron::Categories->search_with_library_limits; my @it = Koha::ItemTypes->search; my $notification = $where->{notification}; my %disabled = map { diff --git a/Koha/Patron/Categories.pm b/Koha/Patron/Categories.pm index 3673ce0211..af21f94e62 100644 --- a/Koha/Patron/Categories.pm +++ b/Koha/Patron/Categories.pm @@ -25,7 +25,7 @@ use Koha::Database; use Koha::Patron::Category; -use base qw(Koha::Objects); +use base qw(Koha::Objects Koha::Objects::Limit::Library); =head1 NAME @@ -37,17 +37,6 @@ Koha::Patron::Categories - Koha Patron Category Object set class =cut -sub search_limited { - my ( $self, $params, $attributes ) = @_; - my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; - if ( $branch_limit ) { - $params->{'categories_branches.branchcode'} = [ $branch_limit, undef ]; - $attributes->{join} = 'categories_branches'; - } - $attributes->{order_by} = ['description'] unless $attributes->{order_by}; - return $self->search($params, $attributes); -} - =head3 type =cut diff --git a/Koha/Template/Plugin/Categories.pm b/Koha/Template/Plugin/Categories.pm index 140f12a395..59d358802e 100644 --- a/Koha/Template/Plugin/Categories.pm +++ b/Koha/Template/Plugin/Categories.pm @@ -25,7 +25,7 @@ use Koha::Patron::Categories; sub all { my ( $self, $params ) = @_; - return Koha::Patron::Categories->search_limited($params); + return Koha::Patron::Categories->search_with_library_limits($params); } sub GetName { diff --git a/acqui/add_user_search.pl b/acqui/add_user_search.pl index d2481c6237..97e5eec03c 100755 --- a/acqui/add_user_search.pl +++ b/acqui/add_user_search.pl @@ -51,7 +51,7 @@ my $search_patrons_with_acq_perm_only = ( $referer =~ m|acqui/basket.pl| ) ? 1 : 0; -my $patron_categories = Koha::Patron::Categories->search_limited; +my $patron_categories = Koha::Patron::Categories->search_with_library_limits; $template->param( patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", diff --git a/admin/add_user_search.pl b/admin/add_user_search.pl index ba3989aa51..709281f47b 100755 --- a/admin/add_user_search.pl +++ b/admin/add_user_search.pl @@ -52,7 +52,7 @@ my $search_patrons_with_acq_perm_only = ( $referer =~ m|admin/aqbudgets.pl| ) ? 1 : 0; -my $patron_categories = Koha::Patron::Categories->search_limited; +my $patron_categories = Koha::Patron::Categories->search_with_library_limits; $template->param( patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", diff --git a/admin/item_circulation_alerts.pl b/admin/item_circulation_alerts.pl index 9ea89a5b53..4e44828103 100755 --- a/admin/item_circulation_alerts.pl +++ b/admin/item_circulation_alerts.pl @@ -50,7 +50,7 @@ sub show { ); my $branch = $input->param('branch') || '*'; - my @categories = Koha::Patron::Categories->search_limited; + my @categories = Koha::Patron::Categories->search_with_library_limits; my @item_types = Koha::ItemTypes->search; my $grid_checkout = $preferences->grid({ branchcode => $branch, notification => 'CHECKOUT' }); my $grid_checkin = $preferences->grid({ branchcode => $branch, notification => 'CHECKIN' }); diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index 174bac5926..4d38504af1 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -95,7 +95,7 @@ sub add_attribute_type_form { }; } - my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); + my $patron_categories = Koha::Patron::Categories->search_with_library_limlits({}, {order_by => ['description']}); $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', diff --git a/members/guarantor_search.pl b/members/guarantor_search.pl index 0287047740..1c9e4c2e0b 100755 --- a/members/guarantor_search.pl +++ b/members/guarantor_search.pl @@ -44,7 +44,7 @@ my $op = $input->param('op') || ''; my $referer = $input->referer(); -my $patron_categories = Koha::Patron::Categories->search_limited; +my $patron_categories = Koha::Patron::Categories->search_with_library_limits; $template->param( view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ], diff --git a/members/memberentry.pl b/members/memberentry.pl index fa5cbe427e..9b5484287b 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -612,7 +612,7 @@ my @typeloop; my $no_categories = 1; my $no_add; foreach my $category_type (qw(C A S P I X)) { - my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => $category_type }, {order_by => ['categorycode']}); + my $patron_categories = Koha::Patron::Categories->search_with_library_limits({ category_type => $category_type }, {order_by => ['categorycode']}); $no_categories = 0 if $patron_categories->count > 0; my @categoryloop; diff --git a/members/members-home.pl b/members/members-home.pl index 73a370dc81..3a6369a0ce 100755 --- a/members/members-home.pl +++ b/members/members-home.pl @@ -45,7 +45,7 @@ if( Koha::Libraries->search->count < 1){ $template->param(no_branches => 1); } -my @categories = Koha::Patron::Categories->search_limited; +my @categories = Koha::Patron::Categories->search_with_library_limits; if(scalar(@categories) < 1){ $no_add = 1; $template->param(no_categories => 1); diff --git a/members/update-child.pl b/members/update-child.pl index 60d239a76c..74ab49528f 100755 --- a/members/update-child.pl +++ b/members/update-child.pl @@ -58,7 +58,7 @@ my $op = $input->param('op'); my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; -my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); +my $patron_categories = Koha::Patron::Categories->search_with_library_limits({ category_type => 'A' }, {order_by => ['categorycode']}); if ( $op eq 'multi' ) { # FIXME - what are the possible upgrade paths? C -> A , C -> S ... # currently just allowing C -> A diff --git a/patroncards/add_user_search.pl b/patroncards/add_user_search.pl index c8eca5fa74..2a54efb014 100755 --- a/patroncards/add_user_search.pl +++ b/patroncards/add_user_search.pl @@ -44,7 +44,7 @@ my $op = $input->param('op') || ''; my $referer = $input->referer(); -my $patron_categories = Koha::Patron::Categories->search_limited; +my $patron_categories = Koha::Patron::Categories->search_with_library_limits; $template->param( view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", columns => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'], diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl index 84a46a36a2..b1864048f3 100755 --- a/reports/bor_issues_top.pl +++ b/reports/bor_issues_top.pl @@ -110,7 +110,7 @@ my @values; my @mime = ( map { {type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation my $delims = GetDelimiterChoices; -my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); +my $patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['categorycode']}); my $itemtypes = Koha::ItemTypes->search_with_localization; $template->param( mimeloop => \@mime, diff --git a/reports/borrowers_out.pl b/reports/borrowers_out.pl index 762a0d4d09..3975c8378d 100755 --- a/reports/borrowers_out.pl +++ b/reports/borrowers_out.pl @@ -118,7 +118,7 @@ if ($do_it) { my $CGIextChoice = ( 'CSV' ); # FIXME translation my $CGIsepChoice = GetDelimiterChoices; - my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); + my $patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['categorycode']}); $template->param( CGIextChoice => $CGIextChoice, CGIsepChoice => $CGIsepChoice, diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl index 604258e9c9..38c6e1559d 100755 --- a/reports/cat_issues_top.pl +++ b/reports/cat_issues_top.pl @@ -133,7 +133,7 @@ if ($do_it) { @shelvinglocloop = sort {$a->{value} cmp $b->{value}} @shelvinglocloop; - my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); + my $patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['categorycode']}); $template->param( CGIextChoice => $CGIextChoice, diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl index 3c1ba1facb..f7d45438ba 100755 --- a/reports/issues_stats.pl +++ b/reports/issues_stats.pl @@ -89,7 +89,7 @@ $template->param(do_it => $do_it, our $itemtypes = Koha::ItemTypes->search_with_localization->unblessed; -our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); +our @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); our $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; our $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; diff --git a/reports/reserves_stats.pl b/reports/reserves_stats.pl index 09bfd0c729..0c309a64ef 100755 --- a/reports/reserves_stats.pl +++ b/reports/reserves_stats.pl @@ -75,7 +75,7 @@ $sep = "\t" if ($sep eq 'tabulation'); $template->param(do_it => $do_it, ); -my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); +my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); my $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; my $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; @@ -337,7 +337,7 @@ sub display_value { } } elsif ( $crit =~ /category/ ) { - my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); + my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); foreach my $patron_category ( @patron_categories ) { ( $value eq $patron_category->categorycode ) or next; $display_value = $patron_category->description and last; diff --git a/serials/add_user_search.pl b/serials/add_user_search.pl index 6cb177acbe..b9f42bc6b6 100755 --- a/serials/add_user_search.pl +++ b/serials/add_user_search.pl @@ -44,7 +44,7 @@ my $op = $input->param('op') || ''; my $referer = $input->referer(); -my $patron_categories = Koha::Patron::Categories->search_limited; +my $patron_categories = Koha::Patron::Categories->search_with_library_limits; $template->param( view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", columns => ['cardnumber', 'name', 'branch', 'action'], diff --git a/t/db_dependent/Utils/Datatables_Virtualshelves.t b/t/db_dependent/Utils/Datatables_Virtualshelves.t index eaf5ce5fd8..758f93fff9 100644 --- a/t/db_dependent/Utils/Datatables_Virtualshelves.t +++ b/t/db_dependent/Utils/Datatables_Virtualshelves.t @@ -38,7 +38,7 @@ my $dbh = C4::Context->dbh; $dbh->do(q|DELETE FROM virtualshelves|); # Pick a categorycode from the DB -my @categories = Koha::Patron::Categories->search_limited; +my @categories = Koha::Patron::Categories->search_with_library_limits; my $categorycode = $categories[0]->categorycode; my $branchcode = "ABC"; my $branch_data = { diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index 3040b1d777..ac4e76d3a7 100755 --- a/tools/cleanborrowers.pl +++ b/tools/cleanborrowers.pl @@ -179,7 +179,7 @@ elsif ( $step == 3 ) { $template->param( patron_lists => [ @non_empty_lists ] ); } -my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); +my $patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); $template->param( step => $step, diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index 4da2cd0d03..ea1a7c3a83 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -80,7 +80,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); # get the patron categories and pass them to the template -my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); +my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); $template->param( categories => \@patron_categories ); my $columns = C4::Templates::GetColumnDefs( $input )->{borrowers}; $columns = [ grep { $_->{field} ne 'borrowernumber' ? $_ : () } @$columns ]; diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index eaa93eaf8f..71da4746e1 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -115,7 +115,7 @@ if ( $op eq 'show' ) { my @patron_attributes_values; my @patron_attributes_codes; my $patron_attribute_types = C4::Members::AttributeTypes::GetAttributeTypes_hashref('all'); - my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); + my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']}); for ( values %$patron_attribute_types ) { my $attr_type = C4::Members::AttributeTypes->fetch( $_->{code} ); # TODO Repeatable attributes are not correctly managed and can cause data lost. -- 2.11.0