← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 14:31:06 2016
Reported on Fri Jan 8 14:33:30 2016

Filename/home/vagrant/kohaclone/Koha/Borrower/Modifications.pm
StatementsExecuted 16 statements in 1.80ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11138µs295µsKoha::Borrower::Modifications::::GetPendingModificationsCountKoha::Borrower::Modifications::GetPendingModificationsCount
11132µs152µsKoha::Borrower::Modifications::::BEGIN@25Koha::Borrower::Modifications::BEGIN@25
11117µs21µsKoha::Borrower::Modifications::::BEGIN@27Koha::Borrower::Modifications::BEGIN@27
11114µs95µsKoha::Borrower::Modifications::::BEGIN@28Koha::Borrower::Modifications::BEGIN@28
0000s0sKoha::Borrower::Modifications::::AddModificationsKoha::Borrower::Modifications::AddModifications
0000s0sKoha::Borrower::Modifications::::ApproveModificationsKoha::Borrower::Modifications::ApproveModifications
0000s0sKoha::Borrower::Modifications::::DelModificationsKoha::Borrower::Modifications::DelModifications
0000s0sKoha::Borrower::Modifications::::DenyModificationsKoha::Borrower::Modifications::DenyModifications
0000s0sKoha::Borrower::Modifications::::GetModificationsKoha::Borrower::Modifications::GetModifications
0000s0sKoha::Borrower::Modifications::::GetPendingModificationsKoha::Borrower::Modifications::GetPendingModifications
0000s0sKoha::Borrower::Modifications::::VerifyKoha::Borrower::Modifications::Verify
0000s0sKoha::Borrower::Modifications::::newKoha::Borrower::Modifications::new
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Koha::Borrower::Modifications;
2
3# Copyright 2012 ByWater Solutions
4# This file is part of Koha.
5#
6# Koha is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
11# Koha is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19=head1 NAME
20
21C4::Borrowers::Modifications
22
23=cut
24
252173µs2271µs
# spent 152µs (32+120) within Koha::Borrower::Modifications::BEGIN@25 which was called: # once (32µs+120µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@31 at line 25
use Modern::Perl;
# spent 152µs making 1 call to Koha::Borrower::Modifications::BEGIN@25 # spent 120µs making 1 call to Modern::Perl::import
26
27250µs225µs
# spent 21µs (17+4) within Koha::Borrower::Modifications::BEGIN@27 which was called: # once (17µs+4µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@31 at line 27
use C4::Context;
# spent 21µs making 1 call to Koha::Borrower::Modifications::BEGIN@27 # spent 4µs making 1 call to C4::Context::import
2821.47ms2176µs
# spent 95µs (14+81) within Koha::Borrower::Modifications::BEGIN@28 which was called: # once (14µs+81µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@31 at line 28
use C4::Debug;
# spent 95µs making 1 call to Koha::Borrower::Modifications::BEGIN@28 # spent 81µs making 1 call to Exporter::import
29
30sub new {
31 my ( $class, %args ) = @_;
32
33 return bless( \%args, $class );
34}
35
36=head2 AddModifications
37
38Koha::Borrower::Modifications->AddModifications( $data );
39
40Adds or updates modifications for a borrower.
41
42Requires either the key borrowernumber, or verification_token
43to be part of the passed in hash.
44
45=cut
46
47sub AddModifications {
48 my ( $self, $data ) = @_;
49
50 delete $data->{borrowernumber};
51 if( $self->{borrowernumber} ) {
52 return if( not keys %$data );
53 $data->{borrowernumber} = $self->{borrowernumber};
54 $data->{verification_token} = '';
55 }
56 elsif( $self->{verification_token} ) {
57 $data->{verification_token} = $self->{verification_token};
58 $data->{borrowernumber} = 0;
59 }
60 else {
61 return;
62 }
63
64 my $rs = Koha::Database->new()->schema->resultset('BorrowerModification');
65 return $rs->update_or_create($data, { key => 'primary' } );
66}
67
68=head2 Verify
69
70$verified = Koha::Borrower::Modifications->Verify( $verification_token );
71
72Returns true if the passed in token is valid.
73
74=cut
75
76sub Verify {
77 my ( $self, $verification_token ) = @_;
78
79 $verification_token =
80 ($verification_token)
81 ? $verification_token
82 : $self->{'verification_token'};
83
84 my $dbh = C4::Context->dbh;
85 my $query = "
86 SELECT COUNT(*) AS count
87 FROM borrower_modifications
88 WHERE verification_token = ?
89 ";
90 my $sth = $dbh->prepare($query);
91 $sth->execute($verification_token);
92 my $result = $sth->fetchrow_hashref();
93
94 return $result->{'count'};
95}
96
97=head2 GetPendingModificationsCount
98
99$count = Koha::Borrower::Modifications->GetPendingModificationsCount();
100
101Returns the number of pending modifications for existing borrowers.
102
103=cut
104
105
# spent 295µs (38+258) within Koha::Borrower::Modifications::GetPendingModificationsCount which was called: # once (38µs+258µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 68 of mainpage.pl
sub GetPendingModificationsCount {
1061600ns my ( $self, $branchcode ) = @_;
107
108110µs1141µs my $dbh = C4::Context->dbh;
# spent 141µs making 1 call to C4::Context::dbh
1091600ns my $query = "
110 SELECT COUNT(*) AS count
111 FROM borrower_modifications, borrowers
112 WHERE borrower_modifications.borrowernumber > 0
113 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
114 ";
115
1161500ns my @params;
1171200ns if ($branchcode) {
118 $query .= " AND borrowers.branchcode = ? ";
119 push( @params, $branchcode );
120 }
121
122114µs267µs my $sth = $dbh->prepare($query);
# spent 40µs making 1 call to DBI::db::prepare # spent 27µs making 1 call to DBD::mysql::db::prepare
123142µs136µs $sth->execute(@params);
# spent 36µs making 1 call to DBI::st::execute
12419µs266µs my $result = $sth->fetchrow_hashref();
# spent 36µs making 1 call to DBI::st::fetchrow_hashref # spent 30µs making 1 call to DBD::mysql::st::__ANON__[DBD/mysql.pm:799]
125
126128µs return $result->{'count'};
127}
128
129=head2 GetPendingModifications
130
131$arrayref = Koha::Borrower::Modifications->GetPendingModifications();
132
133Returns an arrayref of hashrefs for all pending modifications for existing borrowers.
134
135=cut
136
137sub GetPendingModifications {
138 my ( $self, $branchcode ) = @_;
139
140 my $dbh = C4::Context->dbh;
141 my $query = "
142 SELECT borrower_modifications.*
143 FROM borrower_modifications, borrowers
144 WHERE borrower_modifications.borrowernumber > 0
145 AND borrower_modifications.borrowernumber = borrowers.borrowernumber
146 ";
147
148 my @params;
149 if ($branchcode) {
150 $query .= " AND borrowers.branchcode = ? ";
151 push( @params, $branchcode );
152 }
153 $query .= " ORDER BY borrowers.surname, borrowers.firstname";
154 my $sth = $dbh->prepare($query);
155 $sth->execute(@params);
156
157 my @m;
158 while ( my $row = $sth->fetchrow_hashref() ) {
159 foreach my $key ( keys %$row ) {
160 delete $row->{$key} unless defined $row->{$key};
161 }
162
163 push( @m, $row );
164 }
165
166 return \@m;
167}
168
169=head2 ApproveModifications
170
171Koha::Borrower::Modifications->ApproveModifications( $borrowernumber );
172
173Commits the pending modifications to the borrower record and removes
174them from the modifications table.
175
176=cut
177
178sub ApproveModifications {
179 my ( $self, $borrowernumber ) = @_;
180
181 $borrowernumber =
182 ($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'};
183
184 return unless $borrowernumber;
185
186 my $data = $self->GetModifications( { borrowernumber => $borrowernumber } );
187 delete $data->{timestamp};
188 delete $data->{verification_token};
189
190 my $rs = Koha::Database->new()->schema->resultset('Borrower')->search({
191 borrowernumber => $data->{borrowernumber},
192 });
193 if( $rs->update($data) ) {
194 $self->DelModifications( { borrowernumber => $borrowernumber } );
195 }
196}
197
198=head2 DenyModifications
199
200Koha::Borrower::Modifications->DenyModifications( $borrowernumber );
201
202Removes the modifications from the table for the given borrower,
203without commiting the changes to the borrower record.
204
205=cut
206
207sub DenyModifications {
208 my ( $self, $borrowernumber ) = @_;
209
210 $borrowernumber =
211 ($borrowernumber) ? $borrowernumber : $self->{'borrowernumber'};
212
213 return unless $borrowernumber;
214
215 return $self->DelModifications( { borrowernumber => $borrowernumber } );
216}
217
218=head2 DelModifications
219
220Koha::Borrower::Modifications->DelModifications({
221 [ borrowernumber => $borrowernumber ],
222 [ verification_token => $verification_token ]
223});
224
225Deletes the modifications for the given borrowernumber or verification token.
226
227=cut
228
229sub DelModifications {
230 my ( $self, $params ) = @_;
231
232 my ( $field, $value );
233
234 if ( $params->{'borrowernumber'} ) {
235 $field = 'borrowernumber';
236 $value = $params->{'borrowernumber'};
237 }
238 elsif ( $params->{'verification_token'} ) {
239 $field = 'verification_token';
240 $value = $params->{'verification_token'};
241 }
242
243 return unless $value;
244
245 my $dbh = C4::Context->dbh;
246
247 $field = $dbh->quote_identifier($field);
248
249 my $query = "
250 DELETE
251 FROM borrower_modifications
252 WHERE $field = ?
253 ";
254
255 my $sth = $dbh->prepare($query);
256 return $sth->execute($value);
257}
258
259=head2 GetModifications
260
261$hashref = Koha::Borrower::Modifications->GetModifications({
262 [ borrowernumber => $borrowernumber ],
263 [ verification_token => $verification_token ]
264});
265
266Gets the modifications for the given borrowernumber or verification token.
267
268=cut
269
270sub GetModifications {
271 my ( $self, $params ) = @_;
272
273 my ( $field, $value );
274
275 if ( defined( $params->{'borrowernumber'} ) ) {
276 $field = 'borrowernumber';
277 $value = $params->{'borrowernumber'};
278 }
279 elsif ( defined( $params->{'verification_token'} ) ) {
280 $field = 'verification_token';
281 $value = $params->{'verification_token'};
282 }
283
284 return unless $value;
285
286 my $dbh = C4::Context->dbh;
287
288 $field = $dbh->quote_identifier($field);
289
290 my $query = "
291 SELECT *
292 FROM borrower_modifications
293 WHERE $field = ?
294 ";
295
296 my $sth = $dbh->prepare($query);
297 $sth->execute($value);
298 my $data = $sth->fetchrow_hashref();
299
300 foreach my $key ( keys %$data ) {
301 delete $data->{$key} unless ( defined( $data->{$key} ) );
302 }
303
304 return $data;
305}
306
30713µs1;