ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / misc / cronjobs / check-url.pl
index 3936b49..5c0957b 100755 (executable)
@@ -5,18 +5,18 @@
 #
 # 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 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 3 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.
+# 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.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 
 
@@ -85,9 +85,10 @@ use C4::Biblio;
 sub new {
 
     my $self = {};
-    my ($class, $timeout) = @_;
+    my ($class, $timeout, $agent) = @_;
     
     my $uagent = new LWP::UserAgent;
+    $uagent->agent( $agent ) if $agent;
     $uagent->timeout( $timeout) if $timeout;
     $self->{ user_agent } = $uagent;
     $self->{ bad_url    } = { };
@@ -104,7 +105,7 @@ sub check_biblio {
     my $host            = $self->{ host_default };
     my $bad_url         = $self->{ bad_url      };
 
-    my $record = GetMarcBiblio( $biblionumber ); 
+    my $record = GetMarcBiblio({ biblionumber => $biblionumber });
     return unless $record->field('856');
 
     my @urls = ();
@@ -156,6 +157,7 @@ my $host        = '';
 my $host_pro    = '';
 my $html        = 0;
 my $uriedit     = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
+my $agent       = '';
 my $timeout     = 15;
 GetOptions( 
     'verbose'       => \$verbose,
@@ -163,6 +165,7 @@ GetOptions(
     'help'          => \$help,
     'host=s'        => \$host,
     'host-pro=s'    => \$host_pro,
+    'agent=s'       => \$agent,
     'timeout=i',    => \$timeout,
 );
 
@@ -184,7 +187,7 @@ sub bibediturl {
 # Check all URLs from all current Koha biblio records
 #
 sub check_all_url {
-    my $checker = C4::URL::Checker->new($timeout);
+    my $checker = C4::URL::Checker->new($timeout,$agent);
     $checker->{ host_default }  = $host;
     
     my $context = new C4::Context(  );  
@@ -243,10 +246,11 @@ check-url.pl - Check URLs from 856$u field.
 
 =over
 
-=item check-url.pl [--verbose|--help] [--host=http://default.tld] 
+=item check-url.pl [--verbose|--help] [--agent=agent-string] [--host=http://default.tld]
 
 Scan all URLs found in 856$u of bib records 
 and display if resources are available or not.
+This script is deprecated. You should rather use check-url-quick.pl.
 
 =back
 
@@ -274,6 +278,12 @@ record in edit mode. With this parameter B<--host-pro> is required.
 
 Server host used to link to biblio record editing page.
 
+=item B<--agent=agent-string>
+
+Change default libwww user-agent string to custom.  Some sites do
+not like libwww user-agent and return false 40x failure codes,
+so this allows Koha to report itself as Koha, or a browser.
+
 =item B<--timeout=15>
 
 Timeout for fetching URLs. By default 15 seconds.