4 use base qw( FS::o2m_Common FS::Record );
5 use FS::Record qw( qsearch qsearchs dbh );
7 use FS::cgp_rule_condition;
8 use FS::cgp_rule_action;
12 FS::cgp_rule - Object methods for cgp_rule records
18 $record = new FS::cgp_rule \%hash;
19 $record = new FS::cgp_rule { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::cgp_rule object represents a mail filtering rule. FS::cgp_rule
32 inherits from FS::Record. The following fields are currently supported:
65 Creates a new rule. To add the rule to the database, see L<"insert">.
67 Note that this stores the hash reference, not a distinct copy of the hash it
68 points to. You can ask the object for a copy with the I<hash> method.
72 # the new method can be inherited from FS::Record, if a table method is defined
74 sub table { 'cgp_rule'; }
78 Adds this record to the database. If there is an error, returns the error,
79 otherwise returns false.
83 # the insert method can be inherited from FS::Record
87 Delete this record from the database.
94 local $SIG{HUP} = 'IGNORE';
95 local $SIG{INT} = 'IGNORE';
96 local $SIG{QUIT} = 'IGNORE';
97 local $SIG{TERM} = 'IGNORE';
98 local $SIG{TSTP} = 'IGNORE';
99 local $SIG{PIPE} = 'IGNORE';
101 my $oldAutoCommit = $FS::UID::AutoCommit;
102 local $FS::UID::AutoCommit = 0;
105 my @del = $self->cgp_rule_condition;
106 push @del, $self->cgp_rule_action;
108 foreach my $del (@del) {
109 my $error = $del->delete;
111 $dbh->rollback if $oldAutoCommit;
116 my $error = $self->SUPER::delete(@_);
118 $dbh->rollback if $oldAutoCommit;
122 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
126 =item replace OLD_RECORD
128 Replaces the OLD_RECORD with this one in the database. If there is an error,
129 returns the error, otherwise returns false.
133 # the replace method can be inherited from FS::Record
137 Checks all fields to make sure this is a valid rule. If there is
138 an error, returns the error, otherwise returns false. Called by the insert
143 # the check method should currently be supplied - FS::Record contains some
144 # data checking routines
150 $self->ut_numbern('rulenum')
151 || $self->ut_text('name')
152 || $self->ut_textn('comment')
153 || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum')
154 || $self->ut_number('priority')
156 return $error if $error;
167 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
170 =item cgp_rule_condition
172 Returns the conditions associated with this rule, as FS::cgp_rule_condition
177 sub cgp_rule_condition {
179 qsearch('cgp_rule_condition', { 'rulenum' => $self->rulenum } );
182 =item cgp_rule_action
184 Returns the actions associated with this rule, as FS::cgp_rule_action
189 sub cgp_rule_action {
191 qsearch('cgp_rule_action', { 'rulenum' => $self->rulenum } );
200 L<FS::Record>, schema.html from the base documentation.