Bug 28772: DBRev 21.06.00.026
[koha.git] / installer / data / mysql / db_revs / 210600026.pl
1 use Modern::Perl;
2
3 return {
4     bug_number  => "28772",
5     description => "Store hashed API key secrets",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh) = @$args{qw(dbh)};
9
10         use Koha::AuthUtils qw(hash_password);
11
12         my $sth = $dbh->prepare(q{
13             SELECT client_id, secret
14             FROM api_keys
15         });
16         $sth->execute;
17         my $results = $sth->fetchall_arrayref({});
18
19         $sth = $dbh->prepare(q{
20             UPDATE api_keys
21             SET
22                 secret = ?
23             WHERE
24                 client_id = ?
25         });
26
27         foreach my $api_key (@$results) {
28             unless ( $api_key->{secret} =~ m/^\$2a\$08\$/ ) {
29                 my $digest = Koha::AuthUtils::hash_password( $api_key->{secret} );
30                 $sth->execute( $digest, $api_key->{client_id} );
31             }
32         }
33     },
34 }