Skip to content

Commit 3d9ca40

Browse files
authored
Merge pull request #1008 from metacpan/mickey/author_script_updates
Author script updates
2 parents 4c0af7b + e759491 commit 3d9ca40

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

lib/MetaCPAN/Script/Author.pm

+26-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use Log::Contextual qw( :log );
1515
use MetaCPAN::Document::Author ();
1616
use URI ();
1717
use XML::Simple qw( XMLin );
18+
use MetaCPAN::Types::TypeTiny qw( Str );
1819

1920
=head1 SYNOPSIS
2021
@@ -29,6 +30,11 @@ has author_fh => (
2930
default => sub { shift->cpan . '/authors/00whois.xml' },
3031
);
3132

33+
has pauseid => (
34+
is => 'ro',
35+
isa => Str,
36+
);
37+
3238
sub run {
3339
my $self = shift;
3440

@@ -46,9 +52,14 @@ sub index_authors {
4652
my $self = shift;
4753
my $type = $self->index->type('author');
4854
my $authors = XMLin( $self->author_fh )->{cpanid};
49-
my $count = keys %$authors;
50-
log_debug {"Counting author"};
51-
log_info {"Indexing $count authors"};
55+
if ( $self->pauseid ) {
56+
log_info {"Indexing 1 author"};
57+
}
58+
else {
59+
my $count = keys %$authors;
60+
log_debug {"Counting author"};
61+
log_info {"Indexing $count authors"};
62+
}
5263

5364
log_debug {"Getting last update dates"};
5465
my $dates
@@ -70,19 +81,25 @@ sub index_authors {
7081

7182
my @author_ids_to_purge;
7283

73-
while ( my ( $pauseid, $data ) = each %$authors ) {
84+
for my $pauseid ( keys %$authors ) {
85+
next if ( $self->pauseid and $self->pauseid ne $pauseid );
86+
my $data = $authors->{$pauseid};
7487
my ( $name, $email, $homepage, $asciiname )
7588
= ( @$data{qw(fullname email homepage asciiname)} );
7689
$name = undef if ( ref $name );
7790
$asciiname = q{} unless defined $asciiname;
7891
$email = lc($pauseid) . '@cpan.org'
7992
unless ( $email && Email::Valid->address($email) );
93+
my $is_pause_custodial_account
94+
= ( $name && $name =~ /\(PAUSE Custodial Account\)/ );
8095
log_debug {
8196
Encode::encode_utf8(
8297
sprintf( "Indexing %s: %s <%s>", $pauseid, $name, $email ) );
8398
};
84-
my $conf = $self->author_config( $pauseid, $dates ) || next;
85-
my $put = {
99+
my $conf = $self->author_config( $pauseid, $dates );
100+
next unless ( $conf or $is_pause_custodial_account );
101+
$conf ||= {};
102+
my $put = {
86103
pauseid => $pauseid,
87104
name => $name,
88105
asciiname => ref $asciiname ? undef : $asciiname,
@@ -101,8 +118,7 @@ sub index_authors {
101118
grep {$_} @{ $put->{website} }
102119
];
103120

104-
$put->{is_pause_custodial_account} = 1
105-
if $name and $name =~ /\(PAUSE Custodial Account\)/;
121+
$put->{is_pause_custodial_account} = 1 if $is_pause_custodial_account;
106122

107123
# Now check the format we have is actually correct
108124
my @errors = MetaCPAN::Document::Author->validate($put);
@@ -140,6 +156,7 @@ sub index_authors {
140156
}
141157
);
142158
}
159+
143160
$bulk->flush;
144161
$self->index->refresh;
145162

@@ -163,7 +180,7 @@ sub author_config {
163180
# Get the most recent version
164181
my ($file)
165182
= sort { $dir->child($b)->stat->mtime <=> $dir->child($a)->stat->mtime }
166-
grep {m/author-.*?\.json/} readdir($dh);
183+
grep {m/author-.*?\.json/} readdir($dh);
167184
return $fallback unless ($file);
168185
$file = $dir->child($file);
169186
return $fallback if !-e $file;

0 commit comments

Comments
 (0)