File Coverage

blib/lib/CPAN/Testers/Backend/Migrate/MetabaseUsers.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod 0 1 0.0
total 15 16 93.7


line stmt bran cond sub pod time code
1             package CPAN::Testers::Backend::Migrate::MetabaseUsers;
2             our $VERSION = '0.003';
3             # ABSTRACT: Migrate old metabase users to new table for metabase lookups
4              
5             #pod =head1 SYNOPSIS
6             #pod
7             #pod beam run <container> <service>
8             #pod
9             #pod =head1 DESCRIPTION
10             #pod
11             #pod This task migrates the users in the C<metabase.tester_emails> table to the
12             #pod C<cpanstats.metabase_user> table. This makes these users available to the
13             #pod L<CPAN::Testers::Schema> for when new Metabase reports come in.
14             #pod
15             #pod Only the latest name and e-mail address for a given Metabase resource GUID
16             #pod will be migrated.
17             #pod
18             #pod =cut
19              
20 1     1   84396 use CPAN::Testers::Backend::Base 'Runnable';
  1         2  
  1         6  
21             with 'Beam::Runnable';
22              
23             #pod =attr metabase_dbh
24             #pod
25             #pod The L<DBI> object connected to the C<metabase> database.
26             #pod
27             #pod =cut
28              
29             has metabase_dbh => (
30             is => 'ro',
31             isa => InstanceOf['DBI::db'],
32             required => 1,
33             );
34              
35             #pod =attr schema
36             #pod
37             #pod The L<CPAN::Testers::Schema> to write users to.
38             #pod
39             #pod =cut
40              
41             has schema => (
42             is => 'ro',
43             isa => InstanceOf['CPAN::Testers::Schema'],
44             required => 1,
45             );
46              
47 2     2 0 621334 sub run( $self, @args ) {
  2         7  
  2         3  
  2         4  
48 2         25 my @from_users = $self->metabase_dbh->selectall_array( 'SELECT resource,fullname,email FROM testers_email ORDER BY id ASC', { Slice => {} } );
49              
50             # Save the last user for this GUID
51 2         415 my %users;
52 2         9 for \my %user ( @from_users ) {
53 8         21 $users{ $user{resource} } = \%user;
54             }
55              
56             # Update the user in the mapping table
57 2         7 for \my %user ( values %users ) {
58 5         18283 $self->schema->resultset( 'MetabaseUser' )->update_or_create( \%user );
59             }
60             }
61              
62             1;
63              
64             __END__
65              
66             =pod
67              
68             =head1 NAME
69              
70             CPAN::Testers::Backend::Migrate::MetabaseUsers - Migrate old metabase users to new table for metabase lookups
71              
72             =head1 VERSION
73              
74             version 0.003
75              
76             =head1 SYNOPSIS
77              
78             beam run <container> <service>
79              
80             =head1 DESCRIPTION
81              
82             This task migrates the users in the C<metabase.tester_emails> table to the
83             C<cpanstats.metabase_user> table. This makes these users available to the
84             L<CPAN::Testers::Schema> for when new Metabase reports come in.
85              
86             Only the latest name and e-mail address for a given Metabase resource GUID
87             will be migrated.
88              
89             =head1 ATTRIBUTES
90              
91             =head2 metabase_dbh
92              
93             The L<DBI> object connected to the C<metabase> database.
94              
95             =head2 schema
96              
97             The L<CPAN::Testers::Schema> to write users to.
98              
99             =head1 AUTHOR
100              
101             Doug Bell <preaction@cpan.org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             This software is copyright (c) 2017 by Doug Bell.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut