From 215b9c09d33a142473e2aba52a196c608ef808eb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Dec 2017 12:13:10 -0300 Subject: [PATCH] Bug 19847: Track links within the records and 404 for others Test plan: Behave like a robot, you will get 404 Be a human, you will be tracked Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens Signed-off-by: Nick Clemens --- opac/tracklinks.pl | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/opac/tracklinks.pl b/opac/tracklinks.pl index 02b402deac..48076cf860 100755 --- a/opac/tracklinks.pl +++ b/opac/tracklinks.pl @@ -21,6 +21,7 @@ use Modern::Perl; use C4::Context; use C4::Auth qw(checkauth); +use C4::Biblio; use Koha::Linktracker; use CGI qw ( -utf8 ); @@ -54,25 +55,28 @@ if ($uri) { my $biblionumber = $cgi->param('biblionumber') || 0; my $itemnumber = $cgi->param('itemnumber') || 0; - $tracker->trackclick( - { - uri => $uri, - biblionumber => $biblionumber, - borrowernumber => $borrowernumber, - itemnumber => $itemnumber - } - ); - print $cgi->redirect($uri); + my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); + my $marc_urls = C4::Biblio::GetMarcUrls($record, C4::Context->preference('marcflavour')); + if ( grep { /^$uri$/ } map { $_->{MARCURL} } @$marc_urls ) { + $tracker->trackclick( + { + uri => $uri, + biblionumber => $biblionumber, + borrowernumber => $borrowernumber, + itemnumber => $itemnumber + } + ); + print $cgi->redirect($uri); + exit; + } } else { # We have a valid url, but we shouldn't track it, just redirect print $cgi->redirect($uri); + exit; } } -else { - # we shouldn't be here, bail out - print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); # escape early - exit; -} +print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); # escape early +exit; -- 2.39.5