Bug 30649: (follow-up) Improve database update

This patch implements the proposed switch to use the standard DB handle
and only require Koha::Encryption if necessary.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2023-06-07 12:42:01 +01:00 committed by Tomas Cohen Arazi
parent 913f351056
commit f8d2291f2e
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -1,7 +1,7 @@
use Modern::Perl;
return {
bug_number => "30649",
bug_number => "30649",
description => "Increase the vendor EDI account password field to 256 characters",
up => sub {
my ($args) = @_;
@ -10,16 +10,17 @@ return {
ALTER TABLE vendor_edi_accounts CHANGE COLUMN `password` `password` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL
});
require Koha::Encryption;
my $e = Koha::Encryption->new;
my $schema = Koha::Database->new()->schema();
my $rs = $schema->resultset('VendorEdiAccount')->search();
while ( my $a = $rs->next() ) {
my $password = $a->password;
$password = $e->encrypt_hex($password);
$a->password($password);
$a->update();
my $edi_vendors =
$dbh->selectall_arrayref( "SELECT * FROM vendor_edit_accounts", { Slice => {} } );
if (@$edi_vendors) {
require Koha::Encryption;
my $e = Koha::Encryption->new;
for my $edi_vendor (@$edi_vendors) {
my $id = $edi_vendor->{id};
my $password = $edi_vendor->{password};
$password = $e->encrypt_hex($password);
$dbh->do("UPDATE edi_vendor_accounts SET password = $password WHERE id = $id");
}
}
},
};