Bug 33028: Fix calculations around cronjob fines.pl
[koha.git] / installer / data / mysql / atomicupdate / fix_calc_fines_fr-currency_21-11-MT39815.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "BUG_33028",
5     description =>
6 "Fix calculations around fines and values with comma as decimal separator",
7     up => sub {
8         my ($args) = @_;
9         my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11         my $rules = $dbh->selectall_arrayref(
12 q|select * from circulation_rules where rule_name IN ('fine', 'overduefinescap')|,
13             { Slice => {} }
14         );
15
16         my $query = $dbh->prepare(
17             "UPDATE circulation_rules SET rule_value = ? where id = ?");
18
19         foreach my $rule ( @{$rules} ) {
20             my $rule_id    = $rule->{'id'};
21             my $rule_value = $rule->{'rule_value'};
22             if ( $rule_value =~ /[a-zA-Z]/ ) {
23                 die(
24                     sprintf(
25                         'No only numbers in rule id %s ("%s") - fix it before restart this update',
26                         $rule_id, $rule_value
27                     )
28                 );
29             }
30             else {
31                 if ( $rule_value =~ /,/ ) {
32                     if ( $rule_value !~ /,.*?,/ ) {
33                         $rule_value =~ s/,/./;
34                         $query->execute( $rule_value, $rule_id );
35                     }
36                     else {
37                         die(
38                             sprintf(
39                                 'Many commas in rule id %s ("%s") - fix it before restart this update',
40                                 $rule_id, $rule_value
41                             )
42                         );
43                     }
44                 }
45             }
46
47         }
48         say $out
49         "BUG_33028 - Patch applied";
50     },
51   }