@@ -, +, @@ Koha::Patron::Modification->new --- Koha/Patron/Modification.pm | 24 ++++++++++++++++++++++++ t/db_dependent/Koha/Patron/Modifications.t | 14 +++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) --- a/Koha/Patron/Modification.pm +++ a/Koha/Patron/Modification.pm @@ -27,6 +27,7 @@ use Koha::Patron::Modifications; # TODO: Remove once Koha::Patron::Attribute(s) is implemented use C4::Members::Attributes qw( SetBorrowerAttributes ); +use Digest::MD5 qw( md5_hex ); use JSON; use Try::Tiny; @@ -40,6 +41,29 @@ Koha::Patron::Modification - Class represents a request to modify or create a pa =cut +=head2 new + +=cut + +sub new { + my $class = shift; + my ($attributes) = @_; + + # Generate a verification_token unless provided + if ( ref $attributes && !$attributes->{verification_token} ) { + my $verification_token = md5_hex( time().{}.rand().{}.$$ ); + while ( Koha::Patron::Modifications->search( { + verification_token => $verification_token + } )->count() + ) { + $verification_token = md5_hex( time().{}.rand().{}.$$ ); + } + $attributes->{verification_token} = $verification_token; + } + + return $class->SUPER::new(@_); +} + =head2 store =cut --- a/t/db_dependent/Koha/Patron/Modifications.t +++ a/t/db_dependent/Koha/Patron/Modifications.t @@ -40,7 +40,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'new() tests' => sub { - plan tests => 3; + plan tests => 4; $schema->storage->txn_begin; @@ -77,6 +77,18 @@ subtest 'new() tests' => sub { 'Exception carries the right message' ); + # Create new pending modification, let verification_token be generated + # automatically + Koha::Patron::Modification->new( + { + surname => 'Koha-Suomi', + firstname => 'Suha-Koomi', + } + )->store(); + $borrower = Koha::Patron::Modifications->find( + { surname => 'Koha-Suomi' } ); + ok(length($borrower->verification_token) > 0, 'Verification token generated.'); + $schema->storage->txn_rollback; }; --