View | Details | Raw Unified | Return to bug 18230
Collapse All | Expand All

(-)a/Koha/Patron/Modification.pm (+24 lines)
Lines 27-32 use Koha::Patron::Modifications; Link Here
27
# TODO: Remove once Koha::Patron::Attribute(s) is implemented
27
# TODO: Remove once Koha::Patron::Attribute(s) is implemented
28
use C4::Members::Attributes qw( SetBorrowerAttributes );
28
use C4::Members::Attributes qw( SetBorrowerAttributes );
29
29
30
use Digest::MD5 qw( md5_hex );
30
use JSON;
31
use JSON;
31
use Try::Tiny;
32
use Try::Tiny;
32
33
Lines 40-45 Koha::Patron::Modification - Class represents a request to modify or create a pa Link Here
40
41
41
=cut
42
=cut
42
43
44
=head2 new
45
46
=cut
47
48
sub new {
49
    my $class = shift;
50
    my ($attributes) = @_;
51
52
    # Generate a verification_token unless provided
53
    if ( ref $attributes && !$attributes->{verification_token} ) {
54
        my $verification_token = md5_hex( time().{}.rand().{}.$$ );
55
        while ( Koha::Patron::Modifications->search( {
56
                    verification_token => $verification_token
57
                } )->count()
58
        ) {
59
            $verification_token = md5_hex( time().{}.rand().{}.$$ );
60
        }
61
        $attributes->{verification_token} = $verification_token;
62
    }
63
64
    return $class->SUPER::new(@_);
65
}
66
43
=head2 store
67
=head2 store
44
68
45
=cut
69
=cut
(-)a/t/db_dependent/Koha/Patron/Modifications.t (-2 / +13 lines)
Lines 40-46 my $builder = t::lib::TestBuilder->new; Link Here
40
40
41
subtest 'new() tests' => sub {
41
subtest 'new() tests' => sub {
42
42
43
    plan tests => 3;
43
    plan tests => 4;
44
44
45
    $schema->storage->txn_begin;
45
    $schema->storage->txn_begin;
46
46
Lines 77-82 subtest 'new() tests' => sub { Link Here
77
        'Exception carries the right message'
77
        'Exception carries the right message'
78
    );
78
    );
79
79
80
    # Create new pending modification, let verification_token be generated
81
    # automatically
82
    Koha::Patron::Modification->new(
83
        {
84
            surname            => 'Koha-Suomi',
85
            firstname          => 'Suha-Koomi',
86
        }
87
    )->store();
88
    $borrower = Koha::Patron::Modifications->find(
89
        { surname => 'Koha-Suomi' } );
90
    ok(length($borrower->verification_token) > 0, 'Verification token generated.');
91
80
    $schema->storage->txn_rollback;
92
    $schema->storage->txn_rollback;
81
};
93
};
82
94
83
- 

Return to bug 18230