Created
February 18, 2020 12:13
-
-
Save jesusbagpuss/336f505d5b58aa0b55e570b8a7594b34 to your computer and use it in GitHub Desktop.
Find EPrints which have a non-public document who's indexcodes have been added to the full-text index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
### SAVE FILE TO ~/bin/local/eprints_to_reindex, or edit the FindBin path below according to where you've saved it. | |
use FindBin; | |
use lib "$FindBin::Bin/../../perl_lib"; | |
use EPrints; | |
use strict; | |
our $noise = 1; | |
if ( scalar @ARGV < 1 ){ | |
print "Usage: $0 ARCHIVEID [EPrintID]\n"; | |
exit 1; | |
} | |
$|=1; | |
my $repoid = $ARGV[0]; | |
my $eprintid = $ARGV[1]; | |
my $session = new EPrints::Session( 1 , $repoid , $noise ); | |
if( !defined $session ) | |
{ | |
print STDERR "Failed to load repository: $repoid\n"; | |
exit 1; | |
} | |
# get all security types | |
my @types = $session->get_repository->get_types( "security" ); | |
# and remove the public one | |
@types = grep {$_ ne "public"} @types; | |
my $list; | |
if( defined $eprintid ) | |
{ | |
$list = $session->get_repository->dataset( 'eprint' )->search( filters => [ | |
{ meta_fields => [qw/ documents.security /], value=> "@types", match=>"EQ" }, | |
{ meta_fields => [qw/ eprintid /], value => $eprintid }, | |
] ); | |
} | |
else | |
{ | |
$list = $session->get_repository->dataset( 'eprint' )->search( filters => [ | |
{ meta_fields => [qw/ documents.security /], value=> "@types", match=>"EQ" },#, merge=>'ANY' }, | |
] ); | |
} | |
my $count = $list->count(); | |
print "Search found $count items.\n"; | |
$list->map( sub { | |
my $eprint = $_[2] or return; | |
print $eprint->id; | |
my $restricted_docs = 0; | |
foreach my $doc ($eprint->get_all_documents()) | |
{ | |
if( !$doc->is_public ) | |
{ | |
print "\t", $doc->id, "(",$doc->value("security"),")"; | |
$restricted_docs++; | |
} | |
} | |
if( $restricted_docs ) | |
{ | |
$eprint->queue_fulltext(); | |
} | |
print "\t$restricted_docs\n"; | |
} ); | |
$session->terminate(); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment