@@ -, +, @@
---
misc/cronjobs/checkurl | 190 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 190 insertions(+), 0 deletions(-)
create mode 100755 misc/cronjobs/checkurl
--- a/misc/cronjobs/checkurl
+++ a/misc/cronjobs/checkurl
@@ -0,0 +1,190 @@
+#!/usr/bin/perl
+
+# Copyright 2012 Tamil s.a.r.l.
+#
+# 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 2 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use 5.010;
+use utf8;
+use strict;
+use warnings;
+use Pod::Usage;
+use Getopt::Long;
+use C4::Context;
+use C4::Biblio;
+use AnyEvent;
+use AnyEvent::HTTP;
+
+my ($verbose, $help, $html) = (0, 0, 0);
+my ($host, $host_pro) = ('', '');
+my ($timeout, $maxconn) = (10, 200);
+my $uriedit = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
+GetOptions(
+ 'verbose' => \$verbose,
+ 'html' => \$html,
+ 'help' => \$help,
+ 'host=s' => \$host,
+ 'host-pro=s' => \$host_pro,
+ 'timeout=i' => \$timeout,
+ 'maxconn=i' => \$maxconn,
+);
+
+
+sub usage {
+ pod2usage( -verbose => 2 );
+ exit;
+}
+
+
+sub bibediturl {
+ my $biblionumber = shift;
+ my $html = "$biblionumber";
+ return $html;
+}
+
+
+# Check all URLs from all current Koha biblio records
+
+sub check_all_url {
+ my $sth = C4::Context->dbh->prepare(
+ "SELECT biblionumber FROM biblioitems WHERE url <> ''" );
+ $sth->execute;
+ if ( $html ) {
+ print <
+
+
+EOS
+ }
+
+ my $countconn = 0;
+ my $cv = AnyEvent->condvar;
+ my $idle = AnyEvent->idle(
+ cb => sub {
+ return if $countconn > $maxconn;
+ while ( my ($biblionumber) = $sth->fetchrow ) {
+ my $record = GetMarcBiblio( $biblionumber );
+ next unless $record->field('856');
+ foreach my $field ( $record->field('856') ) {
+ my $url = $field->subfield('u');
+ next unless $url;
+ $url = "$host/$url" unless $url =~ /^http/;
+ $countconn++;
+ http_request(
+ HEAD => $url,
+ headers => { 'user-agent' => 'Mozilla/5.0 (compatible; U; Koha checkurl)' },
+ timeout => $timeout,
+ sub {
+ my ($body, $hdr) = @_;
+ #say "HEAD found $url";
+ $countconn--;
+ if ( $hdr->{Status} !~ /^2/ || $verbose) { # OK
+ print $html
+ ? "