Bug 25592: Add Devinim to about page
[koha.git] / Koha / Sitemapper.pm
blobeab42f35ba7435ef73999e6827dc12dffe9c29c3
1 package Koha::Sitemapper;
4 # Copyright 2015 Tamil s.a.r.l.
6 # This file is part of Koha.
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.
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.
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>.
21 use Moo;
22 use Modern::Perl;
23 use Koha::Sitemapper::Writer;
24 use C4::Context;
27 has url => ( is => 'rw', );
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;
41 has short => ( is => 'rw', default => sub { 1 } );
43 has verbose => ( is => 'rw', default => sub { 0 } );
45 has sth => ( is => 'rw' );
47 has writer => ( is => 'rw', );
49 has count => ( is => 'rw', default => sub { 0 } );
52 sub run {
53 my $self = shift;
55 say "Creation of Sitemap files in '" . $self->dir . "' directory"
56 if $self->verbose;
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);
64 while ( $self->process() ) {
65 say "..... ", $self->count
66 if $self->verbose && $self->count % 10000 == 0;
71 sub process {
72 my $self = shift;
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;
83 $self->writer->write($biblionumber, $timestamp);
84 $self->count( $self->count + 1 );
85 return $self->count;