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

(-)a/Koha/Borrower/Modifications.pm (-27 / +12 lines)
Lines 28-48 use C4::Context; Link Here
28
use C4::Debug;
28
use C4::Debug;
29
use C4::SQLHelper qw(InsertInTable UpdateInTable);
29
use C4::SQLHelper qw(InsertInTable UpdateInTable);
30
30
31
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
32
33
BEGIN {
34
35
    # set the version for version checking
36
    $VERSION = 0.01;
37
    require Exporter;
38
    @ISA    = qw(Exporter);
39
    @EXPORT = qw(
40
41
    );
42
43
    my $debug = C4::Context->preference("DebugLevel");
44
}
45
46
sub new {
31
sub new {
47
    my ( $class, %args ) = @_;
32
    my ( $class, %args ) = @_;
48
    my $self = bless( {}, $class );
33
    my $self = bless( {}, $class );
Lines 50-61 sub new { Link Here
50
    $self->{'verification_token'} = $args{'verification_token'};
35
    $self->{'verification_token'} = $args{'verification_token'};
51
    $self->{'borrowernumber'}     = $args{'borrowernumber'};
36
    $self->{'borrowernumber'}     = $args{'borrowernumber'};
52
37
53
    return $self;
38
    return bless( \%args, $class );
54
}
39
}
55
40
56
=head AddModifications
41
=head AddModifications
57
42
58
Koha::Borrower::Modifications->AddModifications( %data );
43
Koha::Borrower::Modifications->AddModifications( $data );
59
44
60
Adds or updates modifications for a borrower.
45
Adds or updates modifications for a borrower.
61
46
Lines 65-77 to be part of the passed in hash. Link Here
65
=cut
50
=cut
66
51
67
sub AddModifications {
52
sub AddModifications {
68
    my ( $self, %data ) = @_;
53
    my ( $self, $data ) = @_;
69
54
70
    if ( $self->{'borrowernumber'} ) {
55
    if ( $self->{'borrowernumber'} ) {
71
        delete $data{'borrowernumber'};
56
        delete $data->{'borrowernumber'};
72
57
73
        if ( keys %data ) {
58
        if ( keys %$data ) {
74
            $data{'borrowernumber'} = $self->{'borrowernumber'};
59
            $data->{'borrowernumber'} = $self->{'borrowernumber'};
75
            my $dbh = C4::Context->dbh;
60
            my $dbh = C4::Context->dbh;
76
61
77
            my $query = "
62
            my $query = "
Lines 85-104 sub AddModifications { Link Here
85
            my $result = $sth->fetchrow_hashref();
70
            my $result = $sth->fetchrow_hashref();
86
71
87
            if ( $result->{'count'} ) {
72
            if ( $result->{'count'} ) {
88
                $data{'verification_token'} = q{};
73
                $data->{'verification_token'} = q{};
89
                return UpdateInTable( "borrower_modifications", \%data );
74
                return UpdateInTable( "borrower_modifications", $data );
90
            }
75
            }
91
            else {
76
            else {
92
                return InsertInTable( "borrower_modifications", \%data );
77
                return InsertInTable( "borrower_modifications", $data );
93
            }
78
            }
94
        }
79
        }
95
80
96
    }
81
    }
97
    elsif ( $self->{'verification_token'} ) {
82
    elsif ( $self->{'verification_token'} ) {
98
        delete $data{'borrowernumber'};
83
        delete $data->{'borrowernumber'};
99
        $data{'verification_token'} = $self->{'verification_token'};
84
        $data->{'verification_token'} = $self->{'verification_token'};
100
85
101
        return InsertInTable( "borrower_modifications", \%data );
86
        return InsertInTable( "borrower_modifications", $data );
102
    }
87
    }
103
    else {
88
    else {
104
        return;
89
        return;
(-)a/opac/opac-memberentry.pl (-2 / +2 lines)
Lines 95-101 if ( $action eq 'create' ) { Link Here
95
95
96
            Koha::Borrower::Modifications->new(
96
            Koha::Borrower::Modifications->new(
97
                verification_token => $verification_token )
97
                verification_token => $verification_token )
98
              ->AddModifications(%borrower);
98
              ->AddModifications(\%borrower);
99
99
100
            #Send verification email
100
            #Send verification email
101
            my $letter = C4::Letters::GetPreparedLetter(
101
            my $letter = C4::Letters::GetPreparedLetter(
Lines 161-167 elsif ( $action eq 'update' ) { Link Here
161
      Koha::Borrower::Modifications->new( borrowernumber => $borrowernumber );
161
      Koha::Borrower::Modifications->new( borrowernumber => $borrowernumber );
162
162
163
    $m->DelModifications;
163
    $m->DelModifications;
164
    $m->AddModifications(%borrower);
164
    $m->AddModifications(\%borrower);
165
}
165
}
166
elsif ($borrowernumber) {    #Display logged in borrower's data
166
elsif ($borrowernumber) {    #Display logged in borrower's data
167
    $action = 'edit';
167
    $action = 'edit';
(-)a/t/db_dependent/Koha_borrower_modifications.t (-1 / +94 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 14;
5
6
use C4::Context;
7
use C4::Members;
8
9
use Koha::Borrower::Modifications;
10
11
C4::Context->dbh->do("TRUNCATE TABLE borrower_modifications");
12
13
## Create new pending modification
14
Koha::Borrower::Modifications->new( verification_token => '1234567890' )->AddModifications({ surname => 'Hall', firstname => 'Kyle' });
15
16
## Get the new pending modification
17
my $borrower = Koha::Borrower::Modifications->GetModifications(
18
    verification_token => '1234567890'
19
);
20
21
## Verify we get the same data
22
ok( $borrower->{'surname'} = 'Hall' );
23
24
## Check the Verify method
25
ok( Koha::Borrower::Modifications->Verify( '1234567890' ) );
26
27
## Delete the pending modification
28
$borrower = Koha::Borrower::Modifications->DelModifications(
29
    verification_token => '1234567890'
30
);
31
32
## Verify it's no longer in the database
33
$borrower = Koha::Borrower::Modifications->GetModifications(
34
    verification_token => '1234567890'
35
);
36
ok( !defined( $borrower->{'surname'} ) );
37
38
## Check the Verify method
39
ok( !Koha::Borrower::Modifications->Verify( '1234567890' ) );
40
41
## Create new pending modification, but for an existing borrower
42
Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications({ surname => 'Hall', firstname => 'Kyle' });
43
44
## Test the counter
45
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1 );
46
47
## Create new pending modification for another existing borrower
48
Koha::Borrower::Modifications->new( borrowernumber => '3' )->AddModifications({ surname => 'Smith', firstname => 'Sandy' });
49
50
## Test the counter
51
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 2 );
52
53
## Check GetPendingModifications
54
my $pending = Koha::Borrower::Modifications->GetPendingModifications();
55
ok( $pending->[0]->{'firstname'} eq 'Kyle' );
56
ok( $pending->[1]->{'firstname'} eq 'Sandy' );
57
58
## This should delete the row from the table
59
Koha::Borrower::Modifications->DenyModifications( '3' );
60
61
## Test the counter
62
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1 );
63
64
## Save a copy of the borrowers original data
65
my $old_borrower = GetMember(borrowernumber => '2' );
66
67
## Apply the modifications
68
Koha::Borrower::Modifications->ApproveModifications( '2' );
69
70
## Test the counter
71
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 0 );
72
73
## Get a copy of the borrowers current data
74
my $new_borrower = GetMember(borrowernumber => '2' );
75
76
## Check to see that the approved modifications were saved
77
ok( $new_borrower->{'surname'} eq 'Hall' );
78
79
## Now let's put it back the way it was
80
Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications({ surname => $old_borrower->{'surname'}, firstname => $old_borrower->{'firstname'}  });
81
82
## Test the counter
83
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1 );
84
85
## Apply the modifications
86
Koha::Borrower::Modifications->ApproveModifications( '2' );
87
88
## Test the counter
89
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 0 );
90
91
$new_borrower = GetMember(borrowernumber => '2' );
92
93
## Test to verify the borrower has been updated with the original values
94
ok( $new_borrower->{'surname'} eq $old_borrower->{'surname'} );

Return to bug 7067