Lines 1-32
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
|
2 |
|
3 |
return { |
3 |
return { |
4 |
bug_number => "33028", |
4 |
bug_number => "33028", |
5 |
description => "Fix wrongly formatted values for monetary values in circulation rules", |
5 |
description => "Fix wrongly formatted values for monetary values in circulation rules", |
6 |
up => sub { |
6 |
up => sub { |
7 |
my ($args) = @_; |
7 |
my ($args) = @_; |
8 |
my ($dbh, $out) = @$args{qw(dbh out)}; |
8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
9 |
|
9 |
|
10 |
my $rules = $dbh->selectall_arrayref( |
10 |
my $rules = $dbh->selectall_arrayref( |
11 |
q|SELECT * FROM circulation_rules WHERE rule_name IN ('fine', 'overduefinescap', 'recall_overdue_fine', 'article_request_fee')|, |
11 |
q|SELECT * FROM circulation_rules WHERE rule_name IN ('fine', 'overduefinescap', 'recall_overdue_fine', 'article_request_fee')|, |
12 |
{ Slice => {} } |
12 |
{ Slice => {} } |
13 |
); |
13 |
); |
14 |
|
14 |
|
15 |
my $query = $dbh->prepare( |
15 |
my $query = $dbh->prepare("UPDATE circulation_rules SET rule_value = ? WHERE id = ?"); |
16 |
"UPDATE circulation_rules SET rule_value = ? WHERE id = ?"); |
|
|
17 |
|
16 |
|
18 |
my $error; |
17 |
my $error; |
19 |
for my $rule ( @{$rules} ) { |
18 |
for my $rule ( @{$rules} ) { |
20 |
my $library = defined($rule->{'branchcode'}) ? $rule->{'branchcode'} : "All"; |
19 |
my $library = |
21 |
my $category = defined($rule->{'categorycode'}) ? $rule->{'categorycode'} : "All"; |
20 |
defined( $rule->{'branchcode'} ) ? $rule->{'branchcode'} : "All"; |
22 |
my $itemtype = defined($rule->{'itemtype'}) ? $rule->{'itemtype'} : "All"; |
21 |
my $category = |
23 |
if ( !( $rule->{'rule_value'} =~ /^[0-9.]*$/ )) { |
22 |
defined( $rule->{'categorycode'} ) |
24 |
$error .= "Rule ID: $rule->{'id'} ($library-$category-$itemtype) \tRule: $rule->{'rule_name'}\tValue: $rule->{'rule_value'}\n"; |
23 |
? $rule->{'categorycode'} |
|
|
24 |
: "All"; |
25 |
my $itemtype = |
26 |
defined( $rule->{'itemtype'} ) ? $rule->{'itemtype'} : "All"; |
27 |
if ( !( $rule->{'rule_value'} =~ /^[0-9.]*$/ ) ) { |
28 |
$error .= |
29 |
"Rule ID: $rule->{'id'} ($library-$category-$itemtype) \tRule: $rule->{'rule_name'}\tValue: $rule->{'rule_value'}\n"; |
25 |
} |
30 |
} |
26 |
} |
31 |
} |
27 |
if ( $error ) { |
32 |
if ($error) { |
28 |
die("Circulation rules contain invalid monetary values:\n$error\nPlease fix these before you restart the update."); |
33 |
die( |
|
|
34 |
"Circulation rules contain invalid monetary values:\n$error\nPlease fix these before you restart the update." |
35 |
); |
29 |
} |
36 |
} |
30 |
say $out "Circulation rules have been validated. All circulation rule values are correctly formatted."; |
37 |
say $out "Circulation rules have been validated. All circulation rule values are correctly formatted."; |
31 |
}, |
38 |
}, |
32 |
}; |
39 |
}; |
33 |
- |
|
|