Bug 30719: ILL Batches
[koha.git] / Koha / Sitemapper.pm
1 package Koha::Sitemapper;
2
3 #
4 # Copyright 2015 Tamil s.a.r.l.
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22 use Moo;
23
24 use Koha::Biblios;
25 use Koha::Sitemapper::Writer;
26
27
28 has url => ( is => 'rw', );
29
30 has dir => (
31     is => 'rw',
32     default => sub { '.' },
33     trigger => sub {
34         my ($self, $dir) = @_;
35         unless (-d $dir) {
36             say "This is not a valid directory: $dir";
37             exit;
38         }
39     }
40 );
41
42 has short => ( is => 'rw', default => sub { 1 } );
43
44 has verbose => ( is => 'rw', default => sub { 0 } );
45
46 has sth => ( is => 'rw' );
47
48 has writer => ( is => 'rw', );
49
50 has count => ( is => 'rw', default => sub { 0 } );
51
52
53 sub run {
54     my ( $self, $where ) = @_;
55     my $filter = $where ? \$where : {};
56
57     say "Creation of Sitemap files in '" . $self->dir . "' directory"
58         if $self->verbose;
59
60     $self->writer( Koha::Sitemapper::Writer->new( sitemapper => $self ) );
61     my $rs = Koha::Biblios->search( $filter, { columns => [ qw/biblionumber timestamp/ ] });
62
63     while ( $self->process($rs) ) {
64         say "..... ", $self->count
65             if $self->verbose && $self->count % 10000 == 0;
66     }
67 }
68
69
70 sub process {
71     my ( $self, $rs ) = @_;
72
73     my $biblio = $rs->next;
74     unless( $biblio ) {
75         $self->writer->end();
76         say "Number of biblio records processed: ", $self->count, "\n" .
77             "Number of Sitemap files:            ", $self->writer->count
78             if $self->verbose;
79         return;
80     }
81
82     $self->writer->write( $biblio->biblionumber, $biblio->timestamp );
83     $self->count( $self->count + 1 );
84     return $self->count;
85 }
86
87
88 1;