Bug 14910: Redirect to the circulation module after a renew
[koha.git] / misc / cronjobs / sitemap.pl
1 #!/usr/bin/perl
2
3 # Copyright 2015 Tamil s.a.r.l.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 package Main;
21
22 use Modern::Perl;
23 use utf8;
24 use Pod::Usage;
25 use Getopt::Long;
26 use C4::Biblio;
27 use Koha::Sitemapper;
28
29
30 my ($verbose, $help, $url, $dir, $short) = (0, 0, '', '.', 1);
31 GetOptions(
32     'verbose'   => \$verbose,
33     'help'      => \$help,
34     'url=s'     => \$url,
35     'dir=s'     => \$dir,
36     'short!'    => \$short,
37 );
38
39 sub usage {
40     pod2usage( -verbose => 2 );
41     exit;
42 }
43
44 usage() if $help;
45
46 unless ($url) {
47     $url = C4::Context->preference("OPACBaseURL");
48     unless ($url) {
49         say "OPACBaseURL syspref isn't defined. You can use --url parameter.";
50         exit;
51     }
52     $url = 'http://' . $url;
53 }
54 $url =~ s/\/*$//g;
55
56 my $sitemaper = Koha::Sitemapper->new(
57     verbose => $verbose,
58     url     => $url,
59     dir     => $dir,
60     short   => $short,
61 );
62 $sitemaper->run();
63
64
65 =head1 USAGE
66
67 =over
68
69 =item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir]
70
71 =back
72
73 =head1 SYNOPSIS
74
75   sitemap.pl --verbose
76   sitemap.pl --noshort --url /home/koha/mylibrary/www
77
78 =head1 DESCRIPTION
79
80 Process all biblio records from a Koha instance and generate Sitemap files
81 complying with this protocol as described on L<http://sitemaps.org>. The goal of
82 this script is to be able to provide to search engines direct access to biblio
83 records. It avoid leaving search engine browsing Koha OPAC and so generating
84 a lot of traffic, and workload, for a bad result.
85
86 A file name F<sitemapindex.xml> is generated. It contains references to Sitemap
87 multiples files. Each file contains at most 50,000 urls, and is named
88 F<sitemapXXXX.xml>.
89
90 The files must be stored on Koha OPAC root directory, ie
91 F<<koha-root>/koha-tmpl/>. Place also in this directory a F<robots.txt> file
92 like this one:
93
94  Sitemap: sitemapindex.xml
95  User-agent: *
96  Disallow: /cgi-bin/
97
98 =head1 PARAMETERS
99
100 =over
101
102 =item B<--url=Koha OPAC base URL>
103
104 If omitted, OPACBaseURL syspref is used.
105
106 =item B<--short|noshort>
107
108 By default, --short. With --short, URL to bib record ends with
109 /bib/biblionumber. With --noshort, URL ends with
110 /cgi-bin/koha/opac-detail.pl?biblionumber=bibnum
111
112 =item B<--dir>
113
114 Directory where to write sitemap files. By default, the current directory.
115
116 =item B<--verbose|-v>
117
118 Enable script verbose mode: a message is displayed for each 10,000 biblio
119 records processed.
120
121 =item B<--help|-h>
122
123 Print this help page.
124
125 =back
126
127 =cut