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 Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
401f01125c
commit
c5ca94df99
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue