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

(-)a/Koha/Borrower/Modifications.pm (-36 / +19 lines)
Lines 26-32 use Modern::Perl; Link Here
26
26
27
use C4::Context;
27
use C4::Context;
28
use C4::Debug;
28
use C4::Debug;
29
use C4::SQLHelper qw(InsertInTable UpdateInTable);
30
29
31
sub new {
30
sub new {
32
    my ( $class, %args ) = @_;
31
    my ( $class, %args ) = @_;
Lines 48-89 to be part of the passed in hash. Link Here
48
sub AddModifications {
47
sub AddModifications {
49
    my ( $self, $data ) = @_;
48
    my ( $self, $data ) = @_;
50
49
51
    if ( $self->{'borrowernumber'} ) {
50
    delete $data->{borrowernumber};
52
        delete $data->{'borrowernumber'};
51
    if( $self->{borrowernumber} ) {
53
52
        return if( not keys %$data );
54
        if ( keys %$data ) {
53
        $data->{borrowernumber} = $self->{borrowernumber};
55
            $data->{'borrowernumber'} = $self->{'borrowernumber'};
56
            my $dbh = C4::Context->dbh;
57
58
            my $query = "
59
                SELECT COUNT(*) AS count
60
                FROM borrower_modifications
61
                WHERE borrowernumber = ?
62
            ";
63
64
            my $sth = $dbh->prepare($query);
65
            $sth->execute( $self->{'borrowernumber'} );
66
            my $result = $sth->fetchrow_hashref();
67
68
            if ( $result->{'count'} ) {
69
                $data->{'verification_token'} = q{};
70
                return UpdateInTable( "borrower_modifications", $data );
71
            }
72
            else {
73
                return InsertInTable( "borrower_modifications", $data );
74
            }
75
        }
76
77
    }
54
    }
78
    elsif ( $self->{'verification_token'} ) {
55
    elsif( $self->{verification_token} ) {
79
        delete $data->{'borrowernumber'};
56
        $data->{verification_token} = $self->{verification_token};
80
        $data->{'verification_token'} = $self->{'verification_token'};
81
82
        return InsertInTable( "borrower_modifications", $data );
83
    }
57
    }
84
    else {
58
    else {
85
        return;
59
        return;
86
    }
60
    }
61
62
    my $rs = Koha::Database->new()->schema->resultset('BorrowerModification');
63
    return $rs->update_or_create($data);
87
}
64
}
88
65
89
=head2 Verify
66
=head2 Verify
Lines 120-125 sub Verify { Link Here
120
$count = Koha::Borrower::Modifications->GetPendingModificationsCount();
97
$count = Koha::Borrower::Modifications->GetPendingModificationsCount();
121
98
122
Returns the number of pending modifications for existing borrowers.
99
Returns the number of pending modifications for existing borrowers.
100
123
=cut
101
=cut
124
102
125
sub GetPendingModificationsCount {
103
sub GetPendingModificationsCount {
Lines 203-212 sub ApproveModifications { Link Here
203
181
204
    return unless $borrowernumber;
182
    return unless $borrowernumber;
205
183
206
    my $data = $self->GetModifications({ borrowernumber => $borrowernumber });
184
    my $data = $self->GetModifications( { borrowernumber => $borrowernumber } );
185
    delete $data->{timestamp};
186
    delete $data->{verification_token};
207
187
208
    if ( UpdateInTable( "borrowers", $data ) ) {
188
    my $rs = Koha::Database->new()->schema->resultset('Borrower')->search({
209
        $self->DelModifications({ borrowernumber => $borrowernumber });
189
        borrowernumber => $data->{borrowernumber},
190
    });
191
    if( $rs->update($data) ) {
192
        $self->DelModifications( { borrowernumber => $borrowernumber } );
210
    }
193
    }
211
}
194
}
212
195
Lines 227-233 sub DenyModifications { Link Here
227
210
228
    return unless $borrowernumber;
211
    return unless $borrowernumber;
229
212
230
    return $self->DelModifications({ borrowernumber => $borrowernumber });
213
    return $self->DelModifications( { borrowernumber => $borrowernumber } );
231
}
214
}
232
215
233
=head2 DelModifications
216
=head2 DelModifications
(-)a/t/db_dependent/Koha_borrower_modifications.t (-2 / +7 lines)
Lines 8-14 use C4::Members; Link Here
8
8
9
use Koha::Borrower::Modifications;
9
use Koha::Borrower::Modifications;
10
10
11
C4::Context->dbh->do("TRUNCATE TABLE borrower_modifications");
11
my $dbh = C4::Context->dbh;
12
$dbh->{RaiseError} = 1;
13
$dbh->{AutoCommit} = 0;
14
15
$dbh->do("TRUNCATE TABLE borrower_modifications");
12
16
13
## Create new pending modification
17
## Create new pending modification
14
Koha::Borrower::Modifications->new( verification_token => '1234567890' )
18
Koha::Borrower::Modifications->new( verification_token => '1234567890' )
Lines 123-125 ok( Link Here
123
    $new_borrower->{'surname'} eq $old_borrower->{'surname'},
127
    $new_borrower->{'surname'} eq $old_borrower->{'surname'},
124
    'Test ApproveModifications() applys modification to borrower, again'
128
    'Test ApproveModifications() applys modification to borrower, again'
125
);
129
);
126
- 
130
131
$dbh->rollback();

Return to bug 12623