← 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:31:39 2016

Filename/home/vagrant/kohaclone/Koha/Borrower/Discharge.pm
StatementsExecuted 27 statements in 6.81ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11122µs73µsKoha::Borrower::Discharge::::BEGIN@6Koha::Borrower::Discharge::BEGIN@6
11121µs85µsKoha::Borrower::Discharge::::BEGIN@3Koha::Borrower::Discharge::BEGIN@3
11118µs7.31msKoha::Borrower::Discharge::::countKoha::Borrower::Discharge::count
11118µs170µsKoha::Borrower::Discharge::::BEGIN@9Koha::Borrower::Discharge::BEGIN@9
11115µs26µsKoha::Borrower::Discharge::::BEGIN@8Koha::Borrower::Discharge::BEGIN@8
11114µs122µsKoha::Borrower::Discharge::::BEGIN@5Koha::Borrower::Discharge::BEGIN@5
11113µs31µsKoha::Borrower::Discharge::::BEGIN@4Koha::Borrower::Discharge::BEGIN@4
11112µs42µsKoha::Borrower::Discharge::::BEGIN@10Koha::Borrower::Discharge::BEGIN@10
11110µs30µsKoha::Borrower::Discharge::::BEGIN@13Koha::Borrower::Discharge::BEGIN@13
11110µs12µsKoha::Borrower::Discharge::::BEGIN@12Koha::Borrower::Discharge::BEGIN@12
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
32101µs2150µs
# spent 85µs (21+64) within Koha::Borrower::Discharge::BEGIN@3 which was called: # once (21µs+64µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 3
use Modern::Perl;
# spent 85µs making 1 call to Koha::Borrower::Discharge::BEGIN@3 # spent 64µs making 1 call to Modern::Perl::import
4259µs250µs
# spent 31µs (13+19) within Koha::Borrower::Discharge::BEGIN@4 which was called: # once (13µs+19µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 4
use CGI;
# spent 31µs making 1 call to Koha::Borrower::Discharge::BEGIN@4 # spent 19µs making 1 call to CGI::import
525.04ms2230µs
# spent 122µs (14+108) within Koha::Borrower::Discharge::BEGIN@5 which was called: # once (14µs+108µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 5
use File::Temp qw( :POSIX );
# spent 122µs making 1 call to Koha::Borrower::Discharge::BEGIN@5 # spent 108µs making 1 call to Exporter::import
62108µs2123µs
# spent 73µs (22+50) within Koha::Borrower::Discharge::BEGIN@6 which was called: # once (22µs+50µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 6
use Carp;
# spent 73µs making 1 call to Koha::Borrower::Discharge::BEGIN@6 # spent 50µs making 1 call to Exporter::import
7
8248µs238µs
# spent 26µs (15+12) within Koha::Borrower::Discharge::BEGIN@8 which was called: # once (15µs+12µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 8
use C4::Templates qw ( gettemplate );
# spent 26µs making 1 call to Koha::Borrower::Discharge::BEGIN@8 # spent 12µs making 1 call to Class::Accessor::import
92201µs2322µs
# spent 170µs (18+152) within Koha::Borrower::Discharge::BEGIN@9 which was called: # once (18µs+152µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 9
use C4::Members qw( GetPendingIssues );
# spent 170µs making 1 call to Koha::Borrower::Discharge::BEGIN@9 # spent 152µs making 1 call to Exporter::import
10267µs272µs
# spent 42µs (12+30) within Koha::Borrower::Discharge::BEGIN@10 which was called: # once (12µs+30µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 10
use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
# spent 42µs making 1 call to Koha::Borrower::Discharge::BEGIN@10 # spent 30µs making 1 call to Exporter::import
11
12234µs215µs
# spent 12µs (10+3) within Koha::Borrower::Discharge::BEGIN@12 which was called: # once (10µs+3µs) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::BEGIN@32 at line 12
use Koha::Database;
# spent 12µs making 1 call to Koha::Borrower::Discharge::BEGIN@12 # spent 3µs making 1 call to Class::Accessor::import
1321.09ms249µs
# spent 30µs (10+19) within Koha::Borrower::Discharge::BEGIN@13 which was called: # once (10µs+19µ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 19µs making 1 call to Exporter::import
14
15134µs3302µsmy $rs = Koha::Database->new->schema->resultset('Discharge');
# spent 289µs making 1 call to DBIx::Class::Schema::resultset # spent 8µs making 1 call to Class::Accessor::new # spent 6µs making 1 call to Koha::Database::schema
16
17
# spent 7.31ms (18µs+7.29) within Koha::Borrower::Discharge::count which was called: # once (18µs+7.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 {
181600ns my ($params) = @_;
191500ns my $values = {};
20
211800ns 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
32124µs37.35ms return $rs->search( $values )->count;
# spent 7.16ms making 1 call to DBIx::Class::ResultSet::count # spent 138µs making 1 call to DBIx::Class::ResultSet::search # spent 62µ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;