summaryrefslogtreecommitdiff
path: root/FS/FS/cgp_rule.pm
diff options
context:
space:
mode:
authorivan <ivan>2010-04-23 06:47:38 +0000
committerivan <ivan>2010-04-23 06:47:38 +0000
commit37591b61f8ad6fc5c5acb2fd8f520d2dbe4f1539 (patch)
tree5a89dc6c073118b973c06f44070b4fbf65dd65e7 /FS/FS/cgp_rule.pm
parent3a201934245c2e72b167804a6d512e0e6d435f65 (diff)
communigate (phase 2): rules. RT#7514
Diffstat (limited to 'FS/FS/cgp_rule.pm')
-rw-r--r--FS/FS/cgp_rule.pm87
1 files changed, 77 insertions, 10 deletions
diff --git a/FS/FS/cgp_rule.pm b/FS/FS/cgp_rule.pm
index 283055f..7e5c9fe 100644
--- a/FS/FS/cgp_rule.pm
+++ b/FS/FS/cgp_rule.pm
@@ -2,7 +2,10 @@ package FS::cgp_rule;
use strict;
use base qw( FS::Record );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
+use FS::cust_svc;
+use FS::cgp_rule_condition;
+use FS::cgp_rule_action;
=head1 NAME
@@ -25,8 +28,8 @@ FS::cgp_rule - Object methods for cgp_rule records
=head1 DESCRIPTION
-An FS::cgp_rule object represents an example. FS::cgp_rule inherits from
-FS::Record. The following fields are currently supported:
+An FS::cgp_rule object represents a mail filtering rule. FS::cgp_rule
+inherits from FS::Record. The following fields are currently supported:
=over 4
@@ -59,7 +62,7 @@ priority
=item new HASHREF
-Creates a new example. To add the example to the database, see L<"insert">.
+Creates a new rule. To add the rule to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
@@ -85,7 +88,40 @@ Delete this record from the database.
=cut
-# the delete method can be inherited from FS::Record
+sub delete {
+ my $self = shift;
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my @del = $self->cgp_rule_condition;
+ push @del, $self->cgp_rule_action;
+
+ foreach my $del (@del) {
+ my $error = $del->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ my $error = $self->SUPER::delete(@_);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+}
=item replace OLD_RECORD
@@ -98,7 +134,7 @@ returns the error, otherwise returns false.
=item check
-Checks all fields to make sure this is a valid example. If there is
+Checks all fields to make sure this is a valid rule. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
@@ -113,8 +149,8 @@ sub check {
my $error =
$self->ut_numbern('rulenum')
|| $self->ut_text('name')
- || $self->ut_text('comment')
- || $self->ut_number('svcnum')
+ || $self->ut_textn('comment')
+ || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum')
|| $self->ut_number('priority')
;
return $error if $error;
@@ -122,12 +158,43 @@ sub check {
$self->SUPER::check;
}
+=item cust_svc
+
+=cut
+
+sub cust_svc {
+ my $self = shift;
+ qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
+}
+
+=item cgp_rule_condition
+
+Returns the conditions associated with this rule, as FS::cgp_rule_condition
+objects.
+
+=cut
+
+sub cgp_rule_condition {
+ my $self = shift;
+ qsearch('cgp_rule_condition', { 'rulenum' => $self->rulenum } );
+}
+
+=item cgp_rule_action
+
+Returns the actions associated with this rule, as FS::cgp_rule_action
+objects.
+
+=cut
+
+sub cgp_rule_action {
+ my $self = shift;
+ qsearch('cgp_rule_action', { 'rulenum' => $self->rulenum } );
+}
+
=back
=head1 BUGS
-The author forgot to customize this manpage.
-
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.