From a0fec35d6bac0cece6bafa557a7a53058fdf5c6a Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 11 Apr 2011 17:22:37 +0000 Subject: [PATCH] fix times condition vs. mysql (causes billing errors even if not using), RT#10574 --- FS/FS/part_event/Condition.pm | 11 +++++++---- FS/FS/part_event/Condition/cust_bill_has_service.pm | 8 ++++---- FS/FS/part_event/Condition/times.pm | 7 +++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm index 9155a7d42..69027744a 100644 --- a/FS/FS/part_event/Condition.pm +++ b/FS/FS/part_event/Condition.pm @@ -145,7 +145,7 @@ passed as an argument. This method is used for optimizing event queries. You may want to add indices for any columns referenced. It is acceptable to return an SQL fragment which partially tests the condition; doing so will still reduce the number of -records which much be returned and tested with the B method. +records which must be returned and tested with the B method. =cut @@ -457,7 +457,7 @@ sub age2seconds_sql { } -=item condition_sql_option_integer +=item condition_sql_option_integer OPTION [ DRIVER_NAME ] As I, but cast the option value to an integer so that comparison to other integers is type-correct. @@ -465,8 +465,11 @@ comparison to other integers is type-correct. =cut sub condition_sql_option_integer { - my ($class, $option) = @_; - 'CAST ('.$class->condition_sql_option($option).' AS INTEGER)'; + my ($class, $option, $driver_name) = @_; + + my $integer = ($driver_name =~ /^mysql/) ? 'UNSIGNED INTEGER' : 'INTEGER'; + + 'CAST ('. $class->condition_sql_option($option). " AS $integer )"; } =head1 NEW CONDITION CLASSES diff --git a/FS/FS/part_event/Condition/cust_bill_has_service.pm b/FS/FS/part_event/Condition/cust_bill_has_service.pm index 744e079d3..7c1916bea 100644 --- a/FS/FS/part_event/Condition/cust_bill_has_service.pm +++ b/FS/FS/part_event/Condition/cust_bill_has_service.pm @@ -41,14 +41,14 @@ sub condition { sub condition_sql { my( $class, $table, %opt ) = @_; - my $integer = $opt{'driver_name'} =~ /^mysql/ ? 'UNSIGNED INTEGER' : 'INTEGER'; - - my $servicenum = $class->condition_sql_option('has_service'); + my $servicenum = + $class->condition_sql_option_integer('has_service', $opt{'driver_name'}); + my $sql = qq| 0 < ( SELECT COUNT(cs.svcpart) FROM cust_bill_pkg cbp, cust_svc cs WHERE cbp.invnum = cust_bill.invnum AND cs.pkgnum = cbp.pkgnum - AND cs.svcpart = CAST( $servicenum AS $integer ) + AND cs.svcpart = $servicenum ) |; return $sql; diff --git a/FS/FS/part_event/Condition/times.pm b/FS/FS/part_event/Condition/times.pm index 91212e778..46c2967bc 100644 --- a/FS/FS/part_event/Condition/times.pm +++ b/FS/FS/part_event/Condition/times.pm @@ -39,17 +39,20 @@ sub condition { } sub condition_sql { - my( $class, $table ) = @_; + my( $class, $table, %opt ) = @_; my %tablenum = %{ FS::part_event->eventtable_pkey_sql }; + my $run_times = + $class->condition_sql_option_integer('run_times', $opt{'driver_name'}); + my $existing = "( SELECT COUNT(*) FROM cust_event WHERE cust_event.eventpart = part_event.eventpart AND cust_event.tablenum = $tablenum{$table} AND status != 'failed' )"; - "$existing <= ". $class->condition_sql_option_integer('run_times'); + "$existing <= $run_times"; } -- 2.11.0