From d67ccfd582da229f08b550bd7f8948544264fd14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Wed, 29 Oct 2025 17:05:52 -0300 Subject: [PATCH] Bug 40841: Implement library limits on Z39.50 searches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Same as 11 but with the advanced editor => SUCCESS: Limits are respected! 14. Sign off :-D Signed-off-by: Tomás Cohen Arazi --- cataloguing/editor.pl | 17 +++++++++-------- cataloguing/z3950_auth_search.pl | 14 +++++++++----- cataloguing/z3950_search.pl | 10 +++++----- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cataloguing/editor.pl b/cataloguing/editor.pl index b40d4c3ecc9..ac41f240eba 100755 --- a/cataloguing/editor.pl +++ b/cataloguing/editor.pl @@ -30,6 +30,7 @@ use Koha::Database; use Koha::MarcSubfieldStructures; use Koha::BiblioFrameworks; use Koha::KeyboardShortcuts; +use Koha::Z3950Servers; my $input = CGI->new; @@ -76,14 +77,14 @@ $template->{VARS}->{authtags} = $authtags; my $frameworks = Koha::BiblioFrameworks->search( {}, { order_by => ['frameworktext'] } ); $template->{VARS}->{frameworks} = $frameworks; -# Z39.50 servers -my $dbh = C4::Context->dbh; -$template->{VARS}->{z3950_servers} = $dbh->selectall_arrayref( - q{ - SELECT * FROM z3950servers - WHERE recordtype != 'authority' AND servertype = 'zed' - ORDER BY `rank`,servername -}, { Slice => {} } +$template->param( + z3950_servers => Koha::Z3950Servers->search_with_library_limits( + { + recordtype => { '!=' => 'authority' }, + servertype => 'zed' + }, + { order_by => [ 'rank', 'servername' ] }, + ) ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/cataloguing/z3950_auth_search.pl b/cataloguing/z3950_auth_search.pl index 2bd0e2fbec7..bbedc34d7c3 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,16 @@ $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' ], + }, ); - $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..4293216226e 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,17 @@ $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' ], }, ); $template->param( - serverloop => [ $rs->all ], + serverloop => $servers, opsearch => "cud-search", ); output_html_with_http_headers $input, $cookie, $template->output; -- 2.50.1 (Apple Git-155)