Skip to content

Commit 9b0c7af

Browse files
committed
WIP: Converted Script::Author
This is probably broken, now missing the Document validation and data extraction.
1 parent f49c2a8 commit 9b0c7af

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

lib/MetaCPAN/Script/Author.pm

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,23 @@ sub run {
3838

3939
sub index_authors {
4040
my $self = shift;
41-
my $type = $self->index->type('author');
4241
my $authors = XMLin( $self->author_fh )->{cpanid};
4342
my $count = keys %$authors;
4443
log_debug {"Counting author"};
4544
log_info {"Indexing $count authors"};
4645

4746
log_debug {"Getting last update dates"};
48-
my $dates
49-
= $type->raw->filter( { exists => { field => 'updated' } } )
50-
->size(10000)->all;
47+
my $dates = $self->es->search(
48+
index => $self->index_name,
49+
type => 'author',
50+
size => 10000,
51+
body => {
52+
query => {
53+
exists => { field => 'updated' }
54+
},
55+
},
56+
);
57+
5158
$dates = {
5259
map {
5360
$_->{pauseid} =>
@@ -98,28 +105,30 @@ sub index_authors {
98105
$put->{is_pause_custodial_account} = 1
99106
if $name and $name =~ /\(PAUSE Custodial Account\)/;
100107

101-
# Now check the format we have is actually correct
102-
my @errors = MetaCPAN::Document::Author->validate($put);
103-
next if scalar @errors;
108+
# Removing usage of EsX::Model - need to replace document functionality
109+
#
110+
# Now check the format we have is actually correct
111+
# my @errors = MetaCPAN::Document::Author->validate($put);
112+
# next if scalar @errors;
104113

105-
my $author = $type->new_document($put);
106-
$author->gravatar_url; # build gravatar_url
114+
$put->{gravatar_url}
115+
= get_gravatar_url( $put->{pauseid} ); # build gravatar_url
107116

108117
# Do not import lat / lon's in the wrong order, or just invalid
109-
if ( my $loc = $author->{location} ) {
118+
if ( my $loc = $put->{location} ) {
110119

111120
my $lat = $loc->[1];
112121
my $lon = $loc->[0];
113122

114123
if ( $lat > 90 or $lat < -90 ) {
115124

116125
# Invalid latitude
117-
delete $author->{location};
126+
delete $put->{location};
118127
}
119128
elsif ( $lon > 180 or $lon < -180 ) {
120129

121130
# Invalid longitude
122-
delete $author->{location};
131+
delete $put->{location};
123132
}
124133
}
125134

@@ -185,6 +194,26 @@ sub author_config {
185194
return $author;
186195
}
187196

197+
sub get_gravatar_url {
198+
my $pauseid = shift;
199+
200+
# We do not use the author personal address ($self->email[0])
201+
# because we want to show the author's CPAN identity.
202+
# Using another e-mail than the CPAN one removes flexibility for
203+
# the author and ultimately could be a privacy leak.
204+
# The author can manage this identity both on his gravatar account
205+
# (by assigning an image to his [email protected])
206+
# and now by changing this URL from metacpa.org
207+
return Gravatar::URL::gravatar_url(
208+
email => $pauseid . '@cpan.org',
209+
size => 130,
210+
https => 1,
211+
212+
# Fallback to a generated image
213+
default => 'identicon',
214+
);
215+
}
216+
188217
__PACKAGE__->meta->make_immutable;
189218
1;
190219

0 commit comments

Comments
 (0)