Bug 28772: Update existing keys [STABLE]

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
This commit is contained in:
Tomas Cohen Arazi 2021-08-30 11:08:30 -03:00 committed by Fridolin Somers
parent b1e38353f9
commit cf7a741381
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
$DBversion = 'XXX';
if( CheckVersion( $DBversion ) ) {
use Koha::AuthUtils qw(hash_password);
my $sth = $dbh->prepare(q{
SELECT client_id, secret
FROM api_keys
});
$sth->execute;
my $results = $sth->fetchall_arrayref({});
$sth = $dbh->prepare(q{
UPDATE api_keys
SET
secret = ?
WHERE
client_id = ?
});
foreach my $api_key (@$results) {
my $digest = Koha::AuthUtils::hash_password( $api_key->{secret} );
$sth->execute( $digest, $api_key->{client_id} );
}
NewVersion( $DBversion, 28772, "Store hashed API key secrets" );
}