Bug 34587: Move everything into a ERM/EUsage subfolder
[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
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.
11 #
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.
16 #
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>.
19
20 package Main;
21
22 use Modern::Perl;
23 use utf8;
24 use Pod::Usage qw( pod2usage );
25 use Getopt::Long qw( GetOptions );
26
27 use Koha::Script -cron;
28 use Koha::Sitemapper;
29
30
31 my ($verbose, $help, $url, $dir, $short) = (0, 0, '', '.', 1);
32 my $where;
33 GetOptions(
34     'verbose'   => \$verbose,
35     'help'      => \$help,
36     'url=s'     => \$url,
37     'dir=s'     => \$dir,
38     'short!'    => \$short,
39     'where=s'   => \$where,
40 );
41
42 sub usage {
43     pod2usage( -verbose => 2 );
44     exit;
45 }
46
47 usage() if $help;
48
49 unless ($url) {
50     $url = C4::Context->preference("OPACBaseURL");
51     unless ($url) {
52         say "OPACBaseURL syspref isn't defined. You can use --url parameter.";
53         exit;
54     }
55 }
56 $url =~ s/\/*$//g;
57
58 my $sitemapper = Koha::Sitemapper->new(
59     verbose => $verbose,
60     url     => $url,
61     dir     => $dir,
62     short   => $short,
63 );
64 $sitemapper->run($where);
65
66
67 =head1 USAGE
68
69 =over
70
71 =item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir|--where ]
72
73 =back
74
75 =head1 SYNOPSIS
76
77   sitemap.pl --verbose
78   sitemap.pl --noshort --dir /home/koha/mylibrary/www
79   sitemap.pl --url opac.myDNSname.org
80   sitemap.pl --where 'biblionumber<100'
81
82 =head1 DESCRIPTION
83
84 Process all biblio records from a Koha instance and generate Sitemap files
85 complying with this protocol as described on L<http://sitemaps.org>. The goal of
86 this script is to be able to provide to search engines direct access to biblio
87 records. It avoid leaving search engine browsing Koha OPAC and so generating
88 a lot of traffic, and workload, for a bad result.
89
90 A file name F<sitemapindex.xml> is generated. It contains references to Sitemap
91 multiples files. Each file contains at most 50,000 urls, and is named
92 F<sitemapXXXX.xml>.
93
94 The files must be stored on Koha OPAC root directory, ie
95 F<<koha-root>/koha-tmpl/>. Place also in this directory a F<robots.txt> file
96 like this one:
97
98  Sitemap: sitemapindex.xml
99  User-agent: *
100  Disallow: /cgi-bin/
101
102 =head1 PARAMETERS
103
104 =over
105
106 =item B<--url=Koha OPAC base URL>
107
108 If omitted, OPACBaseURL syspref is used.
109
110 =item B<--short|noshort>
111
112 By default, --short. With --short, URL to bib record ends with
113 /bib/biblionumber. With --noshort, URL ends with
114 /cgi-bin/koha/opac-detail.pl?biblionumber=bibnum
115
116 =item B<--dir>
117
118 Directory where to write sitemap files. By default, the current directory.
119
120 =item B<--verbose|-v>
121
122 Enable script verbose mode: a message is displayed for each 10,000 biblio
123 records processed.
124
125 =item B<--help|-h>
126
127 Print this help page.
128
129 =item B<--where>
130
131 Add a filter to limit the selection of biblio records. May be useful when testing the feature.
132
133 =back
134
135 =cut