Bugzilla – Attachment 38596 Details for
Bug 8007
Discharge management
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8007: Add error handling when generating the pdf
Bug-8007-Add-error-handling-when-generating-the-pd.patch (text/plain), 6.52 KB, created by
Jonathan Druart
on 2015-04-28 09:02:11 UTC
(
hide
)
Description:
Bug 8007: Add error handling when generating the pdf
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-04-28 09:02:11 UTC
Size:
6.52 KB
patch
obsolete
>From cb937423cb6f3b68ca68a5054a348d1d6d7e791d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 28 Apr 2015 10:59:42 +0200 >Subject: [PATCH] Bug 8007: Add error handling when generating the pdf > >If error occurs when generating the pdf, it would be better to get an >encapsulated error instead of the "software error" message in the pdf >file. >To test this patch I added this change: >--- > .../prog/en/modules/members/discharge.tt | 8 +++++ > .../bootstrap/en/modules/opac-discharge.tt | 11 ++++++- > members/discharge.pl | 35 +++++++++++++--------- > opac/opac-discharge.pl | 35 +++++++++++++--------- > 4 files changed, 60 insertions(+), 29 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt >index c487506..9e1f4fc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt >@@ -18,6 +18,14 @@ > <div class="yui-b"> > <div class="yui-g"> > <h3>Discharge</h3> >+[% FOR message IN messages %] >+ <div class="dialog [% message.type %]"> >+ [% IF message.code == "unable_to_generate_pdf" %] >+ An error occurs when generating the pdf file. >+ Please contact the administrator to resolve this problem. >+ [% END %] >+ </div> >+[% END %] > [% UNLESS can_be_discharged %] > <p>Cannot edit discharge: borrower has issues.</p> > [% ELSE %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt >index c775336..d8f5648 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt >@@ -23,6 +23,15 @@ > <div class="span10"> > <div id="discharge" class="maincontainer"> > <h1>Discharge</h1> >+ [% FOR message IN messages %] >+ <div class="dialog [% message.type %]"> >+ [% IF message.code == "unable_to_generate_pdf" %] >+ An error occurs when generating the pdf file. >+ Please contact the staff to resolve this problem. >+ [% END %] >+ </div> >+ [% END %] >+ > [% IF success %] > <p>Your discharge request has been sent. Your discharge will be available on this page within a few days.</p> > [% ELSIF available %] >@@ -31,7 +40,7 @@ > <p>Your discharge will be available on this page within a few days.</p> > [% ELSIF has_issues %] > <p>You cannot be discharged, you have issues. Please return items before asking for a discharge.</p> >- [% ELSE %] >+ [% ELSIF not messages %] > <h2>What is a discharge?</h2> > <p>This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.</p> > <p><strong>Warning</strong>: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.</p> >diff --git a/members/discharge.pl b/members/discharge.pl >index e2f703d..2144af9 100755 >--- a/members/discharge.pl >+++ b/members/discharge.pl >@@ -28,6 +28,7 @@ Allows librarian to edit and/or manage borrowers' discharges > =cut > > use Modern::Perl; >+use Carp; > > use CGI qw( -utf8 ); > use C4::Auth; >@@ -75,20 +76,26 @@ if ( $input->param('borrowernumber') ) { > borrowernumber => $borrowernumber > }); > } >- my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf( >- { borrowernumber => $borrowernumber, } ); >- >- binmode(STDOUT); >- print $input->header( >- -type => 'application/pdf', >- -charset => 'utf-8', >- -attachment => "discharge_$borrowernumber.pdf", >- ); >- open my $fh, '<', $pdf_path; >- my @lines = <$fh>; >- close $fh; >- print @lines; >- exit; >+ eval { >+ my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf( >+ { borrowernumber => $borrowernumber, } ); >+ >+ binmode(STDOUT); >+ print $input->header( >+ -type => 'application/pdf', >+ -charset => 'utf-8', >+ -attachment => "discharge_$borrowernumber.pdf", >+ ); >+ open my $fh, '<', $pdf_path; >+ my @lines = <$fh>; >+ close $fh; >+ print @lines; >+ exit; >+ }; >+ if ( $@ ) { >+ carp $@; >+ $template->param( messages => [ {type => 'error', code => 'unable_to_generate_pdf'} ] ); >+ } > } > > $template->param( >diff --git a/opac/opac-discharge.pl b/opac/opac-discharge.pl >index e6eca73..800222c 100755 >--- a/opac/opac-discharge.pl >+++ b/opac/opac-discharge.pl >@@ -18,6 +18,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use Carp; > > use C4::Auth qw(:DEFAULT get_session); > use CGI qw( -utf8 ); >@@ -55,21 +56,27 @@ if ( $op eq 'request' ) { > } > } > elsif ( $op eq 'get' ) { >- my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf({ >- borrowernumber => $loggedinuser >- }); >+ eval { >+ my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf({ >+ borrowernumber => $loggedinuser >+ }); > >- binmode(STDOUT); >- print $input->header( >- -type => 'application/pdf', >- -charset => 'utf-8', >- -attachment => "discharge_$loggedinuser.pdf", >- ); >- open my $fh, '<', $pdf_path; >- my @lines = <$fh>; >- close $fh; >- print @lines; >- exit; >+ binmode(STDOUT); >+ print $input->header( >+ -type => 'application/pdf', >+ -charset => 'utf-8', >+ -attachment => "discharge_$loggedinuser.pdf", >+ ); >+ open my $fh, '<', $pdf_path; >+ my @lines = <$fh>; >+ close $fh; >+ print @lines; >+ exit; >+ }; >+ if ( $@ ) { >+ carp $@; >+ $template->param( messages => [ {type => 'error', code => 'unable_to_generate_pdf'} ] ); >+ } > } > else { > my $pending = Koha::Borrower::Discharge::count({ >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8007
:
14490
|
16622
|
16935
|
17484
|
17485
|
21394
|
21395
|
21396
|
21660
|
21674
|
21675
|
21676
|
21677
|
21678
|
24023
|
24024
|
24025
|
24026
|
24027
|
30531
|
30532
|
30533
|
30534
|
30535
|
31007
|
34034
|
34035
|
34036
|
34037
|
34038
|
34039
|
34668
|
34669
|
34670
|
34671
|
34672
|
34673
|
34674
|
34675
|
36180
|
36181
|
36182
|
36183
|
36184
|
36185
|
36186
|
36187
|
36394
|
36395
|
36396
|
36397
|
36398
|
36399
|
36400
|
36401
|
37029
|
37030
|
37031
|
37032
|
37033
|
37034
|
37035
|
37036
|
37037
|
38596
|
38597