Bugzilla – Attachment 180465 Details for
Bug 35604
ILL - Allow for automatic backend selection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35604: Move available_backends() to Koha::ILL::Request::Config
Bug-35604-Move-availablebackends-to-KohaILLRequest.patch (text/plain), 9.79 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-04-03 09:09:05 UTC
(
hide
)
Description:
Bug 35604: Move available_backends() to Koha::ILL::Request::Config
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-04-03 09:09:05 UTC
Size:
9.79 KB
patch
obsolete
>From 686db04a7aa1fa0a6b67c010264071f624e9e436 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 3 Apr 2025 10:50:07 +0200 >Subject: [PATCH] Bug 35604: Move available_backends() to > Koha::ILL::Request::Config > >This patch removes the the Koha::ILL::Backends class as it is not >actually a Koha::Objects-based class as it claims, and also internally >instantiates the config class, which could just hold the only defined >method. > >This method is only used in the preferences.pl page, and its occurence >is fixed by this patch. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/ILL/Backends.pm | 74 --------------------- > Koha/ILL/Request/Config.pm | 13 ++++ > Koha/ILL/Request/Workflow/ConfirmAuto.pm | 1 - > admin/preferences.pl | 4 +- > t/db_dependent/Koha/ILL/Backends.t | 84 ------------------------ > t/db_dependent/Koha/ILL/Request/Config.t | 58 +++++++++++++++- > 6 files changed, 71 insertions(+), 163 deletions(-) > delete mode 100644 Koha/ILL/Backends.pm > delete mode 100755 t/db_dependent/Koha/ILL/Backends.t > >diff --git a/Koha/ILL/Backends.pm b/Koha/ILL/Backends.pm >deleted file mode 100644 >index 88f652ea55e..00000000000 >--- a/Koha/ILL/Backends.pm >+++ /dev/null >@@ -1,74 +0,0 @@ >-package Koha::ILL::Backends; >- >-# Copyright PTFS Europe 2023 >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use base qw(Koha::Objects); >- >-=head1 NAME >- >-Koha::ILL::Backends - Koha Illbackends Object class >- >-=head2 Class methods >- >-=head3 new >- >-New ILL Backend >- >-=cut >- >-sub new { >- my $class = shift; >- my $self = {}; >- return bless $self, $class; >-} >- >-=head3 installed_backends >- >-Return a list of installed backends. >- >-=cut >- >-sub installed_backends { >- my $backends = Koha::ILL::Request::Config->new->available_backends; >- my @installed = grep { !/Standard/ } @{$backends}; >- return \@installed; >-} >- >-=head2 Internal methods >- >-=head3 _type >- >- my $type = Koha::ILL::Backend->_type; >- >-Return this object's type >- >-=cut >- >-sub _type { >- return 'Illbackend'; >-} >- >-=head1 AUTHOR >- >-Pedro Amorim <pedro.amorim@ptfs-europe.com> >- >-=cut >- >-1; >diff --git a/Koha/ILL/Request/Config.pm b/Koha/ILL/Request/Config.pm >index e35fddf4e16..0b14ec76d58 100644 >--- a/Koha/ILL/Request/Config.pm >+++ b/Koha/ILL/Request/Config.pm >@@ -158,6 +158,19 @@ sub available_backends { > return \@all_uniq_backends; > } > >+=head3 installed_backends >+ >+ my $installed_backends = $config->installed_backends(); >+ >+Returns a list of installed backends. >+ >+=cut >+ >+sub installed_backends { >+ my ($self) = @_; >+ return [ grep { !/Standard/ } @{ $self->available_backends } ]; >+} >+ > =head3 has_branch > > Return whether a 'branch' block is defined >diff --git a/Koha/ILL/Request/Workflow/ConfirmAuto.pm b/Koha/ILL/Request/Workflow/ConfirmAuto.pm >index fe257020114..f19c2402410 100644 >--- a/Koha/ILL/Request/Workflow/ConfirmAuto.pm >+++ b/Koha/ILL/Request/Workflow/ConfirmAuto.pm >@@ -22,7 +22,6 @@ use Modern::Perl; > use base qw(Koha::ILL::Request::Workflow); > > use JSON qw( encode_json ); >-use Koha::ILL::Backends; > > =head1 NAME > >diff --git a/admin/preferences.pl b/admin/preferences.pl >index 0d7a885e207..34ddca9497d 100755 >--- a/admin/preferences.pl >+++ b/admin/preferences.pl >@@ -29,7 +29,7 @@ use C4::Output qw( output_html_with_http_headers output_and_exit_if_error ) > use C4::Templates; > use Koha::Acquisition::Currencies; > use Koha::Database::Columns; >-use Koha::ILL::Backends; >+use Koha::ILL::Request::Config; > use IO::File; > use YAML::XS; > use Encode; >@@ -85,7 +85,7 @@ sub _get_chunk { > my @priority_enabled_backends = split ",", C4::Context->preference('AutoILLBackendPriority'); > my @sys_pref_backends = map( { name => $_, enabled => 1 }, @priority_enabled_backends ); > >- my $installed_backends = Koha::ILL::Backends->installed_backends; >+ my $installed_backends = Koha::ILL::Request::Config->new->installed_backends; > foreach my $installed_backend ( @{$installed_backends} ) { > if ( not grep { $installed_backend eq $_->{name} } @sys_pref_backends ) { > my $backend = Koha::ILL::Request->new->load_backend($installed_backend); >diff --git a/t/db_dependent/Koha/ILL/Backends.t b/t/db_dependent/Koha/ILL/Backends.t >deleted file mode 100755 >index d83cba1c91b..00000000000 >--- a/t/db_dependent/Koha/ILL/Backends.t >+++ /dev/null >@@ -1,84 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2023 Koha Development team >-# >-# This file is part of Koha >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >-use File::Basename; >-use File::Path qw(make_path remove_tree); >-use Test::MockModule; >- >-use Test::More tests => 4; >- >-use Koha::ILL::Backends; >- >-use t::lib::TestBuilder; >-use t::lib::Mocks; >- >-BEGIN { >- # Mock pluginsdir before loading Plugins module >- my $path = dirname(__FILE__) . '/../../../lib/plugins'; >- t::lib::Mocks::mock_config( 'pluginsdir', $path ); >- >- use_ok('Koha::Plugins'); >- use_ok('Koha::Plugins::Handler'); >- use_ok('Koha::Plugin::Test'); >-} >- >-my $builder = t::lib::TestBuilder->new; >-my $schema = Koha::Database->new->schema; >- >-t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >- >-subtest 'installed_backends() tests' => sub { >- >- # dir backend = An ILL backend installed through backend_directory in koha-conf.xml >- # plugin backend = An ILL backend installed through a plugin >- >- plan tests => 2; >- >- $schema->storage->txn_begin; >- >- # Install a plugin_backend >- my $plugins = Koha::Plugins->new; >- $plugins->InstallPlugins; >- is_deeply( >- Koha::ILL::Backends->installed_backends, ['Test Plugin'], >- 'Only one backend installed, happens to be a plugin' >- ); >- >- # Install a dir backend >- my $dir_backend = '/tmp/ill_backend_test/Old_Backend'; >- my $ill_config = Test::MockModule->new('Koha::ILL::Request::Config'); >- $ill_config->mock( >- 'backend_dir', >- sub { >- return '/tmp/ill_backend_test'; >- } >- ); >- make_path($dir_backend); >- my $installed_backends = Koha::ILL::Backends->installed_backends; >- is_deeply( >- $installed_backends, [ 'Old_Backend', 'Test Plugin' ], >- 'Two backends are installed, one plugin and one directory backend' >- ); >- >- #cleanup >- remove_tree($dir_backend); >- Koha::Plugins::Methods->delete; >- $schema->storage->txn_rollback; >-}; >diff --git a/t/db_dependent/Koha/ILL/Request/Config.t b/t/db_dependent/Koha/ILL/Request/Config.t >index 8bafed32c1f..e738888ef69 100755 >--- a/t/db_dependent/Koha/ILL/Request/Config.t >+++ b/t/db_dependent/Koha/ILL/Request/Config.t >@@ -17,6 +17,9 @@ > > use Modern::Perl; > >+use File::Basename; >+use File::Path qw(make_path remove_tree); >+ > use Koha::Database; > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -24,11 +27,62 @@ use Test::MockObject; > use Test::Exception; > > use Test::NoWarnings; >-use Test::More tests => 7; >+use Test::More tests => 11; >+ >+BEGIN { >+ # Mock pluginsdir before loading Plugins module >+ my $path = dirname(__FILE__) . '/../../../../lib/plugins'; >+ t::lib::Mocks::mock_config( 'pluginsdir', $path ); >+ >+ use_ok('Koha::ILL::Request::Config'); >+ use_ok('Koha::Plugins'); >+ use_ok('Koha::Plugins::Handler'); >+ use_ok('Koha::Plugin::Test'); >+} > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >-use_ok('Koha::ILL::Request::Config'); >+ >+t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ >+subtest 'installed_backends() tests' => sub { >+ >+ # dir backend = An ILL backend installed through backend_directory in koha-conf.xml >+ # plugin backend = An ILL backend installed through a plugin >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ # Install a plugin_backend >+ my $plugins = Koha::Plugins->new; >+ $plugins->InstallPlugins; >+ is_deeply( >+ Koha::ILL::Request::Config->new->installed_backends, ['Test Plugin'], >+ 'Only one backend installed, happens to be a plugin' >+ ); >+ >+ # Install a dir backend >+ my $dir_backend = '/tmp/ill_backend_test/Old_Backend'; >+ my $ill_config = Test::MockModule->new('Koha::ILL::Request::Config'); >+ $ill_config->mock( >+ 'backend_dir', >+ sub { >+ return '/tmp/ill_backend_test'; >+ } >+ ); >+ make_path($dir_backend); >+ my $installed_backends = Koha::ILL::Request::Config->installed_backends; >+ is_deeply( >+ $installed_backends, [ 'Old_Backend', 'Test Plugin' ], >+ 'Two backends are installed, one plugin and one directory backend' >+ ); >+ >+ #cleanup >+ remove_tree($dir_backend); >+ Koha::Plugins::Methods->delete; >+ $schema->storage->txn_rollback; >+}; > > my $base_limits = { > branch => { CPL => { count => 1, method => 'annual' } }, >-- >2.49.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 35604
:
160035
|
164883
|
164884
|
164885
|
164886
|
164887
|
164888
|
165135
|
165164
|
165165
|
165294
|
165295
|
165296
|
165297
|
165298
|
165299
|
165300
|
166897
|
166898
|
166899
|
166900
|
166901
|
166902
|
166903
|
166995
|
166996
|
166997
|
166998
|
166999
|
167000
|
167001
|
171326
|
171327
|
171328
|
171329
|
171330
|
171331
|
171332
|
174515
|
174516
|
174517
|
174518
|
174519
|
174520
|
174521
|
174522
|
174524
|
174792
|
175828
|
175829
|
175830
|
175831
|
175832
|
175833
|
175834
|
175835
|
175836
|
176036
|
176261
|
176262
|
176263
|
176264
|
176265
|
176266
|
176267
|
176268
|
176269
|
176270
|
176572
|
176662
|
176681
|
176682
|
176683
|
176684
|
176685
|
176686
|
176687
|
176688
|
176689
|
176690
|
176691
|
176692
|
178305
|
178306
|
178307
|
178308
|
178309
|
178310
|
178311
|
178312
|
178313
|
178314
|
178315
|
178316
|
178707
|
178708
|
178709
|
178710
|
178711
|
178712
|
178713
|
178714
|
178715
|
178716
|
178717
|
178718
|
179698
|
179699
|
179720
|
179721
|
180335
|
180451
|
180452
|
180453
|
180454
|
180455
|
180456
|
180457
|
180458
|
180459
|
180460
|
180461
|
180462
|
180463
|
180464
| 180465 |
180956