diff options
author | Mark Wells <mark@freeside.biz> | 2014-09-05 14:47:53 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-09-05 14:47:53 -0700 |
commit | 529413f23d545179ff07ac393713a225a78014c2 (patch) | |
tree | 64f4f409e03efbda006523f8aadc0a35e9be7a1e /FS | |
parent | b13dda3c202b7eb07167e6423ee71c63f18cdac1 (diff) |
validate parameter in balance_age condition, #15045
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/part_event/Condition/balance_age.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/FS/FS/part_event/Condition/balance_age.pm b/FS/FS/part_event/Condition/balance_age.pm index 84806596a..701dafdfe 100644 --- a/FS/FS/part_event/Condition/balance_age.pm +++ b/FS/FS/part_event/Condition/balance_age.pm @@ -5,6 +5,46 @@ use base qw( FS::part_event::Condition ); sub description { 'Customer balance age'; } +=item check_options OPTIONS + +Validate options + +=cut + +my $duration_rx = qr/^(\d+)$/; +my $unit_rx = qr/^[wmdh]$/; +my $both_rx = qr/^(\d+)([wmdh])/; + +sub check_options { + my ($self, $options) = @_; + + my $age = $options->{age}; + my $age_units = $options->{age_units}; + + return "Invalid (age) must be defined: $age" + unless( defined $age ); + + # over-ride possibly inaccurate unit indicator + if( $age =~ /$both_rx/ ){ + $age = $1; + $age_units = $2; + } + + return "Invalid (age_units) must be defined: $age_units" + unless defined $age_units; + + return "Invalid (age) must be integer: $age" + unless( $age =~ /$duration_rx/ ); + + return "Invalid (age) must be non-zero: $age" + if ( $age == 0 ); + + return( "Invalid (age_units) must be m/w/d/h: $age_units" ) + unless( $age_units =~ /$unit_rx/i ); + + return ''; +} + sub option_fields { ( 'balance' => { 'label' => 'Balance over', |