This commit was generated by cvs2svn to compensate for changes in r11022,
[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 successfully"; }
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, %opt) = @_;
20
21   my $obj_pkey = $object->primary_key;
22   my $tablenum = $object->$obj_pkey();
23  
24   my @existing = qsearch( {
25     'table'     => 'cust_event',
26     'hashref'   => {
27                      'eventpart' => $self->eventpart,
28                      'tablenum'  => $tablenum,
29                      'status'    => { op=>'!=', value=>'failed' },
30                    },
31     'extra_sql' => ( $opt{'cust_event'}->eventnum =~ /^(\d+)$/
32                        ? " AND eventnum != $1 "
33                        : ''
34                    ),
35   } );
36
37   ! scalar(@existing);
38
39 }
40
41 sub condition_sql {
42   my( $self, $table ) = @_;
43
44   my %tablenum = %{ FS::part_event->eventtable_pkey_sql };
45
46   "0 = ( SELECT COUNT(*) FROM cust_event
47            WHERE cust_event.eventpart = part_event.eventpart
48              AND cust_event.tablenum = $tablenum{$table}
49              AND status != 'failed'
50        )
51   ";
52
53 }
54
55 1;