summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition/once.pm
diff options
context:
space:
mode:
authorivan <ivan>2007-08-01 22:26:52 +0000
committerivan <ivan>2007-08-01 22:26:52 +0000
commiteb4ff7f73c5d4bdf74a3472448b5a195598ff4cd (patch)
treebb38241e8c865c3bca861da7749071feeadd2b5b /FS/FS/part_event/Condition/once.pm
parent32b5d3a31f112a381f0a15ac5e3a2204242f3405 (diff)
event refactor, landing on HEAD!
Diffstat (limited to 'FS/FS/part_event/Condition/once.pm')
-rw-r--r--FS/FS/part_event/Condition/once.pm48
1 files changed, 48 insertions, 0 deletions
diff --git a/FS/FS/part_event/Condition/once.pm b/FS/FS/part_event/Condition/once.pm
new file mode 100644
index 0000000..8c24e83
--- /dev/null
+++ b/FS/FS/part_event/Condition/once.pm
@@ -0,0 +1,48 @@
+package FS::part_event::Condition::once;
+
+use strict;
+use FS::Record qw( qsearch );
+use FS::part_event;
+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 implicit_flag { 10; }
+
+sub remove_warning {
+ '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?
+}
+
+sub condition {
+ my($self, $object) = @_;
+
+ my $obj_pkey = $object->primary_key;
+ my $tablenum = $object->$obj_pkey();
+
+ my @existing = qsearch( 'cust_event', {
+ 'eventpart' => $self->eventpart,
+ 'tablenum' => $tablenum,
+ 'status' => { op=>'!=', value=>'failed' },
+ } );
+
+ ! scalar(@existing);
+
+}
+
+sub condition_sql {
+ my( $self, $table ) = @_;
+
+ 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'
+ )
+ ";
+
+}
+
+1;