Bug 19074: Fix category display in Batch patron modification.
[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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use Moo;
22 use Modern::Perl;
23 use Koha::Sitemapper::Writer;
24 use C4::Context;
25
26
27 has url => ( is => 'rw', );
28
29 has dir => (
30     is => 'rw',
31     default => sub { '.' },
32     trigger => sub {
33         my ($self, $dir) = @_;
34         unless (-d $dir) {
35             say "This is not a valid directory: $dir";
36             exit;
37         }
38     }
39 );
40
41 has short => ( is => 'rw', default => sub { 1 } );
42
43 has verbose => ( is => 'rw', default => sub { 0 } );
44
45 has sth => ( is => 'rw' );
46
47 has writer => ( is => 'rw', );
48
49 has count => ( is => 'rw', default => sub { 0 } );
50
51
52 sub run {
53     my $self = shift;
54
55     say "Creation of Sitemap files in '" . $self->dir . "' directory"
56         if $self->verbose;
57
58     $self->writer( Koha::Sitemapper::Writer->new( sitemapper => $self ) );
59     my $sth = C4::Context->dbh->prepare(
60          "SELECT biblionumber, timestamp FROM biblio" );
61     $sth->execute();
62     $self->sth($sth);
63
64     while ( $self->process() ) {
65         say "..... ", $self->count
66             if $self->verbose && $self->count % 10000 == 0;
67     }
68 }
69
70
71 sub process {
72     my $self = shift;
73
74     my ($biblionumber, $timestamp) = $self->sth->fetchrow;
75     unless ($biblionumber) {
76         $self->writer->end();
77         say "Number of biblio records processed: ", $self->count, "\n" .
78             "Number of Sitemap files:            ", $self->writer->count
79             if $self->verbose;
80         return;
81     }
82
83     $self->writer->write($biblionumber, $timestamp);
84     $self->count( $self->count + 1 );
85     return $self->count;
86 }
87
88
89 1;