Bug 17600: Standardize our EXPORT_OK
[srvgit] / 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 GetOptions(
33     'verbose'   => \$verbose,
34     'help'      => \$help,
35     'url=s'     => \$url,
36     'dir=s'     => \$dir,
37     'short!'    => \$short,
38 );
39
40 sub usage {
41     pod2usage( -verbose => 2 );
42     exit;
43 }
44
45 usage() if $help;
46
47 unless ($url) {
48     $url = C4::Context->preference("OPACBaseURL");
49     unless ($url) {
50         say "OPACBaseURL syspref isn't defined. You can use --url parameter.";
51         exit;
52     }
53 }
54 $url =~ s/\/*$//g;
55
56 my $sitemapper = Koha::Sitemapper->new(
57     verbose => $verbose,
58     url     => $url,
59     dir     => $dir,
60     short   => $short,
61 );
62 $sitemapper->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 --dir /home/koha/mylibrary/www
77   sitemap.pl --url opac.myDNSname.org
78
79 =head1 DESCRIPTION
80
81 Process all biblio records from a Koha instance and generate Sitemap files
82 complying with this protocol as described on L<http://sitemaps.org>. The goal of
83 this script is to be able to provide to search engines direct access to biblio
84 records. It avoid leaving search engine browsing Koha OPAC and so generating
85 a lot of traffic, and workload, for a bad result.
86
87 A file name F<sitemapindex.xml> is generated. It contains references to Sitemap
88 multiples files. Each file contains at most 50,000 urls, and is named
89 F<sitemapXXXX.xml>.
90
91 The files must be stored on Koha OPAC root directory, ie
92 F<<koha-root>/koha-tmpl/>. Place also in this directory a F<robots.txt> file
93 like this one:
94
95  Sitemap: sitemapindex.xml
96  User-agent: *
97  Disallow: /cgi-bin/
98
99 =head1 PARAMETERS
100
101 =over
102
103 =item B<--url=Koha OPAC base URL>
104
105 If omitted, OPACBaseURL syspref is used.
106
107 =item B<--short|noshort>
108
109 By default, --short. With --short, URL to bib record ends with
110 /bib/biblionumber. With --noshort, URL ends with
111 /cgi-bin/koha/opac-detail.pl?biblionumber=bibnum
112
113 =item B<--dir>
114
115 Directory where to write sitemap files. By default, the current directory.
116
117 =item B<--verbose|-v>
118
119 Enable script verbose mode: a message is displayed for each 10,000 biblio
120 records processed.
121
122 =item B<--help|-h>
123
124 Print this help page.
125
126 =back
127
128 =cut