Bug 20310: (follow-up) Move syspref check into controller
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 28 Jun 2021 13:07:53 +0000 (14:07 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Jul 2021 13:47:34 +0000 (15:47 +0200)
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 <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Biblio.pm
opac/opac-request-article.pl
t/db_dependent/Koha/Biblio/host_record.t

index 12b22d9..3b38a82 100644 (file)
@@ -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;
index 07df6ac..89110b6 100644 (file)
@@ -77,14 +77,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);
index bf728f1..59b9f13 100755 (executable)
@@ -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' });