3 # Copyright 2012 Tamil s.a.r.l.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 my ( $verbose, $help, $html ) = ( 0, 0, 0 );
29 my ( $host, $host_intranet ) = ( '', '' );
30 my ( $timeout, $maxconn ) = ( 10, 200 );
32 my $uriedit = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
33 my $user_agent = 'Mozilla/5.0 (compatible; U; Koha checkurl)';
35 'verbose' => \
$verbose,
39 'host-intranet=s' => \
$host_intranet,
40 'timeout=i' => \
$timeout,
41 'maxconn=i' => \
$maxconn,
42 'tags=s{,}' => \
@tags,
45 # Validate tags to check
47 my %h = map { $_ => undef } @tags;
51 push @invalids, $_ unless /^\d{3}$/;
54 say "Invalid tag(s): ", join( ' ', @invalids );
57 push @tags, '856' unless @tags;
61 pod2usage
( -verbose
=> 2 );
66 my ( $hdr, $biblionumber, $url ) = @_;
68 ?
"<tr>\n <td><a href=\""
72 . "\">$biblionumber</a>"
73 . "</td>\n <td>$url</td>\n <td>"
74 . "$hdr->{Status} $hdr->{Reason}</td>\n</tr>\n"
75 : "$biblionumber\t$url\t" . "$hdr->{Status} $hdr->{Reason}\n";
78 # Check all URLs from all current Koha biblio records
81 my $sth = C4
::Context
->dbh->prepare(
82 "SELECT biblionumber FROM biblioitems ORDER BY biblionumber");
85 my $count = 0; # Number of requested URL
86 my $cv = AnyEvent
->condvar;
87 say "<html>\n<body>\n<div id=\"checkurl\">\n<table>" if $html;
88 my $idle = AnyEvent
->timer(
91 return if $count > $maxconn;
92 while ( my ($biblionumber) = $sth->fetchrow ) {
93 my $record = GetMarcBiblio
($biblionumber);
95 foreach my $field ( $record->field($tag) ) {
96 my $url = $field->subfield('u');
98 $url = "$host/$url" unless $url =~ /^http
/i
;
102 headers
=> { 'user-agent' => $user_agent },
105 my ( undef, $hdr ) = @_;
107 report
( $hdr, $biblionumber, $url )
108 if $hdr->{Status
} !~ /^2/ || $verbose;
113 return if $count > $maxconn;
121 # Few more time for pending requests
122 $cv = AnyEvent
->condvar;
123 my $timer = AnyEvent
->timer(
125 interval
=> $timeout,
126 cb
=> sub { $cv->send if $count == 0; }
129 say "</table>\n</div>\n</body>\n</html>" if $html;
134 if ( $html && !$host_intranet ) {
136 $host_intranet = $host;
140 "Error: host-intranet parameter or host must be provided in html mode";
149 check-url-quick.pl - Check URLs from biblio records
155 =item check-url-quick [--verbose|--help|--html] [--tags 310 856] [--host=http://default.tld]
158 Scan all URLs found by default in 856$u of bib records and display if resources
159 are available or not. HTTP requests are sent in parallel for efficiency, and
160 speed. This script replaces check-url.pl script.
168 =item B<--host=http://default.tld>
170 Server host used when URL doesn't have one, ie doesn't begin with 'http:'.
171 For example, if --host=http://www.mylib.com, then when 856$u contains
172 'img/image.jpg', the url checked is: http://www.mylib.com/image.jpg'.
176 Tags containing URLs in $u subfields. If not provided, 856 tag is checked. Multiple tags can be specified, for example:
178 check-url-quick.pl --tags 310 410 856
180 =item B<--verbose|-v>
182 Outputs both successful and failed URLs.
186 Formats output in HTML. The result can be redirected to a file
187 accessible by http. This way, it's possible to link directly to biblio
188 record in edit mode. With this parameter B<--host-intranet> is required.
190 =item B<--host-intranet=http://koha-pro.tld>
192 Server host used to link to biblio record editing page in Koha intranet
195 =item B<--timeout=10>
197 Timeout for fetching URLs. By default 10 seconds.
199 =item B<--maxconn=1000>
201 Number of simulaneous HTTP requests. By default 200 connexions.
205 Print this help page.