Lines 1-5
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
|
2 |
|
|
|
3 |
use Koha::CirculationRules; |
4 |
|
3 |
return { |
5 |
return { |
4 |
bug_number => "29012", |
6 |
bug_number => "29012", |
5 |
description => "Some rules are not saved when left blank while editing a 'rule' line in smart-rules.pl", |
7 |
description => "Some rules are not saved when left blank while editing a 'rule' line in smart-rules.pl", |
Lines 13-41
return {
Link Here
|
13 |
rentaldiscount => 0, |
15 |
rentaldiscount => 0, |
14 |
decreaseloanholds => '', |
16 |
decreaseloanholds => '', |
15 |
); |
17 |
); |
16 |
while (my ($rule_name, $rule_value) = each (%default_rule_values)) { |
18 |
|
17 |
$dbh->do(q{ |
19 |
my $rules = Koha::CirculationRules->search( { rule_name => 'suspension_chargeperiod' } ); |
18 |
INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) |
20 |
while ( my $rule = $rules->next ) { |
19 |
SELECT branchcode, categorycode, itemtype, ?, ? FROM circulation_rules cr |
21 |
foreach my $key ( keys %default_rule_values ) { |
20 |
WHERE EXISTS ( |
22 |
next |
21 |
SELECT * FROM circulation_rules cr2 |
23 |
if # If there is a rule matching these criteria with defined value, we can skip it. |
22 |
WHERE |
24 |
Koha::CirculationRules->search( |
23 |
cr2.rule_name="suspension_chargeperiod" |
25 |
{ |
24 |
AND ( (cr2.branchcode=cr.branchcode) OR ( ISNULL(cr2.branchcode) AND ISNULL(cr.branchcode) ) ) |
26 |
branchcode => $rule->branchcode, |
25 |
AND ( (cr2.categorycode=cr.categorycode) OR ( ISNULL(cr2.categorycode) AND ISNULL(cr.categorycode) ) ) |
27 |
categorycode => $rule->categorycode, |
26 |
AND ( (cr2.itemtype=cr.itemtype) OR ( ISNULL(cr2.itemtype) AND ISNULL(cr.itemtype) ) ) |
28 |
itemtype => $rule->itemtype, |
27 |
) |
29 |
rule_name => $key, |
28 |
AND NOT EXISTS ( |
30 |
} |
29 |
SELECT * FROM circulation_rules cr2 |
31 |
)->count; |
30 |
WHERE |
32 |
|
31 |
cr2.rule_name=? |
33 |
my $derived_rule = Koha::CirculationRules->get_effective_rule( |
32 |
AND ( (cr2.branchcode=cr.branchcode) OR ( ISNULL(cr2.branchcode) AND ISNULL(cr.branchcode) ) ) |
34 |
{ |
33 |
AND ( (cr2.categorycode=cr.categorycode) OR ( ISNULL(cr2.categorycode) AND ISNULL(cr.categorycode) ) ) |
35 |
branchcode => $rule->branchcode, |
34 |
AND ( (cr2.itemtype=cr.itemtype) OR ( ISNULL(cr2.itemtype) AND ISNULL(cr.itemtype) ) ) |
36 |
categorycode => $rule->categorycode, |
35 |
) |
37 |
itemtype => $rule->itemtype, |
36 |
GROUP BY branchcode, categorycode, itemtype |
38 |
rule_name => $key, |
37 |
}, undef, $rule_name, $rule_value, $rule_name); |
39 |
} |
|
|
40 |
); |
41 |
my $value = |
42 |
$derived_rule |
43 |
? $derived_rule->rule_value // $default_rule_values{$key} |
44 |
: $default_rule_values{$key}; |
45 |
|
46 |
Koha::CirculationRule->new( |
47 |
{ |
48 |
branchcode => $rule->branchcode, |
49 |
categorycode => $rule->categorycode, |
50 |
itemtype => $rule->itemtype, |
51 |
rule_name => $key, |
52 |
rule_value => $value, |
53 |
} |
54 |
)->store(); |
55 |
} |
38 |
} |
56 |
} |
39 |
say $out "Add default values for blank circulation rules that weren't saved to the database"; |
57 |
|
|
|
58 |
say $out "Set derived values for blank circulation rules that weren't saved to the database"; |
40 |
}, |
59 |
}, |
41 |
} |
60 |
} |
42 |
- |
|
|