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 dstsvc - svcnum of the destination of the forward (see L<FS::svc_acct>)
52 =item dst - foreign destination (email address) - forward not local to freeside
62 Creates a new mail forwarding alias. To add the mail forwarding alias to the
63 database, see L<"insert">.
67 sub table { 'svc_forward'; }
71 Adds this mail forwarding alias to the database. If there is an error, returns
72 the error, otherwise returns false.
74 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
75 defined. An FS::cust_svc record will be created and inserted.
83 local $SIG{HUP} = 'IGNORE';
84 local $SIG{INT} = 'IGNORE';
85 local $SIG{QUIT} = 'IGNORE';
86 local $SIG{TERM} = 'IGNORE';
87 local $SIG{TSTP} = 'IGNORE';
88 local $SIG{PIPE} = 'IGNORE';
90 my $oldAutoCommit = $FS::UID::AutoCommit;
91 local $FS::UID::AutoCommit = 0;
94 $error = $self->check;
95 return $error if $error;
97 $error = $self->SUPER::insert;
99 $dbh->rollback if $oldAutoCommit;
103 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
110 Deletes this mail forwarding alias from the database. If there is an error,
111 returns the error, otherwise returns false.
113 The corresponding FS::cust_svc record will be deleted as well.
120 local $SIG{HUP} = 'IGNORE';
121 local $SIG{INT} = 'IGNORE';
122 local $SIG{QUIT} = 'IGNORE';
123 local $SIG{TERM} = 'IGNORE';
124 local $SIG{TSTP} = 'IGNORE';
125 local $SIG{PIPE} = 'IGNORE';
127 my $oldAutoCommit = $FS::UID::AutoCommit;
128 local $FS::UID::Autocommit = 0;
131 my $error = $self->SUPER::delete;
133 $dbh->rollback if $oldAutoCommit;
137 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
142 =item replace OLD_RECORD
144 Replaces OLD_RECORD with this one in the database. If there is an error,
145 returns the error, otherwise returns false.
150 my ( $new, $old ) = ( shift, shift );
152 if ( $new->srcsvc != $old->srcsvc
153 && ( $new->dstsvc != $old->dstsvc
154 || ! $new->dstsvc && $new->dst ne $old->dst
157 return "Can't change both source and destination of a mail forward!"
160 local $SIG{HUP} = 'IGNORE';
161 local $SIG{INT} = 'IGNORE';
162 local $SIG{QUIT} = 'IGNORE';
163 local $SIG{TERM} = 'IGNORE';
164 local $SIG{TSTP} = 'IGNORE';
165 local $SIG{PIPE} = 'IGNORE';
167 my $oldAutoCommit = $FS::UID::AutoCommit;
168 local $FS::UID::AutoCommit = 0;
171 my $error = $new->SUPER::replace($old);
173 $dbh->rollback if $oldAutoCommit;
177 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
183 Just returns false (no error) for now.
185 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
189 Just returns false (no error) for now.
191 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
195 Just returns false (no error) for now.
197 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
201 Checks all fields to make sure this is a valid mail forwarding alias. If there
202 is an error, returns the error, otherwise returns false. Called by the insert
205 Sets any fixed values; see L<FS::part_svc>.
212 my $x = $self->setfixed;
213 return $x unless ref($x);
216 my $error = $self->ut_numbern('svcnum')
217 || $self->ut_number('srcsvc')
218 || $self->ut_numbern('dstsvc')
220 return $error if $error;
222 return "Unknown srcsvc" unless $self->srcsvc_acct;
224 return "Both dstsvc and dst were defined; only one can be specified"
225 if $self->dstsvc && $self->dst;
227 return "one of dstsvc or dst is required"
228 unless $self->dstsvc || $self->dst;
230 #return "Unknown dstsvc: $dstsvc" unless $self->dstsvc_acct || ! $self->dstsvc;
231 return "Unknown dstsvc"
232 unless qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } )
237 $self->dst =~ /^([\w\.\-]+)\@(([\w\-]+\.)+\w+)$/
238 or return "Illegal dst: ". $self->dst;
239 $self->dst("$1\@$2");
249 Returns the FS::svc_acct object referenced by the srcsvc column.
255 qsearchs('svc_acct', { 'svcnum' => $self->srcsvc } );
260 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
261 forwards not local to freeside.
267 qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } );
276 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
277 L<FS::svc_acct>, L<FS::svc_domain>, schema.html from the base documentation.