From 686db04a7aa1fa0a6b67c010264071f624e9e436 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi 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 --- 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 . - -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 - -=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 . - -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