From 6636003ec52a61afaff119084285a8d4c9049d6f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 28 Jun 2021 14:07:53 +0100 Subject: [PATCH] Bug 20310: (follow-up) Move syspref check into controller I believe the syspref check is better placed in the controller. This way the host_record method is not so closely tied to the articel requests feature and may subsequently prove useful to future use cases. Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Biblio.pm | 1 - opac/opac-request-article.pl | 21 +++++++++++++-------- t/db_dependent/Koha/Biblio/host_record.t | 1 - 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 12b22d90ef..3b38a82ce0 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -910,7 +910,6 @@ sub host_record { my ($self, $params) = @_; my $no_items = $params->{no_items}; return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO - return if !C4::Context->preference('ArticleRequestsHostRedirection'); return if $params->{no_items} && $self->items->count > 0; my $record; diff --git a/opac/opac-request-article.pl b/opac/opac-request-article.pl index c25aa3fd63..ffa8b0cab1 100755 --- a/opac/opac-request-article.pl +++ b/opac/opac-request-article.pl @@ -79,14 +79,19 @@ if ( $action eq 'create' ) { print $cgi->redirect("/cgi-bin/koha/opac-user.pl#opac-user-article-requests"); exit; -} elsif ( !$action ) { - # Should we redirect? - # Conditions: no items, host item entry (MARC21 773) - my ( $host, $pageinfo ) = $biblio->host_record({ no_items => 1 }); - if( $host ) { - $template->param( pageinfo => $pageinfo, title => $biblio->title, author => $biblio->author ); - $biblio = $host; - } +# Should we redirect? +} +elsif ( !$action && C4::Context->preference('ArticleRequestsHostRedirection') ) { + # Conditions: no items, host item entry (MARC21 773) + my ( $host, $pageinfo ) = $biblio->host_record( { no_items => 1 } ); + if ($host) { + $template->param( + pageinfo => $pageinfo, + title => $biblio->title, + author => $biblio->author + ); + $biblio = $host; + } } my $patron = Koha::Patrons->find($borrowernumber); diff --git a/t/db_dependent/Koha/Biblio/host_record.t b/t/db_dependent/Koha/Biblio/host_record.t index bf728f1d38..59b9f139e6 100755 --- a/t/db_dependent/Koha/Biblio/host_record.t +++ b/t/db_dependent/Koha/Biblio/host_record.t @@ -40,7 +40,6 @@ subtest 'host_record' => sub { t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); t::lib::Mocks::mock_preference( 'MARCOrgCode', 'xyz' ); - t::lib::Mocks::mock_preference( 'ArticleRequestsHostRedirection', 1 ); my $bib1 = $builder->build_object({ class => 'Koha::Biblios' }); my $bib2 = $builder->build_object({ class => 'Koha::Biblios' }); -- 2.20.1