Bugzilla – Attachment 55336 Details for
Bug 5670
Housebound Readers Module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 5670: [Followup] Refactor .pl; error messages.
Bug-5670-Followup-Refactor-pl-error-messages.patch (text/plain), 7.96 KB, created by
Alex Sassmannshausen
on 2016-09-08 12:11:50 UTC
(
hide
)
Description:
Bug 5670: [Followup] Refactor .pl; error messages.
Filename:
MIME Type:
Creator:
Alex Sassmannshausen
Created:
2016-09-08 12:11:50 UTC
Size:
7.96 KB
patch
obsolete
>From 8b2ea41baff19d10193e4c203f215c22c8c49a0c Mon Sep 17 00:00:00 2001 >From: Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com> >Date: Thu, 8 Sep 2016 12:39:24 +0200 >Subject: [PATCH] Bug 5670: [Followup] Refactor .pl; error messages. > >* members/housebound.pl: Refactor & store messages for encountered > errors. >* koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt: Show > messages. >--- > .../prog/en/modules/members/housebound.tt | 24 ++++++++ > members/housebound.pl | 64 +++++++++++++++------- > 2 files changed, 69 insertions(+), 19 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt >index d48af41..11a8bce 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt >@@ -48,6 +48,30 @@ $(document).ready(function() { > <h3>Housebound details for [% patron.title %] [% patron.firstname %] [% patron.surname %] ([% patron.cardnumber %])</h3> > <div class="yui-u first"> > >+ [% FOR m IN messages %] >+ <div class="dialog [% m.type %]"> >+ [% SWITCH m.code %] >+ [% CASE 'error_on_patron_load' %] >+ An error occurred whilst loading the patron details. >+ [% CASE 'error_on_profile_store' %] >+ An error occurred whilst updating this housebound profile. >+ [% CASE 'error_on_profile_create' %] >+ An error occurred whilst creating this housebound profile. >+ [% CASE 'error_on_visit_load' %] >+ An error occurred whilst loading the housebound visit. >+ [% CASE 'error_on_visit_delete' %] >+ An error occurred whilst deleting a housebound visit. >+ [% CASE 'error_on_visit_store' %] >+ An error occurred whilst updating a housebound visit. >+ [% CASE 'error_on_visit_create' %] >+ An error occurred whilst creating a new housebound visit. >+ [% CASE %] >+ [% m.code %] >+ [% END %] >+ Please try again later. >+ </div> >+ [% END %] >+ > <!-- Create or edit housebound_profile --> > [% IF ( method == 'update_or_create' ) %] > <h4>Manage housebound profile</h4> >diff --git a/members/housebound.pl b/members/housebound.pl >index f5ced86..516effc 100755 >--- a/members/housebound.pl >+++ b/members/housebound.pl >@@ -47,17 +47,37 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-my $patron = Koha::Patrons->new->find($input->param('borrowernumber')); >+my @messages; # For error messages. > my $method = $input->param('method') // q{}; > my $visit_id = $input->param('visit_id') // q{}; >-my $branch = Koha::Libraries->new->find($patron->branchcode); >-my $category = Koha::Patron::Categories->new->find($patron->categorycode); >-my $houseboundprofile = $patron->housebound_profile; > >+# Get patron >+my $patron = eval { >+ return Koha::Patrons->new->find($input->param('borrowernumber')); >+}; >+push @messages, { type => 'error', code => 'error_on_patron_load' } >+ if ( $@ or !$patron ); >+ >+# Get supporting cast >+my ( $branch, $category, $houseboundprofile, $visit ); >+if ( $patron ) { >+ $branch = Koha::Libraries->new->find($patron->branchcode); >+ $category = Koha::Patron::Categories->new->find($patron->categorycode); >+ $houseboundprofile = $patron->housebound_profile; >+} >+if ( $visit_id ) { >+ $visit = eval { >+ return Koha::Patron::HouseboundVisits->find($visit_id); >+ }; >+ push @messages, { type => 'error', code => 'error_on_visit_load' } >+ if ( $@ or !$visit ); >+} >+ >+# Main processing > my ( $houseboundvisits, $deliverers, $choosers ); > my ( $houseboundvisit, $deliverer, $chooser ); > >-if ( $method eq 'updateconfirm' ) { >+if ( $method eq 'updateconfirm' and $houseboundprofile ) { > # We have received the input from the profile edit form. We must save the > # changes, and return to simple display. > $houseboundprofile->set({ >@@ -69,8 +89,9 @@ if ( $method eq 'updateconfirm' ) { > referral => $input->param('referral') // q{}, > notes => $input->param('notes') // q{}, > }); >- die("Unable to store edited profile") >- unless ( $houseboundprofile->store ); >+ my $success = eval { return $houseboundprofile->store }; >+ push @messages, { type => 'error', code => 'error_on_profile_store' } >+ if ( $@ or !$success ); > $method = undef; > } elsif ( $method eq 'createconfirm' ) { > # We have received the input necessary to create a new profile. We must >@@ -85,24 +106,24 @@ if ( $method eq 'updateconfirm' ) { > referral => $input->param('referral') // q{}, > notes => $input->param('notes') // q{}, > }); >- die("Unable to store new profile") >- unless ( $houseboundprofile->store ); >+ my $success = eval { return $houseboundprofile->store }; >+ push @messages, { type => 'error', code => 'error_on_profile_create' } >+ if ( $@ or !$success ); > $method = undef; > } elsif ( $method eq 'visit_update_or_create' ) { > # We want to edit, edit a visit, so we must pass its details. > $deliverers = Koha::Patrons->new->housebound_deliverers; > $choosers = Koha::Patrons->new->housebound_choosers; >- $houseboundvisit = Koha::Patron::HouseboundVisits->find($visit_id) >- if ( $visit_id ); >-} elsif ( $method eq 'visit_delete' ) { >+ $houseboundvisit = $visit; >+} elsif ( $method eq 'visit_delete' and $visit ) { > # We want ot delete a specific visit. >- my $visit = Koha::Patron::HouseboundVisits->find($visit_id); >- die("Unable to delete visit") unless ( $visit->delete ); >+ my $success = eval { return $visit->delete }; >+ push @messages, { type => 'error', code => 'error_on_visit_delete' } >+ if ( $@ or !$success ); > $method = undef; >-} elsif ( $method eq 'editvisitconfirm' ) { >+} elsif ( $method eq 'editvisitconfirm' and $visit ) { > # We have received input for editing a visit. We must store and return to > # simple display. >- my $visit = Koha::Patron::HouseboundVisits->find($visit_id); > $visit->set({ > borrowernumber => $input->param('borrowernumber') // q{}, > appointment_date => $input->param('date') // q{}, >@@ -110,9 +131,11 @@ if ( $method eq 'updateconfirm' ) { > chooser_brwnumber => $input->param('chooser') // q{}, > deliverer_brwnumber => $input->param('deliverer') // q{}, > }); >- die("Unable to store edited visit") unless ( $visit->store ); >+ my $success = eval { return $visit->store }; >+ push @messages, { type => 'error', code => 'error_on_visit_store' } >+ if ( $@ or !$success ); > $method = undef; >-} elsif ( $method eq 'addvisitconfirm' ) { >+} elsif ( $method eq 'addvisitconfirm' and !$visit ) { > # We have received input for creating a visit. We must store and return > # to simple display. > my $visit = Koha::Patron::HouseboundVisit->new({ >@@ -122,7 +145,9 @@ if ( $method eq 'updateconfirm' ) { > chooser_brwnumber => $input->param('chooser') // q{}, > deliverer_brwnumber => $input->param('deliverer') // q{}, > }); >- die("Unable to store new visit") unless ( $visit->store ); >+ my $success = eval { return $visit->store }; >+ push @messages, { type => 'error', code => 'error_on_visit_create' } >+ if ( $@ or !$success ); > $method = undef; > } > >@@ -135,6 +160,7 @@ $template->param( > visit => $houseboundvisit, > branch => $branch, > category => $category, >+ messages => \@messages, > method => $method, > choosers => $choosers, > deliverers => $deliverers, >-- >2.9.3
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 5670
:
3038
|
22162
|
22163
|
22164
|
22165
|
26816
|
27288
|
50930
|
51377
|
51875
|
54384
|
54385
|
55326
|
55334
|
55335
|
55336
|
55734
|
55735
|
55736
|
55737
|
55738
|
55739
|
55865
|
55866
|
55867
|
55890
|
55891
|
56298
|
56299
|
56300
|
56301
|
56302
|
56308
|
56337
|
56341
|
56346
|
56347
|
56348
|
56349
|
56350
|
56351
|
56352
|
56353
|
56354
|
56355
|
56356
|
56357
|
56358
|
56359
|
56360
|
56361
|
56362
|
56363
|
56364
|
56365
|
56366
|
56367
|
56368
|
56369
|
56580
|
56581
|
56582
|
56583
|
56584
|
56585
|
56586
|
56587
|
56588
|
56589
|
56590
|
56591
|
56592
|
56593
|
56594
|
56595
|
56596
|
56597
|
56598
|
56599
|
56600
|
56601
|
56602
|
56603
|
56604
|
56605
|
56606