X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fonce.pm;h=f1645828b6bfa84dd1be5f449d56555ffecc1733;hb=2322f0123062b8cf2f52aed0a63bb4634cdbaef1;hp=adab2432aa158bb84d4ba9fd368265fc025c551e;hpb=8b33800764316232933f5996ac3fe9ea1793d944;p=freeside.git diff --git a/FS/FS/part_event/Condition/once.pm b/FS/FS/part_event/Condition/once.pm index adab2432a..f1645828b 100644 --- a/FS/FS/part_event/Condition/once.pm +++ b/FS/FS/part_event/Condition/once.pm @@ -7,7 +7,7 @@ use FS::cust_event; use base qw( FS::part_event::Condition ); -sub description { "Don't run this event again after it has completed sucessfully"; } +sub description { "Don't run this event again after it has completed successfully"; } sub implicit_flag { 10; } @@ -20,19 +20,18 @@ sub condition { my $obj_pkey = $object->primary_key; my $tablenum = $object->$obj_pkey(); - + my @existing = qsearch( { - 'table' => 'cust_event', - 'hashref' => { - 'eventpart' => $self->eventpart, - 'tablenum' => $tablenum, - #'status' => { op=>'NOT IN', value=>"('failed','new')" }, - 'status' => { op=>'!=', value=>'failed' }, - }, - 'addl_sql' => ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/ - ? " AND eventnum != $1 " - : '' - ), + 'table' => 'cust_event', + 'hashref' => { + 'eventpart' => $self->eventpart, + 'tablenum' => $tablenum, + 'status' => { op=>'!=', value=>'failed' }, + }, + 'extra_sql' => ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/ + ? " AND eventnum != $1 " + : '' + ), } ); ! scalar(@existing); @@ -44,11 +43,12 @@ sub condition_sql { my %tablenum = %{ FS::part_event->eventtable_pkey_sql }; - "0 = ( SELECT COUNT(*) FROM cust_event - WHERE cust_event.eventpart = part_event.eventpart - AND cust_event.tablenum = $tablenum{$table} - AND status != 'failed' - ) + "NOT EXISTS ( SELECT 1 FROM cust_event + WHERE cust_event.eventpart = part_event.eventpart + AND cust_event.tablenum = $tablenum{$table} + AND status != 'failed' + LIMIT 1 + ) "; }