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'; }
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.
85 local $SIG{HUP} = 'IGNORE';
86 local $SIG{INT} = 'IGNORE';
87 local $SIG{QUIT} = 'IGNORE';
88 local $SIG{TERM} = 'IGNORE';
89 local $SIG{TSTP} = 'IGNORE';
90 local $SIG{PIPE} = 'IGNORE';
92 my $oldAutoCommit = $FS::UID::AutoCommit;
93 local $FS::UID::AutoCommit = 0;
96 $error = $self->check;
97 return $error if $error;
99 $error = $self->SUPER::insert;
101 $dbh->rollback if $oldAutoCommit;
105 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
112 Deletes this mail forwarding alias from the database. If there is an error,
113 returns the error, otherwise returns false.
115 The corresponding FS::cust_svc record will be deleted as well.
122 local $SIG{HUP} = 'IGNORE';
123 local $SIG{INT} = 'IGNORE';
124 local $SIG{QUIT} = 'IGNORE';
125 local $SIG{TERM} = 'IGNORE';
126 local $SIG{TSTP} = 'IGNORE';
127 local $SIG{PIPE} = 'IGNORE';
129 my $oldAutoCommit = $FS::UID::AutoCommit;
130 local $FS::UID::Autocommit = 0;
133 my $error = $self->SUPER::delete;
135 $dbh->rollback if $oldAutoCommit;
139 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
144 =item replace OLD_RECORD
146 Replaces OLD_RECORD with this one in the database. If there is an error,
147 returns the error, otherwise returns false.
152 my ( $new, $old ) = ( shift, shift );
154 if ( $new->srcsvc != $old->srcsvc
155 && ( $new->dstsvc != $old->dstsvc
156 || ! $new->dstsvc && $new->dst ne $old->dst
159 return "Can't change both source and destination of a mail forward!"
162 local $SIG{HUP} = 'IGNORE';
163 local $SIG{INT} = 'IGNORE';
164 local $SIG{QUIT} = 'IGNORE';
165 local $SIG{TERM} = 'IGNORE';
166 local $SIG{TSTP} = 'IGNORE';
167 local $SIG{PIPE} = 'IGNORE';
169 my $oldAutoCommit = $FS::UID::AutoCommit;
170 local $FS::UID::AutoCommit = 0;
173 my $error = $new->SUPER::replace($old);
175 $dbh->rollback if $oldAutoCommit;
179 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
185 Just returns false (no error) for now.
187 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
191 Just returns false (no error) for now.
193 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
197 Just returns false (no error) for now.
199 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
203 Checks all fields to make sure this is a valid mail forwarding alias. If there
204 is an error, returns the error, otherwise returns false. Called by the insert
207 Sets any fixed values; see L<FS::part_svc>.
214 my $x = $self->setfixed;
215 return $x unless ref($x);
218 my $error = $self->ut_numbern('svcnum')
219 || $self->ut_numbern('srcsvc')
220 || $self->ut_numbern('dstsvc')
222 return $error if $error;
224 return "Both srcsvc and src were defined; only one can be specified"
225 if $self->srcsvc && $self->src;
227 return "one of srcsvc or src is required"
228 unless $self->srcsvc || $self->src;
230 return "Unknown srcsvc: ". $self->srcsvc
231 unless ! $self->srcsvc || $self->srcsvc_acct;
233 return "Both dstsvc and dst were defined; only one can be specified"
234 if $self->dstsvc && $self->dst;
236 return "one of dstsvc or dst is required"
237 unless $self->dstsvc || $self->dst;
239 return "Unknown dstsvc: ". $self->dstsvc
240 unless ! $self->dstsvc || $self->dstsvc_acct;
241 #return "Unknown dstsvc"
242 # unless qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } )
243 # || ! $self->dstsvc;
246 $self->src =~ /^([\w\.\-\&]*)(\@([\w\-]+\.)+\w+)?$/
247 or return "Illegal src: ". $self->dst;
254 $self->dst =~ /^([\w\.\-\&]*)(\@([\w\-]+\.)+\w+)?$/
255 or return "Illegal dst: ". $self->dst;
266 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
267 literally specified forwards.
273 qsearchs('svc_acct', { 'svcnum' => $self->srcsvc } );
278 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
279 literally specified forwards.
285 qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } );
294 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
295 L<FS::svc_acct>, L<FS::svc_domain>, schema.html from the base documentation.