From 4fd847b7ae12f4efdbf8c4740fd20a7dccee0849 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 31 May 2023 11:44:26 +0000 Subject: [PATCH] Bug 33871: Use Koha object in Sitemapper, add optional filter Test plan: Run misc/cronjobs/sitemap.pl -where "biblionumber>X" (replace X by some clever value) Verify results by browsing sitemap files. Signed-off-by: Marcel de Rooy Signed-off-by: Pedro Amorim Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- Koha/Sitemapper.pm | 23 +++++++++++------------ misc/cronjobs/sitemap.pl | 11 +++++++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Koha/Sitemapper.pm b/Koha/Sitemapper.pm index eab42f35ba..6c2520781d 100644 --- a/Koha/Sitemapper.pm +++ b/Koha/Sitemapper.pm @@ -18,10 +18,11 @@ package Koha::Sitemapper; # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use Moo; use Modern::Perl; +use Moo; + +use Koha::Biblios; use Koha::Sitemapper::Writer; -use C4::Context; has url => ( is => 'rw', ); @@ -50,18 +51,16 @@ has count => ( is => 'rw', default => sub { 0 } ); sub run { - my $self = shift; + my ( $self, $where ) = @_; + my $filter = $where ? \$where : {}; say "Creation of Sitemap files in '" . $self->dir . "' directory" if $self->verbose; $self->writer( Koha::Sitemapper::Writer->new( sitemapper => $self ) ); - my $sth = C4::Context->dbh->prepare( - "SELECT biblionumber, timestamp FROM biblio" ); - $sth->execute(); - $self->sth($sth); + my $rs = Koha::Biblios->search( $filter, { columns => [ qw/biblionumber timestamp/ ] }); - while ( $self->process() ) { + while ( $self->process($rs) ) { say "..... ", $self->count if $self->verbose && $self->count % 10000 == 0; } @@ -69,10 +68,10 @@ sub run { sub process { - my $self = shift; + my ( $self, $rs ) = @_; - my ($biblionumber, $timestamp) = $self->sth->fetchrow; - unless ($biblionumber) { + my $biblio = $rs->next; + unless( $biblio ) { $self->writer->end(); say "Number of biblio records processed: ", $self->count, "\n" . "Number of Sitemap files: ", $self->writer->count @@ -80,7 +79,7 @@ sub process { return; } - $self->writer->write($biblionumber, $timestamp); + $self->writer->write( $biblio->biblionumber, $biblio->timestamp ); $self->count( $self->count + 1 ); return $self->count; } diff --git a/misc/cronjobs/sitemap.pl b/misc/cronjobs/sitemap.pl index 93abb02ed0..4b4576a567 100755 --- a/misc/cronjobs/sitemap.pl +++ b/misc/cronjobs/sitemap.pl @@ -29,12 +29,14 @@ use Koha::Sitemapper; my ($verbose, $help, $url, $dir, $short) = (0, 0, '', '.', 1); +my $where; GetOptions( 'verbose' => \$verbose, 'help' => \$help, 'url=s' => \$url, 'dir=s' => \$dir, 'short!' => \$short, + 'where=s' => \$where, ); sub usage { @@ -59,14 +61,14 @@ my $sitemapper = Koha::Sitemapper->new( dir => $dir, short => $short, ); -$sitemapper->run(); +$sitemapper->run($where); =head1 USAGE =over -=item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir] +=item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir|--where ] =back @@ -75,6 +77,7 @@ $sitemapper->run(); sitemap.pl --verbose sitemap.pl --noshort --dir /home/koha/mylibrary/www sitemap.pl --url opac.myDNSname.org + sitemap.pl --where 'biblionumber<100' =head1 DESCRIPTION @@ -123,6 +126,10 @@ records processed. Print this help page. +=item B<--where> + +Add a filter to limit the selection of biblio records. May be useful when testing the feature. + =back =cut -- 2.39.5