Bugzilla – Attachment 58300 Details for
Bug 17783
Optimize Koha::IssuingRules->get_effective_issuing_rule
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17783: Prevent crash when providing an undefined value
Bug-17783-Prevent-crash-when-providing-an-undefine.patch (text/plain), 4.09 KB, created by
Lari Taskula
on 2016-12-20 15:07:56 UTC
(
hide
)
Description:
Bug 17783: Prevent crash when providing an undefined value
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2016-12-20 15:07:56 UTC
Size:
4.09 KB
patch
obsolete
>From 87690d47a61453f7187b8e05e1ff36b5f1f506c5 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Tue, 20 Dec 2016 16:54:44 +0200 >Subject: [PATCH] Bug 17783: Prevent crash when providing an undefined value > >When calling the proposed version of get_effective_issuing_rule with undefined >parameter values, a following crash occurs: > >SQL::Abstract::puke(): [SQL::Abstract::__ANON__] Fatal: SQL::Abstract before v1.75 >used to generate incorrect SQL when the -IN operator was given an undef-containing >list: !!!AUDIT YOUR CODE AND DATA!!! (the upcoming Data::Query-based version of >SQL::Abstract will emit the logically correct SQL instead of raising this >exception) at /home/ubuntu/kohaclone/Koha/Objects.pm line 182 > >This patch adds a test to cover this problem and fixes the issue. > >To test: >1. Run t/db_dependent/Koha/IsssuingRules.t >--- > Koha/IssuingRules.pm | 20 +++++++++++++++++--- > t/db_dependent/Koha/IssuingRules.t | 31 ++++++++++++++++++++++++++++++- > 2 files changed, 47 insertions(+), 4 deletions(-) > >diff --git a/Koha/IssuingRules.pm b/Koha/IssuingRules.pm >index c0c69be..e3664df 100644 >--- a/Koha/IssuingRules.pm >+++ b/Koha/IssuingRules.pm >@@ -44,10 +44,24 @@ sub get_effective_issuing_rule { > my $itemtype = $params->{itemtype}; > my $branchcode = $params->{branchcode}; > >+ my $search_categorycode = $default; >+ my $search_itemtype = $default; >+ my $search_branchcode = $default; >+ >+ if ($categorycode) { >+ $search_categorycode = { 'in' => [ $categorycode, $default ] }; >+ } >+ if ($itemtype) { >+ $search_itemtype = { 'in' => [ $itemtype, $default ] }; >+ } >+ if ($branchcode) { >+ $search_branchcode = { 'in' => [ $branchcode, $default ] }; >+ } >+ > my $rule = $self->search({ >- categorycode => { 'in' => [ $categorycode, $default ] }, >- itemtype => { 'in' => [ $itemtype, $default ] }, >- branchcode => { 'in' => [ $branchcode, $default ] }, >+ categorycode => $search_categorycode, >+ itemtype => $search_itemtype, >+ branchcode => $search_branchcode, > }, { > order_by => { > -desc => ['branchcode', 'categorycode', 'itemtype'] >diff --git a/t/db_dependent/Koha/IssuingRules.t b/t/db_dependent/Koha/IssuingRules.t >index 158e3cf..847f971 100644 >--- a/t/db_dependent/Koha/IssuingRules.t >+++ b/t/db_dependent/Koha/IssuingRules.t >@@ -33,7 +33,7 @@ $schema->storage->txn_begin; > my $builder = t::lib::TestBuilder->new; > > subtest 'get_effective_issuing_rule' => sub { >- plan tests => 2; >+ plan tests => 3; > > my $patron = $builder->build({ source => 'Borrower' }); > my $item = $builder->build({ source => 'Item' }); >@@ -42,6 +42,35 @@ subtest 'get_effective_issuing_rule' => sub { > my $itemtype = $item->{'itype'}; > my $branchcode = $item->{'homebranch'}; > >+ subtest 'Call with undefined values' => sub { >+ plan tests => 4; >+ >+ my $rule; >+ Koha::IssuingRules->delete; >+ ok(!Koha::IssuingRules->search->count, 'There are no issuing rules.'); >+ $rule = Koha::IssuingRules->get_effective_issuing_rule({ >+ branchcode => undef, >+ categorycode => undef, >+ itemtype => undef, >+ }); >+ is($rule, undef, 'When I attempt to get effective issuing rule by' >+ .' providing undefined values, then undef is returned.'); >+ ok(Koha::IssuingRule->new({ >+ branchcode => '*', >+ categorycode => '*', >+ itemtype => '*', >+ })->store, 'Given I added an issuing rule branchcode => *,' >+ .' categorycode => *, itemtype => *,'); >+ $rule = Koha::IssuingRules->get_effective_issuing_rule({ >+ branchcode => undef, >+ categorycode => undef, >+ itemtype => undef, >+ }); >+ ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective' >+ .' issuing rule by providing undefined values, then the above one is' >+ .' returned.'); >+ }; >+ > subtest 'Get effective issuing rule in correct order' => sub { > plan tests => 18; > >-- >1.9.1
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 17783
:
58228
|
58229
|
58230
|
58231
|
58268
|
58269
|
58270
|
58271
|
58300
|
58304
|
58309
|
58310
|
58311
|
58312
|
58313
|
58314