1 package FS::svc_forward;
6 use FS::Record qw( fields qsearch qsearchs dbh );
12 @ISA = qw( FS::svc_Common );
16 FS::svc_forward - Object methods for svc_forward records
22 $record = new FS::svc_forward \%hash;
23 $record = new FS::svc_forward { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
33 $error = $record->suspend;
35 $error = $record->unsuspend;
37 $error = $record->cancel;
41 An FS::svc_forward object represents a mail forwarding alias. FS::svc_forward
42 inherits from FS::Record. The following fields are currently supported:
46 =item svcnum - primary key (assigned automatcially for new accounts)
48 =item srcsvc - svcnum of the source of the forward (see L<FS::svc_acct>)
50 =item src - literal source (username or full email address)
52 =item dstsvc - svcnum of the destination of the forward (see L<FS::svc_acct>)
54 =item dst - literal destination (username or full email address)
64 Creates a new mail forwarding alias. To add the mail forwarding alias to the
65 database, see L<"insert">.
73 'name_plural' => 'Mail forwards',
74 'display_weight' => 30,
75 'cancel_weight' => 30,
77 'srcsvc' => 'service from which mail is to be forwarded',
78 'dstsvc' => 'service to which mail is to be forwarded',
79 'dst' => 'someone@another.domain.com to use when dstsvc is 0',
84 sub table { 'svc_forward'; }
86 =item search_sql STRING
88 Class method which returns an SQL fragment to search for the given string.
93 my( $class, $string ) = @_;
94 $class->search_sql_field('src', $string);
97 =item label [ END_TIMESTAMP [ START_TIMESTAMP ] ]
99 Returns a text string representing this forward.
101 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
110 if ( $self->srcsvc ) {
111 my $svc_acct = $self->srcsvc_acct(@_);
112 $tag = $svc_acct->email(@_);
119 if ( $self->dstsvc ) {
120 my $svc_acct = $self->dstsvc_acct(@_);
121 $tag .= $svc_acct->email(@_);
130 =item insert [ , OPTION => VALUE ... ]
132 Adds this mail forwarding alias to the database. If there is an error, returns
133 the error, otherwise returns false.
135 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
136 defined. An FS::cust_svc record will be created and inserted.
138 Currently available options are: I<depend_jobnum>
140 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
141 jobnums), all provisioning jobs will have a dependancy on the supplied
142 jobnum(s) (they will not run until the specific job(s) complete(s)).
150 local $SIG{HUP} = 'IGNORE';
151 local $SIG{INT} = 'IGNORE';
152 local $SIG{QUIT} = 'IGNORE';
153 local $SIG{TERM} = 'IGNORE';
154 local $SIG{TSTP} = 'IGNORE';
155 local $SIG{PIPE} = 'IGNORE';
157 my $oldAutoCommit = $FS::UID::AutoCommit;
158 local $FS::UID::AutoCommit = 0;
161 $error = $self->check;
162 return $error if $error;
164 $error = $self->SUPER::insert(@_);
166 $dbh->rollback if $oldAutoCommit;
170 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
177 Deletes this mail forwarding alias from the database. If there is an error,
178 returns the error, otherwise returns false.
180 The corresponding FS::cust_svc record will be deleted as well.
187 local $SIG{HUP} = 'IGNORE';
188 local $SIG{INT} = 'IGNORE';
189 local $SIG{QUIT} = 'IGNORE';
190 local $SIG{TERM} = 'IGNORE';
191 local $SIG{TSTP} = 'IGNORE';
192 local $SIG{PIPE} = 'IGNORE';
194 my $oldAutoCommit = $FS::UID::AutoCommit;
195 local $FS::UID::Autocommit = 0;
198 my $error = $self->SUPER::delete(@_);
200 $dbh->rollback if $oldAutoCommit;
204 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
209 =item replace OLD_RECORD
211 Replaces OLD_RECORD with this one in the database. If there is an error,
212 returns the error, otherwise returns false.
217 my ( $new, $old ) = ( shift, shift );
219 if ( $new->srcsvc != $old->srcsvc
220 && ( $new->dstsvc != $old->dstsvc
221 || ! $new->dstsvc && $new->dst ne $old->dst
224 return "Can't change both source and destination of a mail forward!"
227 local $SIG{HUP} = 'IGNORE';
228 local $SIG{INT} = 'IGNORE';
229 local $SIG{QUIT} = 'IGNORE';
230 local $SIG{TERM} = 'IGNORE';
231 local $SIG{TSTP} = 'IGNORE';
232 local $SIG{PIPE} = 'IGNORE';
234 my $oldAutoCommit = $FS::UID::AutoCommit;
235 local $FS::UID::AutoCommit = 0;
238 my $error = $new->SUPER::replace($old, @_);
240 $dbh->rollback if $oldAutoCommit;
244 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
250 Just returns false (no error) for now.
252 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
256 Just returns false (no error) for now.
258 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
262 Just returns false (no error) for now.
264 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
268 Checks all fields to make sure this is a valid mail forwarding alias. If there
269 is an error, returns the error, otherwise returns false. Called by the insert
272 Sets any fixed values; see L<FS::part_svc>.
279 my $x = $self->setfixed;
280 return $x unless ref($x);
283 my $error = $self->ut_numbern('svcnum')
284 || $self->ut_numbern('srcsvc')
285 || $self->ut_numbern('dstsvc')
287 return $error if $error;
289 return "Both srcsvc and src were defined; only one can be specified"
290 if $self->srcsvc && $self->src;
292 return "one of srcsvc or src is required"
293 unless $self->srcsvc || $self->src;
295 return "Unknown srcsvc: ". $self->srcsvc
296 unless ! $self->srcsvc || $self->srcsvc_acct;
298 return "Both dstsvc and dst were defined; only one can be specified"
299 if $self->dstsvc && $self->dst;
301 return "one of dstsvc or dst is required"
302 unless $self->dstsvc || $self->dst;
304 return "Unknown dstsvc: ". $self->dstsvc
305 unless ! $self->dstsvc || $self->dstsvc_acct;
306 #return "Unknown dstsvc"
307 # unless qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } )
308 # || ! $self->dstsvc;
311 $self->src =~ /^([\w\.\-\&]*)(\@([\w\-]+\.)+\w+)$/
312 or return "Illegal src: ". $self->src;
319 my $conf = new FS::Conf;
320 if ( $conf->exists('svc_forward-arbitrary_dst') ) {
321 my $error = $self->ut_textn('dst');
322 return $error if $error;
324 $self->dst =~ /^([\w\.\-\&]*)(\@([\w\-]+\.)+\w+)$/
325 or return "Illegal dst: ". $self->dst;
337 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
338 literally specified forwards.
344 qsearchs('svc_acct', { 'svcnum' => $self->srcsvc } );
349 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
350 literally specified forwards.
356 qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } );
365 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
366 L<FS::svc_acct>, L<FS::svc_domain>, schema.html from the base documentation.