@@ -15,6 +15,7 @@ use Log::Contextual qw( :log );
15
15
use MetaCPAN::Document::Author ();
16
16
use URI ();
17
17
use XML::Simple qw( XMLin ) ;
18
+ use MetaCPAN::Types::TypeTiny qw( Str ) ;
18
19
19
20
=head1 SYNOPSIS
20
21
@@ -29,6 +30,11 @@ has author_fh => (
29
30
default => sub { shift -> cpan . ' /authors/00whois.xml' },
30
31
);
31
32
33
+ has pauseid => (
34
+ is => ' ro' ,
35
+ isa => Str,
36
+ );
37
+
32
38
sub run {
33
39
my $self = shift ;
34
40
@@ -46,9 +52,14 @@ sub index_authors {
46
52
my $self = shift ;
47
53
my $type = $self -> index -> type(' author' );
48
54
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
+ }
52
63
53
64
log_debug {" Getting last update dates" };
54
65
my $dates
@@ -70,19 +81,25 @@ sub index_authors {
70
81
71
82
my @author_ids_to_purge ;
72
83
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 };
74
87
my ( $name , $email , $homepage , $asciiname )
75
88
= ( @$data {qw( fullname email homepage asciiname) } );
76
89
$name = undef if ( ref $name );
77
90
$asciiname = q{ } unless defined $asciiname ;
78
91
$email = lc ($pauseid ) . ' @cpan.org'
79
92
unless ( $email && Email::Valid-> address($email ) );
93
+ my $is_pause_custodial_account
94
+ = ( $name && $name =~ / \( PAUSE Custodial Account\) / );
80
95
log_debug {
81
96
Encode::encode_utf8(
82
97
sprintf ( " Indexing %s : %s <%s >" , $pauseid , $name , $email ) );
83
98
};
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 = {
86
103
pauseid => $pauseid ,
87
104
name => $name ,
88
105
asciiname => ref $asciiname ? undef : $asciiname ,
@@ -101,8 +118,7 @@ sub index_authors {
101
118
grep {$_ } @{ $put -> {website } }
102
119
];
103
120
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 ;
106
122
107
123
# Now check the format we have is actually correct
108
124
my @errors = MetaCPAN::Document::Author-> validate($put );
@@ -140,6 +156,7 @@ sub index_authors {
140
156
}
141
157
);
142
158
}
159
+
143
160
$bulk -> flush;
144
161
$self -> index -> refresh;
145
162
@@ -163,7 +180,7 @@ sub author_config {
163
180
# Get the most recent version
164
181
my ($file )
165
182
= 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 );
167
184
return $fallback unless ($file );
168
185
$file = $dir -> child($file );
169
186
return $fallback if !-e $file ;
0 commit comments