From ea8fe82de29d75393947a154eaad4187a6896623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Wed, 29 Oct 2025 10:05:32 -0300 Subject: [PATCH] Bug 40841: Implement library limits on Z39.50 searches This patchset implements Z39.50/SRU limits by branch in Koha. Key implementation notes: - Follows Koha's established pattern for library limits - A new table linking to library limits is added - The admin UI is adjusted so the form includes library limit selection - Z39.50/SRU search controllers use the `search_with_library_limits` methods to correctly constraint the offered servers. To test: 1. Apply this patches 2. Run: $ ktd --shell k$ updatedatabase => SUCCESS: Database upgrade goes well 3. Re-run: k$ updatedatabase => SUCCESS: No explosions, DB update idempotent 4. Restart everything: k$ restart_all 5. POint your browser to the admin page: http://kohadev-intra.localhost/cgi-bin/koha/admin/z3950servers.pl => SUCCESS: A new column is displayed for library limits brief 6. Edit `LIBRARY OF CONGRESS` => SUCCESS: The form includes the usual library limit selection UI 7. Choose some branches, excluding your current one (KTD's default is 'Centerville'). 8. Save => SUCCESS: It is saved correctly => SUCCESS: The table shows the edited library has the library limits set 9. Edit again => SUCCESS: The selected limits are preserved when editing 10. Pick some authorities Z39.50 target, and exclude your current branch for testing purposes. 11. Go to Cataloguing, and choose 'New from Z39.50/SRU' => SUCCESS: Limits are respected! 12. Go to Authorities, and choose 'New from Z39.50/SRU' => SUCCESS: Limits are respected! 13. Sign off :-D --- cataloguing/z3950_auth_search.pl | 15 ++++++++++----- cataloguing/z3950_search.pl | 11 ++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cataloguing/z3950_auth_search.pl b/cataloguing/z3950_auth_search.pl index 2bd0e2fbec7..3d4dfeed915 100755 --- a/cataloguing/z3950_auth_search.pl +++ b/cataloguing/z3950_auth_search.pl @@ -27,6 +27,7 @@ use C4::Breeding qw( Z3950Search Z3950SearchAuth ); use MARC::Record; use Koha::Authorities; use Koha::Authority::Types; +use Koha::Z3950Servers; use C4::AuthoritiesMarc qw( GetAuthority ); my $input = CGI->new; @@ -97,13 +98,17 @@ $template->param( ); if ( $op ne "cud-do_search" ) { - my $sth = $dbh->prepare( - "SELECT id,host,servername,checked FROM z3950servers WHERE recordtype = 'authority' ORDER BY `rank`, servername" + my $servers = Koha::Z3950Servers->search_with_library_limits( + { + recordtype => 'authority', + }, + { + order_by => [ 'rank', 'servername' ], + }, + C4::Context->userenv ? C4::Context->userenv->{branch} : undef ); - $sth->execute(); - my $serverloop = $sth->fetchall_arrayref( {} ); $template->param( - serverloop => $serverloop, + serverloop => $servers, opsearch => "cud-search", index => $index, ); diff --git a/cataloguing/z3950_search.pl b/cataloguing/z3950_search.pl index a80cd122420..55883fe2714 100755 --- a/cataloguing/z3950_search.pl +++ b/cataloguing/z3950_search.pl @@ -26,6 +26,8 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Context; use C4::Breeding qw( Z3950Search ); +use Koha::Z3950Servers; + my $input = CGI->new; my $error = $input->param('error'); my $biblionumber = $input->param('biblionumber') || 0; @@ -74,19 +76,18 @@ $template->param( ); if ( $op ne "cud-do_search" ) { - my $schema = Koha::Database->new()->schema(); - my $rs = $schema->resultset('Z3950server')->search( + my $servers = Koha::Z3950Servers->search_with_library_limits( { recordtype => 'biblio', servertype => [ 'zed', 'sru' ], }, { - result_class => 'DBIx::Class::ResultClass::HashRefInflator', - order_by => [ 'rank', 'servername' ], + order_by => [ 'rank', 'servername' ], }, + C4::Context->userenv ? C4::Context->userenv->{branch} : undef ); $template->param( - serverloop => [ $rs->all ], + serverloop => $servers, opsearch => "cud-search", ); output_html_with_http_headers $input, $cookie, $template->output; -- 2.51.2