diff --git a/installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl b/installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl new file mode 100644 index 0000000000..4fd6b399f2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl @@ -0,0 +1,8 @@ +if( CheckVersion( $DBversion ) ) { + $dbh->do( "UPDATE borrowers SET login_attempts=0 WHERE login_attempts IS NULL" ); + $dbh->do( "ALTER TABLE borrowers MODIFY COLUMN login_attempts int(4) NOT NULL DEFAULT 0" ); + $dbh->do( "UPDATE deletedborrowers SET login_attempts=0 WHERE login_attempts IS NULL" ); + $dbh->do( "ALTER TABLE deletedborrowers MODIFY COLUMN login_attempts int(4) NOT NULL DEFAULT 0" ); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug XXXXX - Set login_attempts NOT NULL)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 6e87aef416..239b66cb2b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -602,7 +602,7 @@ CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- time of last change could be useful for synchronization with external systems (among others) `lastseen` datetime default NULL, -- last time a patron has been seen (connected at the OPAC or staff interface) `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron - `login_attempts` int(4) default 0, -- number of failed login attemps + `login_attempts` int(4) NOT NULL default 0, -- number of failed login attemps `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization `autorenew_checkouts` TINYINT(1) NOT NULL DEFAULT 1, -- flag for allowing auto-renewal @@ -1522,7 +1522,7 @@ CREATE TABLE `borrowers` ( -- this table includes information about your patrons `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- time of last change could be useful for synchronization with external systems (among others) `lastseen` datetime default NULL, -- last time a patron has been seen (connected at the OPAC or staff interface) `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron - `login_attempts` int(4) default 0, -- number of failed login attemps + `login_attempts` int(4) NOT NULL default 0, -- number of failed login attemps `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization `autorenew_checkouts` TINYINT(1) NOT NULL DEFAULT 1, -- flag for allowing auto-renewal diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 3ffc7ca1c2..86653ebdad 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -14662,10 +14662,10 @@ if( CheckVersion( $DBversion ) ) { $DBversion = '17.06.00.009'; if( CheckVersion( $DBversion ) ) { $dbh->do(q{ - ALTER TABLE borrowers MODIFY COLUMN login_attempts int(4) AFTER lang; + ALTER TABLE borrowers MODIFY COLUMN login_attempts int(4) DEFAULT 0 AFTER lang; }); $dbh->do(q{ - ALTER TABLE deletedborrowers MODIFY COLUMN login_attempts int(4) AFTER lang; + ALTER TABLE deletedborrowers MODIFY COLUMN login_attempts int(4) DEFAULT 0 AFTER lang; }); SetVersion( $DBversion ); diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 63b77c1573..3548e8ca78 100644 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Test::Exception; use Koha::Database; @@ -192,3 +192,22 @@ subtest 'to_api() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'login_attempts tests' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + } + ); + my $patron_info = $patron->unblessed; + $patron->delete; + delete $patron_info->{login_attempts}; + my $new_patron = Koha::Patron->new($patron_info)->store; + is( $new_patron->discard_changes->login_attempts, 0, "login_attempts defaults to 0 as expected"); + + $schema->storage->txn_rollback; +};