#!/usr/bin/perl -w use FindBin; use lib "$FindBin::Bin/../perl_lib"; ###################################################################### # # ###################################################################### =pod =for Pod2Wiki =head1 NAME B - Regenerate all the static abstract pages for an EPrint repository =head1 SYNOPSIS B I [B] [I, I, I-I ...] =head1 DESCRIPTION This script recreates every static abstract page for an eprints repository. To save load on the database, as archived data should not change, EPrints creates static webpages containing the summary of each eprint. If you change the way the abstracts are rendered or change the site template then you will want to run this script. To only recreate static abstract pages for certain eprint IDs provide a space separated list of eprint ID integer values. To recreate a tranche of consecutive eprint static abstract pages, use a hyphen between integer values, (e.g. 10-20). =head1 ARGUMENTS =over 8 =item B The ID of the eprint repository to use. =item B An optional integer indicating that the static abstract page for eprint record I should be updated. Multiple I integer values may be provided to regenerate a set of static abstract pages for the specified eprints. To recreate a tranche of consecutive eprint static abstracts pages use a hyphen between integer values, (e.g. 10-20). =back =head1 OPTIONS =over 8 =item B<--help> Print a brief help message and exit. =item B<--man> Print the full manual page and then exit. =item B<--quiet> Be vewwy vewwy quiet. This option will suppress all output unless an error occurs. =item B<--verbose> Explain in detail what is going on. May be repeated for greater effect. =item B<--version> Output version information and exit. =back =cut use EPrints; use strict; use Getopt::Long; use Pod::Usage; my $version = 0; my $verbose = 0; my $quiet = 0; my $help = 0; my $man = 0; Getopt::Long::Configure("permute"); GetOptions( 'help|?' => \$help, 'man' => \$man, 'version' => \$version, 'verbose+' => \$verbose, 'silent' => \$quiet, 'quiet' => \$quiet ) || pod2usage( 2 ); EPrints::Utils::cmd_version( "generate_abstracts" ) if $version; pod2usage( 1 ) if $help; pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; pod2usage( 2 ) if( scalar @ARGV == 0 ); our $noise = 1; $noise = 0 if( $quiet ); $noise = 1+$verbose if( $verbose ); # Set STDOUT to auto flush (without needing a \n) $|=1; my $repoid = shift @ARGV; my $session = new EPrints::Session( 1 , $repoid , $noise ); if( !defined $session ) { print STDERR "Failed to load repository: $repoid\n"; exit 1; } if( defined $ARGV[0] ) { my @eprintids = expand_ids( $session, 'eprint', @ARGV ); foreach my $eprintid ( @eprintids ) { my $eprint = EPrints::DataObj::EPrint->new( $session, $eprintid ); if( !defined $eprint ) { $session->get_repository->log( "EPrint #".$eprintid." not found. Can't write abstract." ); } else { make_static( $session, $eprint->get_dataset, $eprint, {} ); print "Wrote abstract #$eprintid\n" if( $noise > 0); } } } else { print "Writing abstracts\n" if( $noise > 0); my $dataset = $session->dataset( "eprint" ); my $info = { count=>0 }; $dataset->map( $session , \&make_static, $info ); if( $noise > 0) { print "Done writing ".$info->{count}." abstracts\n"; } } $session->terminate(); exit; sub make_static { my( $session, $dataset, $eprint, $info ) = @_; $eprint->clear_citationcaches() if defined $session->config( "citation_caching", "enabled" ) && $session->config( "citation_caching", "enabled" ); $eprint->generate_static(); if( $noise > 1 ) { print "Generated ".$eprint->get_value( "eprintid" )."\n"; } $info->{count}++; } sub expand_ids { my ( $repo, $datasetid, @ids ) = @_; my $dataset = $repo->dataset( $datasetid ); my @all_ids = (); foreach my $id ( @ids ) { if( $id =~ m/^[0-9]+-[0-9]+$/ ) { my $searchexp = new EPrints::Search( session=>$repo, dataset=>$dataset ); $searchexp->add_field( $dataset->key_field, $id ); my $list = $searchexp->perform_search; push @all_ids, @{$list->ids}; } else { push @all_ids, $id; } } return @all_ids; } =head1 COPYRIGHT =for COPYRIGHT BEGIN Copyright 2022 University of Southampton. EPrints 3.4 is supplied by EPrints Services. http://www.eprints.org/eprints-3.4/ =for COPYRIGHT END =for LICENSE BEGIN This file is part of EPrints 3.4 L. EPrints 3.4 and this file are released under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation unless otherwise stated. EPrints 3.4 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with EPrints 3.4. If not, see L. =for LICENSE END