Bugzilla – Attachment 152760 Details for
Bug 33028
Wrongly formatted monetary amounts in circulation rules break scripts and calculations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33028: (follow-up) Rewrite database update
Bug-33028-follow-up-Rewrite-database-update.patch (text/plain), 4.22 KB, created by
Martin Renvoize (ashimema)
on 2023-06-27 15:58:42 UTC
(
hide
)
Description:
Bug 33028: (follow-up) Rewrite database update
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-06-27 15:58:42 UTC
Size:
4.22 KB
patch
obsolete
>From 9f6bb4480442eb2005a315a9d037c56f2730fe8f Mon Sep 17 00:00:00 2001 >From: Katrin Fischer <katrin.fischer@bsz-bw.de> >Date: Fri, 16 Jun 2023 17:01:52 +0000 >Subject: [PATCH] Bug 33028: (follow-up) Rewrite database update >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This rewrite the database update with some things in mind: > >* We now use a positive value list of allowed characters to check > This makes sure that all of those are recognized: > 1,00 > 1.00⬠> abc >* Instead of dying after finding one wrong value, we loop through > all values first, building up an error string >* When we have errors... we die and print the full list of things > that need fixing. > >Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > ...ix_calc_fines_fr-currency_21-11-MT39815.pl | 54 ++++++------------- > 1 file changed, 17 insertions(+), 37 deletions(-) > >diff --git a/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl b/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl >index 637b0f18f4..f3203dc764 100755 >--- a/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl >+++ b/installer/data/mysql/atomicupdate/fix_calc_fines_fr-currency_21-11-MT39815.pl >@@ -1,52 +1,32 @@ > use Modern::Perl; > > return { >- bug_number => "BUG_33028", >- description => >-"Fix calculations around fines and values with comma as decimal separator", >+ bug_number => "33028", >+ description => "Fix wrongly formatted values for monetary values in circulation rules", > up => sub { > my ($args) = @_; >- my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ my ($dbh, $out) = @$args{qw(dbh out)}; > > my $rules = $dbh->selectall_arrayref( >-q|select * from circulation_rules where rule_name IN ('fine', 'overduefinescap')|, >+ q|SELECT * FROM circulation_rules WHERE rule_name IN ('fine', 'overduefinescap', 'recall_overdue_fine', 'article_request_fee')|, > { Slice => {} } > ); > > my $query = $dbh->prepare( >- "UPDATE circulation_rules SET rule_value = ? where id = ?"); >+ "UPDATE circulation_rules SET rule_value = ? WHERE id = ?"); > >- foreach my $rule ( @{$rules} ) { >- my $rule_id = $rule->{'id'}; >- my $rule_value = $rule->{'rule_value'}; >- if ( $rule_value =~ /[a-zA-Z]/ ) { >- die( >- sprintf( >- 'No only numbers in rule id %s ("%s") - fix it before restart this update', >- $rule_id, $rule_value >- ) >- ); >+ my $error; >+ for my $rule ( @{$rules} ) { >+ my $library = defined($rule->{'branchcode'}) ? $rule->{'branchcode'} : "All"; >+ my $category = defined($rule->{'categorycode'}) ? $rule->{'categorycode'} : "All"; >+ my $itemtype = defined($rule->{'itemtype'}) ? $rule->{'itemtype'} : "All"; >+ if ( !( $rule->{'rule_value'} =~ /^[0-9.]*$/ )) { >+ $error .= "Rule ID: $rule->{'id'} ($library-$category-$itemtype) \tRule: $rule->{'rule_name'}\tValue: $rule->{'rule_value'}\n"; > } >- else { >- if ( $rule_value =~ /,/ ) { >- if ( $rule_value !~ /,.*?,/ ) { >- $rule_value =~ s/,/./; >- $rule_value =~ s/\.0+$//; >- $query->execute( $rule_value, $rule_id ); >- } >- else { >- die( >- sprintf( >- 'Many commas in rule id %s ("%s") - fix it before restart this update', >- $rule_id, $rule_value >- ) >- ); >- } >- } >- } >- > } >- say $out >- "BUG_33028 - Patch applied"; >+ if ( $error ) { >+ die("Circulation rules contain invalid monetary values:\n$error\nPlease fix these before you restart the update."); >+ } >+ say $out "Circulation rules have been validated. All circulation rule values are correctly formatted."; > }, >- } >+ }; >-- >2.41.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33028
:
147058
|
147686
|
147687
|
147688
|
152441
|
152442
|
152443
|
152444
|
152445
|
152446
|
152509
|
152510
|
152511
|
152512
|
152513
|
152514
|
152515
|
152752
|
152753
|
152754
|
152755
|
152756
|
152757
|
152758
|
152759
|
152760
|
152761
|
152762
|
152763
|
152764
|
152803
|
152804
|
152805
|
152829
|
152928
|
152929
|
152930
|
152931
|
152932
|
152933
|
152934
|
152935
|
152936
|
153313
|
153314
|
153315
|
153316
|
153317
|
153318
|
153319
|
153320
|
153321
|
153322
|
153323
|
153619
|
153620
|
153632
|
153633
|
153634
|
153635
|
153636
|
153677