Bug 30261: Render opac 404 for opac/tracklinks.pl

This patch updates C4::Output::output_error to take
an additional argument which contains an "interface"
parameter, so that opac/tracklinks.pl can generate
an OPAC error instead of an Intranet error.

Test plan:
0. Apply patch and koha-plack --restart kohadev
1. Go to http://localhost:8081/test.pl
2. Note normal Intranet 404 error
3. Go to http://localhost:8080/cgi-bin/koha/tracklinks.pl?uri=https%3A%2F%2Ftest.com&biblionumber=29
4. Note normal Opac 404 error
4b. For extra points, note that tracklinks.pl returns a 404 instead of a 302 to the 404.pl page
5. Change 'TrackClicks' syspref to "Track"
6. Go to http://localhost:8080/cgi-bin/koha/tracklinks.pl?uri=https%3A%2F%2Ftest.com&biblionumber=29
7. Note normal Opac 404 error
7b. For extra points, note that tracklinks.pl returns a 404 instead of a 302 to the 404.pl page
8. Rejoice!

Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
David Cook 2022-03-10 03:32:03 +00:00 committed by Martin Renvoize
parent c10e7a67df
commit 532d10a800
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
2 changed files with 7 additions and 4 deletions

View File

@ -392,16 +392,19 @@ Missing POD for output_error.
=cut =cut
sub output_error { sub output_error {
my ( $query, $error ) = @_; my ( $query, $error, $params ) = @_;
if ( !$error || $error =~ /\D/ ) { if ( !$error || $error =~ /\D/ ) {
Koha::Exceptions::WrongParameter->throw('output_error requires $error to be an integer'); Koha::Exceptions::WrongParameter->throw('output_error requires $error to be an integer');
} }
my $interface = 'intranet';
$interface = 'opac' if ( $params && $params->{interface} eq 'opac' );
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ {
template_name => 'errors/errorpage.tt', template_name => 'errors/errorpage.tt',
query => $query, query => $query,
type => 'intranet', type => $interface,
authnotrequired => 1, authnotrequired => 1,
} }
); );

View File

@ -37,7 +37,7 @@ $uri =~ s/^\s+|\s+$//g if $uri; # trim
my $tracking_method = C4::Context->preference('TrackClicks'); my $tracking_method = C4::Context->preference('TrackClicks');
unless ($tracking_method) { unless ($tracking_method) {
output_error( $cgi, '404' ); output_error( $cgi, '404', { interface => 'opac' } );
exit; exit;
} }
my $tracker = Koha::Linktracker->new( { trackingmethod => $tracking_method } ); my $tracker = Koha::Linktracker->new( { trackingmethod => $tracking_method } );
@ -85,5 +85,5 @@ if ( $uri && ( $biblionumber || $itemnumber ) ) {
} }
} }
output_error( $cgi, '404' ); output_error( $cgi, '404', { interface => 'opac' } );
exit; exit;