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">.
69 sub table { 'svc_forward'; }
71 =item insert [ , OPTION => VALUE ... ]
73 Adds this mail forwarding alias to the database. If there is an error, returns
74 the error, otherwise returns false.
76 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
77 defined. An FS::cust_svc record will be created and inserted.
79 Currently available options are: I<depend_jobnum>
81 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
82 jobnums), all provisioning jobs will have a dependancy on the supplied
83 jobnum(s) (they will not run until the specific job(s) complete(s)).
91 local $SIG{HUP} = 'IGNORE';
92 local $SIG{INT} = 'IGNORE';
93 local $SIG{QUIT} = 'IGNORE';
94 local $SIG{TERM} = 'IGNORE';
95 local $SIG{TSTP} = 'IGNORE';
96 local $SIG{PIPE} = 'IGNORE';
98 my $oldAutoCommit = $FS::UID::AutoCommit;
99 local $FS::UID::AutoCommit = 0;
102 $error = $self->check;
103 return $error if $error;
105 $error = $self->SUPER::insert(@_);
107 $dbh->rollback if $oldAutoCommit;
111 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
118 Deletes this mail forwarding alias from the database. If there is an error,
119 returns the error, otherwise returns false.
121 The corresponding FS::cust_svc record will be deleted as well.
128 local $SIG{HUP} = 'IGNORE';
129 local $SIG{INT} = 'IGNORE';
130 local $SIG{QUIT} = 'IGNORE';
131 local $SIG{TERM} = 'IGNORE';
132 local $SIG{TSTP} = 'IGNORE';
133 local $SIG{PIPE} = 'IGNORE';
135 my $oldAutoCommit = $FS::UID::AutoCommit;
136 local $FS::UID::Autocommit = 0;
139 my $error = $self->SUPER::delete;
141 $dbh->rollback if $oldAutoCommit;
145 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
150 =item replace OLD_RECORD
152 Replaces OLD_RECORD with this one in the database. If there is an error,
153 returns the error, otherwise returns false.
158 my ( $new, $old ) = ( shift, shift );
160 if ( $new->srcsvc != $old->srcsvc
161 && ( $new->dstsvc != $old->dstsvc
162 || ! $new->dstsvc && $new->dst ne $old->dst
165 return "Can't change both source and destination of a mail forward!"
168 local $SIG{HUP} = 'IGNORE';
169 local $SIG{INT} = 'IGNORE';
170 local $SIG{QUIT} = 'IGNORE';
171 local $SIG{TERM} = 'IGNORE';
172 local $SIG{TSTP} = 'IGNORE';
173 local $SIG{PIPE} = 'IGNORE';
175 my $oldAutoCommit = $FS::UID::AutoCommit;
176 local $FS::UID::AutoCommit = 0;
179 my $error = $new->SUPER::replace($old);
181 $dbh->rollback if $oldAutoCommit;
185 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
191 Just returns false (no error) for now.
193 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
197 Just returns false (no error) for now.
199 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
203 Just returns false (no error) for now.
205 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
209 Checks all fields to make sure this is a valid mail forwarding alias. If there
210 is an error, returns the error, otherwise returns false. Called by the insert
213 Sets any fixed values; see L<FS::part_svc>.
220 my $x = $self->setfixed;
221 return $x unless ref($x);
224 my $error = $self->ut_numbern('svcnum')
225 || $self->ut_numbern('srcsvc')
226 || $self->ut_numbern('dstsvc')
228 return $error if $error;
230 return "Both srcsvc and src were defined; only one can be specified"
231 if $self->srcsvc && $self->src;
233 return "one of srcsvc or src is required"
234 unless $self->srcsvc || $self->src;
236 return "Unknown srcsvc: ". $self->srcsvc
237 unless ! $self->srcsvc || $self->srcsvc_acct;
239 return "Both dstsvc and dst were defined; only one can be specified"
240 if $self->dstsvc && $self->dst;
242 return "one of dstsvc or dst is required"
243 unless $self->dstsvc || $self->dst;
245 return "Unknown dstsvc: ". $self->dstsvc
246 unless ! $self->dstsvc || $self->dstsvc_acct;
247 #return "Unknown dstsvc"
248 # unless qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } )
249 # || ! $self->dstsvc;
252 $self->src =~ /^([\w\.\-\&]*)(\@([\w\-]+\.)+\w+)$/
253 or return "Illegal src: ". $self->src;
260 $self->dst =~ /^([\w\.\-\&]*)(\@([\w\-]+\.)+\w+)$/
261 or return "Illegal dst: ". $self->dst;
272 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
273 literally specified forwards.
279 qsearchs('svc_acct', { 'svcnum' => $self->srcsvc } );
284 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
285 literally specified forwards.
291 qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } );
300 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
301 L<FS::svc_acct>, L<FS::svc_domain>, schema.html from the base documentation.