Bugzilla – Attachment 125707 Details for
Bug 27945
Limit the number of active article requests per patron category
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27945: Fix error handling and translatability
Bug-27945-Fix-error-handling-and-translatability.patch (text/plain), 6.24 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-10-04 15:15:58 UTC
(
hide
)
Description:
Bug 27945: Fix error handling and translatability
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-10-04 15:15:58 UTC
Size:
6.24 KB
patch
obsolete
>From 2cada4f422a10c12969e750e91eff8d116f30611 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 4 Oct 2021 12:08:12 -0300 >Subject: [PATCH] Bug 27945: Fix error handling and translatability > >This patch adds better error handling and reporting when placing an >article request fails. It also makes the error messages translatable. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > circ/request-article.pl | 21 +++++++++--- > .../prog/en/modules/circ/request-article.tt | 5 ++- > .../en/modules/opac-request-article.tt | 5 ++- > opac/opac-request-article.pl | 32 ++++++++++++++----- > 4 files changed, 48 insertions(+), 15 deletions(-) > >diff --git a/circ/request-article.pl b/circ/request-article.pl >index 0cc4cc591d..1c92927b82 100755 >--- a/circ/request-article.pl >+++ b/circ/request-article.pl >@@ -25,8 +25,11 @@ use C4::Utils::DataTables::Members; > use C4::Search qw( enabled_staff_search_views ); > use C4::Serials qw( CountSubscriptionFromBiblionumber ); > use Koha::Biblios; >+use Koha::Logger; > use Koha::Patrons; > use Koha::ArticleRequests; >+ >+use Scalar::Util qw( blessed ); > use Try::Tiny; > > my $cgi = CGI->new; >@@ -86,11 +89,19 @@ if ( $action eq 'create' ) { > patron_notes => $patron_notes, > format => $format, > } >- )->store(); >+ )->request; > } catch { >- $template->param( >- error_message => $_->{message} >- ); >+ if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) { >+ $template->param( >+ error_message => 'article_request_limit_reached' >+ ); >+ } >+ else { >+ Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)"); >+ $template->param( >+ error_message => 'article_request_unhandled_exception' >+ ); >+ } > }; > > } >@@ -119,7 +130,7 @@ if ( !$patron && $patron_cardnumber ) { > if( $patron && !$patron->can_request_article) { > $patron = undef; > $template->param( >- error_message => 'Patron cannot request more articles for today' >+ error_message => 'article_request_limit_reached' > ); > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >index f26a10318d..d1c3306b89 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >@@ -48,7 +48,10 @@ > <h1>Request article from [% INCLUDE 'biblio-title.inc' link = 1 %]</h1> > [% IF error_message %] > <div class="dialog alert"> >- <p>[% error_message | html %]</p> >+ [% SWITCH error_message %] >+ [% CASE 'article_request_limit_reached' %]<p>Patron reached daily limit.</p> >+ [% CASE 'article_request_unhandled_exception' %]<p>An error has occurred. Check the logs.</p> >+ [% END %] > </div> > [% END %] > [% IF no_patrons_found %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt >index e504556b74..9dad25f038 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt >@@ -219,7 +219,10 @@ > [% ELSIF error_message %] > <h1 class="title">[% biblio.title | html %]</h1> > <div class="alert alert-info"> >- [% error_message | html %] >+ [% SWITCH error_message %] >+ [% CASE 'article_request_limit_reached' %]You reached your article requests daily limit. >+ [% CASE 'article_request_unhandled_exception' %]An error has occurred. >+ [% END %] > </div> > [% ELSE %] > <h1 class="title">[% biblio.title | html %]</h1> >diff --git a/opac/opac-request-article.pl b/opac/opac-request-article.pl >index 146454f033..b6048cc8c2 100755 >--- a/opac/opac-request-article.pl >+++ b/opac/opac-request-article.pl >@@ -25,7 +25,10 @@ use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > > use Koha::Biblios; >+use Koha::Logger; > use Koha::Patrons; >+ >+use Scalar::Util qw( blessed ); > use Try::Tiny; > > my $cgi = CGI->new; >@@ -60,6 +63,9 @@ if ( $action eq 'create' ) { > my $patron_notes = $cgi->param('patron_notes') || undef; > my $format = $cgi->param('format') || undef; > >+ >+ my $success; >+ > try { > my $ar = Koha::ArticleRequest->new( > { >@@ -77,16 +83,26 @@ if ( $action eq 'create' ) { > patron_notes => $patron_notes, > format => $format, > } >- )->store(); >+ )->request; >+ $success = 1; >+ } catch { >+ if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) { >+ $template->param( >+ error_message => 'article_request_limit_reached' >+ ); >+ } >+ else { >+ Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)"); >+ $template->param( >+ error_message => 'article_request_unhandled_exception' >+ ); >+ } >+ }; > >+ if ( $success ) { > print $cgi->redirect("/cgi-bin/koha/opac-user.pl#opac-user-article-requests"); > exit; >- } catch { >- exit unless $_->[0] && $_->[0] eq 'EXIT'; >- $template->param( >- error_message => $_->{message} >- ); >- }; >+ } > # Should we redirect? > } > elsif ( !$action && C4::Context->preference('ArticleRequestsOpacHostRedirection') ) { >@@ -106,7 +122,7 @@ my $patron = Koha::Patrons->find($borrowernumber); > > if(!$patron->can_request_article) { > $template->param( >- error_message => 'You cannot request more articles for today' >+ error_message => 'article_request_limit_reached' > ); > } > >-- >2.32.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 27945
:
123217
|
123218
|
123219
|
123220
|
123714
|
123715
|
123774
|
123775
|
123776
|
123777
|
123778
|
123820
|
124066
|
124067
|
124068
|
124069
|
124070
|
124071
|
124072
|
124073
|
124074
|
124075
|
124076
|
124077
|
124078
|
124079
|
124284
|
124285
|
124633
|
124673
|
124674
|
124675
|
124676
|
124677
|
124678
|
124679
|
124680
|
124681
|
124682
|
125140
|
125142
|
125143
|
125144
|
125145
|
125146
|
125147
|
125148
|
125149
|
125150
|
125151
|
125152
|
125178
|
125179
|
125569
|
125571
|
125638
|
125690
|
125702
|
125703
|
125704
|
125705
|
125706
| 125707 |
125726
|
125741
|
125761