← 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/Discharge.pm
StatementsExecuted 27 statements in 2.01ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11137µs152µsKoha::Borrower::Discharge::::BEGIN@3Koha::Borrower::Discharge::BEGIN@3
11121µs3.31msKoha::Borrower::Discharge::::countKoha::Borrower::Discharge::count
11116µs48µsKoha::Borrower::Discharge::::BEGIN@10Koha::Borrower::Discharge::BEGIN@10
11112µs33µsKoha::Borrower::Discharge::::BEGIN@4Koha::Borrower::Discharge::BEGIN@4
11112µs93µsKoha::Borrower::Discharge::::BEGIN@5Koha::Borrower::Discharge::BEGIN@5
11112µs14µsKoha::Borrower::Discharge::::BEGIN@12Koha::Borrower::Discharge::BEGIN@12
11110µs30µsKoha::Borrower::Discharge::::BEGIN@13Koha::Borrower::Discharge::BEGIN@13
1117µs116µsKoha::Borrower::Discharge::::BEGIN@9Koha::Borrower::Discharge::BEGIN@9
111100ns100nsKoha::Borrower::Discharge::::BEGIN@6Koha::Borrower::Discharge::BEGIN@6
111100ns100nsKoha::Borrower::Discharge::::BEGIN@8Koha::Borrower::Discharge::BEGIN@8
0000s0sKoha::Borrower::Discharge::::can_be_dischargedKoha::Borrower::Discharge::can_be_discharged
0000s0sKoha::Borrower::Discharge::::dischargeKoha::Borrower::Discharge::discharge
0000s0sKoha::Borrower::Discharge::::generate_as_pdfKoha::Borrower::Discharge::generate_as_pdf
0000s0sKoha::Borrower::Discharge::::get_pendingsKoha::Borrower::Discharge::get_pendings
0000s0sKoha::Borrower::Discharge::::get_validatedKoha::Borrower::Discharge::get_validated
0000s0sKoha::Borrower::Discharge::::is_dischargedKoha::Borrower::Discharge::is_discharged
0000s0sKoha::Borrower::Discharge::::requestKoha::Borrower::Discharge::request
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::Discharge;
2
32164µs2267µs
# spent 152µs (37+115) within Koha::Borrower::Discharge::BEGIN@3 which was called: # once (37µs+115µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 3
use Modern::Perl;
# spent 152µs making 1 call to Koha::Borrower::Discharge::BEGIN@3 # spent 115µs making 1 call to Modern::Perl::import
4265µs254µs
# spent 33µs (12+21) within Koha::Borrower::Discharge::BEGIN@4 which was called: # once (12µs+21µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 4
use CGI;
# spent 33µs making 1 call to Koha::Borrower::Discharge::BEGIN@4 # spent 21µs making 1 call to CGI::import
5288µs2174µs
# spent 93µs (12+81) within Koha::Borrower::Discharge::BEGIN@5 which was called: # once (12µs+81µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 5
use File::Temp qw( :POSIX );
# spent 93µs making 1 call to Koha::Borrower::Discharge::BEGIN@5 # spent 81µs making 1 call to Exporter::import
62100ns2100ns
# spent 100ns within Koha::Borrower::Discharge::BEGIN@6 which was called: # once (100ns+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 6
use Carp;
# spent 100ns making 1 call to Koha::Borrower::Discharge::BEGIN@6 # spent 0s making 1 call to Exporter::import
7
82300ns2100ns
# spent 100ns within Koha::Borrower::Discharge::BEGIN@8 which was called: # once (100ns+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 8
use C4::Templates qw ( gettemplate );
# spent 100ns making 1 call to Koha::Borrower::Discharge::BEGIN@8 # spent 0s making 1 call to Class::Accessor::import
92150µs2226µs
# spent 116µs (7+110) within Koha::Borrower::Discharge::BEGIN@9 which was called: # once (7µs+110µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 9
use C4::Members qw( GetPendingIssues );
# spent 116µs making 1 call to Koha::Borrower::Discharge::BEGIN@9 # spent 110µs making 1 call to Exporter::import
10270µs281µs
# spent 48µs (16+32) within Koha::Borrower::Discharge::BEGIN@10 which was called: # once (16µs+32µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 10
use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
# spent 48µs making 1 call to Koha::Borrower::Discharge::BEGIN@10 # spent 32µs making 1 call to Exporter::import
11
12238µs217µs
# spent 14µs (12+3) within Koha::Borrower::Discharge::BEGIN@12 which was called: # once (12µs+3µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 12
use Koha::Database;
# spent 14µs making 1 call to Koha::Borrower::Discharge::BEGIN@12 # spent 3µs making 1 call to Class::Accessor::import
1321.33ms250µs
# spent 30µs (10+20) within Koha::Borrower::Discharge::BEGIN@13 which was called: # once (10µs+20µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 13
use Koha::DateUtils qw( dt_from_string output_pref );
# spent 30µs making 1 call to Koha::Borrower::Discharge::BEGIN@13 # spent 20µs making 1 call to Exporter::import
14
15167µs3286µsmy $rs = Koha::Database->new->schema->resultset('Discharge');
# spent 265µs making 1 call to DBIx::Class::Schema::resultset # spent 13µs making 1 call to Koha::Database::schema # spent 8µs making 1 call to Class::Accessor::new
16
17
# spent 3.31ms (21µs+3.29) within Koha::Borrower::Discharge::count which was called: # once (21µs+3.29ms) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 70 of mainpage.pl
sub count {
181700ns my ($params) = @_;
191600ns my $values = {};
20
2111µs if( $params->{borrowernumber} ) {
22 $values->{borrower} = $params->{borrowernumber};
23 }
241600ns if( $params->{pending} ) {
2512µs $values->{needed} = { '!=', undef };
261800ns $values->{validated} = undef;
27 }
28 elsif( $params->{validated} ) {
29 $values->{validated} = { '!=', undef };
30 }
31
32128µs33.41ms return $rs->search( $values )->count;
# spent 3.15ms making 1 call to DBIx::Class::ResultSet::count # spent 143µs making 1 call to DBIx::Class::ResultSet::search # spent 113µs making 1 call to DBIx::Class::Storage::DBI::Cursor::DESTROY
33}
34
35sub can_be_discharged {
36 my ($params) = @_;
37 return unless $params->{borrowernumber};
38
39 my $issues = GetPendingIssues( $params->{borrowernumber} );
40 if( @$issues ) {
41 return 0;
42 }
43 else {
44 return 1;
45 }
46}
47
48sub is_discharged {
49 my ($params) = @_;
50 return unless $params->{borrowernumber};
51 my $borrowernumber = $params->{borrowernumber};
52
53
54 my $restricted = Koha::Borrower::Debarments::IsDebarred($borrowernumber);
55 my $validated = get_validated({borrowernumber => $borrowernumber});
56
57 if ($restricted && $validated) {
58 return 1;
59 } else {
60 return 0;
61 }
62}
63
64sub request {
65 my ($params) = @_;
66 my $borrowernumber = $params->{borrowernumber};
67 return unless $borrowernumber;
68 return unless can_be_discharged({ borrowernumber => $borrowernumber });
69
70 return $rs->create({
71 borrower => $borrowernumber,
72 needed => dt_from_string,
73 });
74}
75
76sub discharge {
77 my ($params) = @_;
78 my $borrowernumber = $params->{borrowernumber};
79 return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
80
81 # Cancel reserves
82 my @reserves = GetReservesFromBorrowernumber($borrowernumber);
83 for my $reserve (@reserves) {
84 CancelReserve( { reserve_id => $reserve->{reserve_id} } );
85 }
86
87 # Debar the member
88 Koha::Borrower::Debarments::AddDebarment({
89 borrowernumber => $borrowernumber,
90 type => 'DISCHARGE',
91 });
92
93 # Generate the discharge
94 my $discharge = $rs->search({ borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 });
95 if( $discharge->count > 0 ) {
96 $discharge->update({ validated => dt_from_string });
97 }
98 else {
99 $rs->create({
100 borrower => $borrowernumber,
101 validated => dt_from_string,
102 });
103 }
104}
105
106sub generate_as_pdf {
107 my ($params) = @_;
108 return unless $params->{borrowernumber};
109
110 my $letter = C4::Letters::GetPreparedLetter(
111 module => 'members',
112 letter_code => 'DISCHARGE',
113 tables => { borrowers => $params->{borrowernumber}, branches => $params->{'branchcode'}, },
114 );
115
116 my $today = output_pref( dt_from_string() );
117 $letter->{'title'} =~ s/<<today>>/$today/g;
118 $letter->{'content'} =~ s/<<today>>/$today/g;
119
120 my $tmpl = C4::Templates::gettemplate('batch/print-notices.tt', 'intranet', new CGI);
121 $tmpl->param(
122 stylesheet => C4::Context->preference("NoticeCSS"),
123 today => $today,
124 messages => [$letter],
125 );
126
127 my $html_path = tmpnam() . '.html';
128 my $pdf_path = tmpnam() . '.pdf';
129 my $html_content = $tmpl->output;
130 open my $html_fh, '>:encoding(utf8)', $html_path;
131 say $html_fh $html_content;
132 close $html_fh;
133 my $output = eval { require PDF::FromHTML; return; } || $@;
134 if ($output && $params->{testing}) {
135 carp $output;
136 $pdf_path = undef;
137 }
138 elsif ($output) {
139 die $output;
140 }
141 else {
142 my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
143 $pdf->load_file( $html_path );
144 $pdf->convert;
145 $pdf->write_file( $pdf_path );
146 }
147
148 return $pdf_path;
149}
150
151sub get_pendings {
152 my ($params) = @_;
153 my $branchcode = $params->{branchcode};
154 my $borrowernumber = $params->{borrowernumber};
155
156 my $cond = {
157 'me.needed' => { '!=', undef },
158 'me.validated' => undef,
159 ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
160 ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
161 };
162
163 my @rs = $rs->search( $cond, { join => 'borrower' } );
164 return \@rs;
165}
166
167sub get_validated {
168 my ($params) = @_;
169 my $branchcode = $params->{branchcode};
170 my $borrowernumber = $params->{borrowernumber};
171
172 my $cond = {
173 'me.validated' => { '!=', undef },
174 ( defined $borrowernumber ? ( 'me.borrower' => $borrowernumber ) : () ),
175 ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ),
176 };
177
178 my @rs = $rs->search( $cond, { join => 'borrower' } );
179 return \@rs;
180}
181
182
18314µs1;