This commit was generated by cvs2svn to compensate for changes in r5562,
[freeside.git] / FS / FS / part_event / Condition / once.pm
1 package FS::part_event::Condition::once;
2
3 use strict;
4 use FS::Record qw( qsearch );
5 use FS::part_event;
6 use FS::cust_event;
7
8 use base qw( FS::part_event::Condition );
9
10 sub description { "Don't run this event again after it has completed sucessfully"; }
11
12 sub implicit_flag { 10; }
13
14 sub remove_warning {
15   'Are you sure you want to remove this condition?  Doing so will allow this event to run every time the other conditions are satisfied, even if it has already run sucessfully.'; #better error msg?
16 }
17
18 sub condition {
19   my($self, $object) = @_;
20
21   my $obj_pkey = $object->primary_key;
22   my $tablenum = $object->$obj_pkey();
23   
24   my @existing = qsearch( 'cust_event', {
25     'eventpart' => $self->eventpart,
26     'tablenum'  => $tablenum,
27     'status'    => { op=>'!=', value=>'failed' },
28   } );
29
30   ! scalar(@existing);
31
32 }
33
34 sub condition_sql {
35   my( $self, $table ) = @_;
36
37   my %tablenum = %{ FS::part_event->eventtable_pkey_sql };
38
39   "0 = ( SELECT COUNT(*) FROM cust_event
40            WHERE cust_event.eventpart = part_event.eventpart
41              AND cust_event.tablenum = $tablenum{$table}
42              AND status != 'failed'
43        )
44   ";
45
46 }
47
48 1;