Bug 28786: (follow-up) Improve style of 2FA code input
[koha.git] / installer / data / mysql / atomicupdate / two-fa.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => 28786,
5     description => "Add syspref TwoFactorAuthentication, fields secret and auth_method",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh, $out) = @$args{qw(dbh out)};
9
10         $dbh->do(q{
11             INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
12             ('TwoFactorAuthentication', '0', 'NULL', 'Enables two-factor authentication', 'YesNo')
13         });
14
15         if( !column_exists( 'borrowers', 'secret' ) ) {
16           $dbh->do(q{
17               ALTER TABLE borrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
18           });
19         }
20
21         if( !column_exists( 'deletedborrowers', 'secret' ) ) {
22           $dbh->do(q{
23               ALTER TABLE deletedborrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
24             });
25         }
26
27         if( !column_exists( 'borrowers', 'auth_method' ) ) {
28           $dbh->do(q{
29               ALTER TABLE borrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
30           });
31         }
32
33         if( !column_exists( 'deletedborrowers', 'auth_method' ) ) {
34           $dbh->do(q{
35               ALTER TABLE deletedborrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
36           });
37         }
38     },
39 };