View | Details | Raw Unified | Return to bug 33871
Collapse All | Expand All

(-)a/Koha/Sitemapper.pm (-12 / +11 lines)
Lines 18-27 package Koha::Sitemapper; Link Here
18
# You should have received a copy of the GNU General Public License
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>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Moo;
22
use Modern::Perl;
21
use Modern::Perl;
22
use Moo;
23
24
use Koha::Biblios;
23
use Koha::Sitemapper::Writer;
25
use Koha::Sitemapper::Writer;
24
use C4::Context;
25
26
26
27
27
has url => ( is => 'rw', );
28
has url => ( is => 'rw', );
Lines 50-67 has count => ( is => 'rw', default => sub { 0 } ); Link Here
50
51
51
52
52
sub run {
53
sub run {
53
    my $self = shift;
54
    my ( $self, $where ) = @_;
55
    my $filter = $where ? \$where : {};
54
56
55
    say "Creation of Sitemap files in '" . $self->dir . "' directory"
57
    say "Creation of Sitemap files in '" . $self->dir . "' directory"
56
        if $self->verbose;
58
        if $self->verbose;
57
59
58
    $self->writer( Koha::Sitemapper::Writer->new( sitemapper => $self ) );
60
    $self->writer( Koha::Sitemapper::Writer->new( sitemapper => $self ) );
59
    my $sth = C4::Context->dbh->prepare(
61
    my $rs = Koha::Biblios->search( $filter, { columns => [ qw/biblionumber timestamp/ ] });
60
         "SELECT biblionumber, timestamp FROM biblio" );
61
    $sth->execute();
62
    $self->sth($sth);
63
62
64
    while ( $self->process() ) {
63
    while ( $self->process($rs) ) {
65
        say "..... ", $self->count
64
        say "..... ", $self->count
66
            if $self->verbose && $self->count % 10000 == 0;
65
            if $self->verbose && $self->count % 10000 == 0;
67
    }
66
    }
Lines 69-78 sub run { Link Here
69
68
70
69
71
sub process {
70
sub process {
72
    my $self = shift;
71
    my ( $self, $rs ) = @_;
73
72
74
    my ($biblionumber, $timestamp) = $self->sth->fetchrow;
73
    my $biblio = $rs->next;
75
    unless ($biblionumber) {
74
    unless( $biblio ) {
76
        $self->writer->end();
75
        $self->writer->end();
77
        say "Number of biblio records processed: ", $self->count, "\n" .
76
        say "Number of biblio records processed: ", $self->count, "\n" .
78
            "Number of Sitemap files:            ", $self->writer->count
77
            "Number of Sitemap files:            ", $self->writer->count
Lines 80-86 sub process { Link Here
80
        return;
79
        return;
81
    }
80
    }
82
81
83
    $self->writer->write($biblionumber, $timestamp);
82
    $self->writer->write( $biblio->biblionumber, $biblio->timestamp );
84
    $self->count( $self->count + 1 );
83
    $self->count( $self->count + 1 );
85
    return $self->count;
84
    return $self->count;
86
}
85
}
(-)a/misc/cronjobs/sitemap.pl (-3 / +9 lines)
Lines 29-40 use Koha::Sitemapper; Link Here
29
29
30
30
31
my ($verbose, $help, $url, $dir, $short) = (0, 0, '', '.', 1);
31
my ($verbose, $help, $url, $dir, $short) = (0, 0, '', '.', 1);
32
my $where;
32
GetOptions(
33
GetOptions(
33
    'verbose'   => \$verbose,
34
    'verbose'   => \$verbose,
34
    'help'      => \$help,
35
    'help'      => \$help,
35
    'url=s'     => \$url,
36
    'url=s'     => \$url,
36
    'dir=s'     => \$dir,
37
    'dir=s'     => \$dir,
37
    'short!'    => \$short,
38
    'short!'    => \$short,
39
    'where=s'   => \$where,
38
);
40
);
39
41
40
sub usage {
42
sub usage {
Lines 59-72 my $sitemapper = Koha::Sitemapper->new( Link Here
59
    dir     => $dir,
61
    dir     => $dir,
60
    short   => $short,
62
    short   => $short,
61
);
63
);
62
$sitemapper->run();
64
$sitemapper->run($where);
63
65
64
66
65
=head1 USAGE
67
=head1 USAGE
66
68
67
=over
69
=over
68
70
69
=item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir]
71
=item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir|--where ]
70
72
71
=back
73
=back
72
74
Lines 75-80 $sitemapper->run(); Link Here
75
  sitemap.pl --verbose
77
  sitemap.pl --verbose
76
  sitemap.pl --noshort --dir /home/koha/mylibrary/www
78
  sitemap.pl --noshort --dir /home/koha/mylibrary/www
77
  sitemap.pl --url opac.myDNSname.org
79
  sitemap.pl --url opac.myDNSname.org
80
  sitemap.pl --where 'biblionumber<100'
78
81
79
=head1 DESCRIPTION
82
=head1 DESCRIPTION
80
83
Lines 123-128 records processed. Link Here
123
126
124
Print this help page.
127
Print this help page.
125
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
126
=back
133
=back
127
134
128
=cut
135
=cut
129
- 

Return to bug 33871