View | Details | Raw Unified | Return to bug 33028
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl (-38 / +17 lines)
Lines 1-52 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "BUG_33028",
4
    bug_number => "33028",
5
    description =>
5
    description => "Fix wrongly formatted values for monetary values in circulation rules",
6
"Fix calculations around fines and values with comma as decimal separator",
7
    up => sub {
6
    up => sub {
8
        my ($args) = @_;
7
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
8
        my ($dbh, $out) = @$args{qw(dbh out)};
10
9
11
        my $rules = $dbh->selectall_arrayref(
10
        my $rules = $dbh->selectall_arrayref(
12
q|select * from circulation_rules where rule_name IN ('fine', 'overduefinescap')|,
11
            q|SELECT * FROM circulation_rules WHERE rule_name IN ('fine', 'overduefinescap', 'recall_overdue_fine', 'article_request_fee')|,
13
            { Slice => {} }
12
            { Slice => {} }
14
        );
13
        );
15
14
16
        my $query = $dbh->prepare(
15
        my $query = $dbh->prepare(
17
            "UPDATE circulation_rules SET rule_value = ? where id = ?");
16
            "UPDATE circulation_rules SET rule_value = ? WHERE id = ?");
18
17
19
        foreach my $rule ( @{$rules} ) {
18
        my $error;
20
            my $rule_id    = $rule->{'id'};
19
        for my $rule ( @{$rules} ) {
21
            my $rule_value = $rule->{'rule_value'};
20
            my $library = defined($rule->{'branchcode'}) ? $rule->{'branchcode'} : "All";
22
            if ( $rule_value =~ /[a-zA-Z]/ ) {
21
            my $category = defined($rule->{'categorycode'}) ? $rule->{'categorycode'} : "All";
23
                die(
22
            my $itemtype = defined($rule->{'itemtype'}) ? $rule->{'itemtype'} : "All";
24
                    sprintf(
23
            if ( !( $rule->{'rule_value'} =~ /^[0-9.]*$/ )) {
25
                        'No only numbers in rule id %s ("%s") - fix it before restart this update',
24
                $error .= "Rule ID: $rule->{'id'} ($library-$category-$itemtype) \tRule: $rule->{'rule_name'}\tValue: $rule->{'rule_value'}\n";
26
                        $rule_id, $rule_value
27
                    )
28
                );
29
            }
25
            }
30
            else {
31
                if ( $rule_value =~ /,/ ) {
32
                    if ( $rule_value !~ /,.*?,/ ) {
33
                        $rule_value =~ s/,/./;
34
                        $rule_value =~ s/\.0+$//;
35
                        $query->execute( $rule_value, $rule_id );
36
                    }
37
                    else {
38
                        die(
39
                            sprintf(
40
                                'Many commas in rule id %s ("%s") - fix it before restart this update',
41
                                $rule_id, $rule_value
42
                            )
43
                        );
44
                    }
45
                }
46
            }
47
48
        }
26
        }
49
        say $out
27
        if ( $error ) {
50
        "BUG_33028 - Patch applied";
28
            die("Circulation rules contain invalid monetary values:\n$error\nPlease fix these before you restart the update.");
29
        }
30
        say $out "Circulation rules have been validated. All circulation rule values are correctly formatted.";
51
    },
31
    },
52
  }
32
  };
53
- 

Return to bug 33028