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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2023-05-31 11:44:26 +00:00 committed by Tomas Cohen Arazi
parent 2557ef4e51
commit 4fd847b7ae
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 20 additions and 14 deletions

View file

@ -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 <http://www.gnu.org/licenses>.
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;
}

View file

@ -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