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'; }
69 =item insert [ , OPTION => VALUE ... ]
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.
77 Currently available options are: I<depend_jobnum>
79 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
80 jobnums), all provisioning jobs will have a dependancy on the supplied
81 jobnum(s) (they will not run until the specific job(s) complete(s)).
89 local $SIG{HUP} = 'IGNORE';
90 local $SIG{INT} = 'IGNORE';
91 local $SIG{QUIT} = 'IGNORE';
92 local $SIG{TERM} = 'IGNORE';
93 local $SIG{TSTP} = 'IGNORE';
94 local $SIG{PIPE} = 'IGNORE';
96 my $oldAutoCommit = $FS::UID::AutoCommit;
97 local $FS::UID::AutoCommit = 0;
100 $error = $self->check;
101 return $error if $error;
103 $error = $self->SUPER::insert(@_);
105 $dbh->rollback if $oldAutoCommit;
109 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
116 Deletes this mail forwarding alias from the database. If there is an error,
117 returns the error, otherwise returns false.
119 The corresponding FS::cust_svc record will be deleted as well.
126 local $SIG{HUP} = 'IGNORE';
127 local $SIG{INT} = 'IGNORE';
128 local $SIG{QUIT} = 'IGNORE';
129 local $SIG{TERM} = 'IGNORE';
130 local $SIG{TSTP} = 'IGNORE';
131 local $SIG{PIPE} = 'IGNORE';
133 my $oldAutoCommit = $FS::UID::AutoCommit;
134 local $FS::UID::Autocommit = 0;
137 my $error = $self->SUPER::delete;
139 $dbh->rollback if $oldAutoCommit;
143 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
148 =item replace OLD_RECORD
150 Replaces OLD_RECORD with this one in the database. If there is an error,
151 returns the error, otherwise returns false.
156 my ( $new, $old ) = ( shift, shift );
158 if ( $new->srcsvc != $old->srcsvc
159 && ( $new->dstsvc != $old->dstsvc
160 || ! $new->dstsvc && $new->dst ne $old->dst
163 return "Can't change both source and destination of a mail forward!"
166 local $SIG{HUP} = 'IGNORE';
167 local $SIG{INT} = 'IGNORE';
168 local $SIG{QUIT} = 'IGNORE';
169 local $SIG{TERM} = 'IGNORE';
170 local $SIG{TSTP} = 'IGNORE';
171 local $SIG{PIPE} = 'IGNORE';
173 my $oldAutoCommit = $FS::UID::AutoCommit;
174 local $FS::UID::AutoCommit = 0;
177 my $error = $new->SUPER::replace($old);
179 $dbh->rollback if $oldAutoCommit;
183 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
189 Just returns false (no error) for now.
191 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
195 Just returns false (no error) for now.
197 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
201 Just returns false (no error) for now.
203 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
207 Checks all fields to make sure this is a valid mail forwarding alias. If there
208 is an error, returns the error, otherwise returns false. Called by the insert
211 Sets any fixed values; see L<FS::part_svc>.
218 my $x = $self->setfixed;
219 return $x unless ref($x);
222 my $error = $self->ut_numbern('svcnum')
223 || $self->ut_number('srcsvc')
224 || $self->ut_numbern('dstsvc')
226 return $error if $error;
228 return "Unknown srcsvc" unless $self->srcsvc_acct;
230 return "Both dstsvc and dst were defined; only one can be specified"
231 if $self->dstsvc && $self->dst;
233 return "one of dstsvc or dst is required"
234 unless $self->dstsvc || $self->dst;
236 #return "Unknown dstsvc: $dstsvc" unless $self->dstsvc_acct || ! $self->dstsvc;
237 return "Unknown dstsvc"
238 unless qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } )
243 $self->dst =~ /^([\w\.\-]+)\@(([\w\-]+\.)+\w+)$/
244 or return "Illegal dst: ". $self->dst;
245 $self->dst("$1\@$2");
255 Returns the FS::svc_acct object referenced by the srcsvc column.
261 qsearchs('svc_acct', { 'svcnum' => $self->srcsvc } );
266 Returns the FS::svc_acct object referenced by the srcsvc column, or false for
267 forwards not local to freeside.
273 qsearchs('svc_acct', { 'svcnum' => $self->dstsvc } );
282 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
283 L<FS::svc_acct>, L<FS::svc_domain>, schema.html from the base documentation.