Bugzilla – Attachment 99639 Details for
Bug 4461
Add a context-sensitive report a problem process
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 4461: Better error handling
Bug-4461-Better-error-handling.patch (text/plain), 8.75 KB, created by
Jonathan Druart
on 2020-02-26 11:21:47 UTC
(
hide
)
Description:
Bug 4461: Better error handling
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-02-26 11:21:47 UTC
Size:
8.75 KB
patch
obsolete
>From 1127f929a135abcb9822472831180064c52708e3 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 26 Feb 2020 12:15:42 +0100 >Subject: [PATCH] Bug 4461: Better error handling > >--- > .../bootstrap/en/modules/opac-reportproblem.tt | 24 +++- > opac/opac-reportproblem.pl | 132 ++++++++++++--------- > 2 files changed, 97 insertions(+), 59 deletions(-) > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt >index 038e8462d6..3b5ffe30f8 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reportproblem.tt >@@ -27,7 +27,22 @@ > [% END %] > <h1>Report a problem</h1> > >- [% IF ( successfuladd ) %] >+ [% FOR m IN messages %] >+ <div class="alert alert-[% m.type | html %]"> >+ [% SWITCH m.code %] >+ [% CASE 'success_on_send' %] >+ [% IF recipient == 'admin' %] >+ Your problem report has been sent to the Koha administrator. >+ [% ELSE %] >+ Your problem report has been sent to the library. >+ [% END %] >+ [% CASE 'error_on_send' %][#% We really should avoid reaching this! %] >+ Something wrong happened when sending the report. Please contact your library. >+ [% END %] >+ </div> >+ [% END %] >+ >+ [% IF success_on_send %] > <div class="alert alert-info"> > [% IF recipient == 'admin' %] > Your problem report has been sent to the Koha administrator. >@@ -36,6 +51,7 @@ > [% END %] > </div> > [% END %] >+ > <div id="reportproblem" class="maincontent toptabs"> > <form name="reportlibform" action="/cgi-bin/koha/opac-reportproblem.pl" method="post"> > <input type="hidden" name="op" value="addreport"> >@@ -53,9 +69,9 @@ > [% END %] > </li> > <li> >- <label for="place">Problem found on page: </label> >- <input type="hidden" name="place" id="place" value="[% probpage | html %]"> >- [% probpage | html %] >+ <label for="problempage">Problem found on page: </label> >+ <input type="hidden" name="problempage" id="problempage" value="[% problempage | html %]"> >+ [% problempage | html %] > </li> > <li> > <label for="user">Username: </label> >diff --git a/opac/opac-reportproblem.pl b/opac/opac-reportproblem.pl >index 2d4d8b174d..c8e0d2a22a 100644 >--- a/opac/opac-reportproblem.pl >+++ b/opac/opac-reportproblem.pl >@@ -19,12 +19,12 @@ > > use Modern::Perl; > use CGI qw ( -utf8 ); >+use Try::Tiny; >+ > use C4::Auth; # get_template_and_user > use C4::Output; >-use C4::Members; > use C4::Letters; > use Koha::ProblemReport; >-use Koha::DateUtils; > use Koha::Libraries; > use Koha::Patrons; > use Koha::Util::Navigation; >@@ -48,15 +48,16 @@ if ( !C4::Context->preference('OPACReportProblem') > > my $problempage = C4::Context->preference('OPACBaseURL') . Koha::Util::Navigation::local_referer($input ); > >-my $member = Koha::Patrons->find($borrowernumber); >-my $username = $member->userid; >-my $branchcode = $member->branchcode; >+my $patron = Koha::Patrons->find($borrowernumber); >+my $username = $patron->userid; >+my $branchcode = $patron->branchcode; > my $library = Koha::Libraries->find($branchcode); >+my @messages; > > $template->param( >- username => $username, >- probpage => $problempage, >- library => $library, >+ username => $username, >+ problempage => $problempage, >+ library => $library, > ); > > my $op = $input->param('op') || ''; >@@ -64,55 +65,76 @@ if ( $op eq 'addreport' ) { > > my $subject = $input->param('subject'); > my $message = $input->param('message'); >- my $place = $input->param('place'); >+ my $problempage = $input->param('problempage'); > my $recipient = $input->param('recipient') || 'admin'; >- my $problem = Koha::ProblemReport->new( >- { >- title => $subject, >- content => $message, >- borrowernumber => $borrowernumber, >- branchcode => $branchcode, >- username => $username, >- problempage => $place, >- recipient => $recipient, >- } >- )->store; >- $template->param( >- recipient => $recipient, >- successfuladd => 1, >- probpage => $place, >- ); >- >- # send notice to library >- my $letter = C4::Letters::GetPreparedLetter( >- module => 'members', >- letter_code => 'PROBLEM_REPORT', >- branchcode => $problem->branchcode, >- tables => { >- 'problem_reports', $problem->reportid >- } >- ); >- >- my $from_address = C4::Context->preference('KohaAdminEmailAddress'); >- my $transport = 'email'; >- >- if ( $recipient eq 'admin' ) { >- C4::Letters::EnqueueLetter({ >- letter => $letter, >- borrowernumber => $borrowernumber, >- message_transport_type => $transport, >- to_address => C4::Context->preference('KohaAdminEmailAddress'), >- from_address => $from_address, >- }); >- } else { >- C4::Letters::EnqueueLetter({ >- letter => $letter, >- borrowernumber => $borrowernumber, >- message_transport_type => $transport, >- to_address => $library->branchemail, >- from_address => $from_address, >- }); >+ >+ try { >+ my $schema = Koha::Database->new->schema; >+ $schema->txn_do( >+ sub { >+ my $problem = Koha::ProblemReport->new( >+ { >+ title => $subject, >+ content => $message, >+ borrowernumber => $borrowernumber, >+ branchcode => $branchcode, >+ username => $username, >+ problempage => $problempage, >+ recipient => $recipient, >+ } >+ )->store; >+ >+ # send notice to library >+ my $letter = C4::Letters::GetPreparedLetter( >+ module => 'members', >+ letter_code => 'PROBLEM_REPORT', >+ branchcode => $problem->branchcode, >+ tables => { >+ 'problem_reports', $problem->reportid >+ } >+ ); >+ >+ my $from_address = C4::Context->preference('KohaAdminEmailAddress'); >+ my $transport = 'email'; >+ >+ if ( $recipient eq 'admin' ) { >+ C4::Letters::EnqueueLetter({ >+ letter => $letter, >+ borrowernumber => $borrowernumber, >+ message_transport_type => $transport, >+ to_address => C4::Context->preference('KohaAdminEmailAddress'), >+ from_address => $from_address, >+ }); >+ } else { >+ C4::Letters::EnqueueLetter({ >+ letter => $letter, >+ borrowernumber => $borrowernumber, >+ message_transport_type => $transport, >+ to_address => $library->branchemail, >+ from_address => $from_address, >+ }); >+ } >+ >+ push @messages, { >+ type => 'info', >+ code => 'success_on_send', >+ }; >+ >+ $template->param( >+ recipient => $recipient, >+ ); >+ } >+ ); >+ } >+ catch { >+ warn "Something wrong happened when sending the report problem: $_"; >+ push @messages, { >+ type => 'error', >+ code => 'error_on_send', >+ }; > } > } > >+$template->param( messages => \@messages ); >+ > output_html_with_http_headers $input, $cookie, $template->output; >-- >2.11.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 4461
:
58887
|
59032
|
61654
|
65871
|
66253
|
66323
|
66324
|
98687
|
98688
|
98689
|
98725
|
99551
|
99599
|
99600
|
99601
|
99602
|
99603
|
99633
|
99635
|
99636
|
99637
|
99638
|
99639
|
99929
|
99930
|
99931
|
99932
|
99933
|
99934
|
99935
|
99936
|
99937
|
99938
|
99939
|
99940
|
99941
|
99942
|
100488
|
100489
|
100490
|
100491
|
100492
|
100493
|
100494
|
100495
|
100496
|
100497
|
100498
|
100499
|
100500
|
100506
|
100507
|
100508
|
100509
|
100510
|
100511
|
100512
|
100513
|
100514
|
100515
|
100516
|
100517
|
100518
|
100519
|
100520
|
100521
|
100522
|
100523
|
100524
|
100619
|
100989
|
100990
|
102188
|
102189
|
102190
|
102191
|
102192
|
102193
|
102194
|
102195
|
102196
|
102198
|
102200
|
102201
|
102202
|
102203
|
102204
|
102205
|
102206
|
102207
|
102208
|
102209
|
102210
|
102211
|
102253
|
102279
|
102281
|
102308
|
102309
|
102310
|
102311
|
102312
|
102313
|
102314
|
102315
|
102316
|
102317
|
102318
|
102319
|
102320
|
102321
|
102322
|
102323
|
102324
|
102325
|
102326
|
102327
|
102328
|
102329
|
102330
|
102331
|
102358
|
102359
|
102360
|
102361
|
102362
|
102363
|
102364
|
102365
|
102366
|
102367
|
102368
|
102369
|
102370
|
102371
|
102372
|
102373
|
102374
|
102375
|
102376
|
102377
|
102378
|
102379
|
102380
|
102381
|
102382
|
102383
|
102384
|
102385
|
102386