1 package FS::svc_Common;
4 use vars qw( @ISA $noexport_hack );
5 use FS::Record qw( qsearchs fields dbh );
10 @ISA = qw( FS::Record );
14 FS::svc_Common - Object method for all svc_ records
20 @ISA = qw( FS::svc_Common );
24 FS::svc_Common is intended as a base class for table-specific classes to
25 inherit from, i.e. FS::svc_acct. FS::svc_Common inherits from FS::Record.
31 =item insert [ JOBNUM_ARRAYREF ]
33 Adds this record to the database. If there is an error, returns the error,
34 otherwise returns false.
36 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
37 defined. An FS::cust_svc record will be created and inserted.
39 If an arrayref is passed as parameter, the B<jobnum>s of any export jobs will
40 be added to the array.
46 local $FS::queue::jobnums = shift if @_;
49 local $SIG{HUP} = 'IGNORE';
50 local $SIG{INT} = 'IGNORE';
51 local $SIG{QUIT} = 'IGNORE';
52 local $SIG{TERM} = 'IGNORE';
53 local $SIG{TSTP} = 'IGNORE';
54 local $SIG{PIPE} = 'IGNORE';
56 my $oldAutoCommit = $FS::UID::AutoCommit;
57 local $FS::UID::AutoCommit = 0;
60 $error = $self->check;
61 return $error if $error;
63 my $svcnum = $self->svcnum;
66 $cust_svc = new FS::cust_svc ( {
67 #hua?# 'svcnum' => $svcnum,
68 'pkgnum' => $self->pkgnum,
69 'svcpart' => $self->svcpart,
71 $error = $cust_svc->insert;
73 $dbh->rollback if $oldAutoCommit;
76 $svcnum = $self->svcnum($cust_svc->svcnum);
78 $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
79 unless ( $cust_svc ) {
80 $dbh->rollback if $oldAutoCommit;
81 return "no cust_svc record found for svcnum ". $self->svcnum;
83 $self->pkgnum($cust_svc->pkgnum);
84 $self->svcpart($cust_svc->svcpart);
87 $error = $self->SUPER::insert;
89 $dbh->rollback if $oldAutoCommit;
94 unless ( $noexport_hack ) {
95 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
96 my $error = $part_export->export_insert($self);
98 $dbh->rollback if $oldAutoCommit;
99 return "exporting to ". $part_export->exporttype.
100 " (transaction rolled back): $error";
105 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
112 Deletes this account from the database. If there is an error, returns the
113 error, otherwise returns false.
115 The corresponding FS::cust_svc record will be deleted as well.
123 local $SIG{HUP} = 'IGNORE';
124 local $SIG{INT} = 'IGNORE';
125 local $SIG{QUIT} = 'IGNORE';
126 local $SIG{TERM} = 'IGNORE';
127 local $SIG{TSTP} = 'IGNORE';
128 local $SIG{PIPE} = 'IGNORE';
130 my $svcnum = $self->svcnum;
132 my $oldAutoCommit = $FS::UID::AutoCommit;
133 local $FS::UID::AutoCommit = 0;
136 $error = $self->SUPER::delete;
137 return $error if $error;
140 unless ( $noexport_hack ) {
141 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
142 my $error = $part_export->export_delete($self);
144 $dbh->rollback if $oldAutoCommit;
145 return "exporting to ". $part_export->exporttype.
146 " (transaction rolled back): $error";
151 return $error if $error;
153 my $cust_svc = $self->cust_svc;
154 $error = $cust_svc->delete;
155 return $error if $error;
157 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
162 =item replace OLD_RECORD
164 Replaces OLD_RECORD with this one. If there is an error, returns the error,
165 otherwise returns false.
170 my ($new, $old) = (shift, shift);
172 local $SIG{HUP} = 'IGNORE';
173 local $SIG{INT} = 'IGNORE';
174 local $SIG{QUIT} = 'IGNORE';
175 local $SIG{TERM} = 'IGNORE';
176 local $SIG{TSTP} = 'IGNORE';
177 local $SIG{PIPE} = 'IGNORE';
179 my $oldAutoCommit = $FS::UID::AutoCommit;
180 local $FS::UID::AutoCommit = 0;
183 my $error = $new->SUPER::replace($old);
185 $dbh->rollback if $oldAutoCommit;
190 unless ( $noexport_hack ) {
191 foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
192 my $error = $part_export->export_replace($new,$old);
194 $dbh->rollback if $oldAutoCommit;
195 return "error exporting to ". $part_export->exporttype.
196 " (transaction rolled back): $error";
201 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
208 Sets any fixed fields for this service (see L<FS::part_svc>). If there is an
209 error, returns the error, otherwise returns the FS::part_svc object (use ref()
210 to test the return). Usually called by the check method.
221 Sets all fields to their defaults (see L<FS::part_svc>), overriding their
222 current values. If there is an error, returns the error, otherwise returns
223 the FS::part_svc object (use ref() to test the return).
239 $self->ut_numbern('svcnum')
241 return $error if $error;
245 if ( $self->svcnum ) {
246 my $cust_svc = $self->cust_svc;
247 return "Unknown svcnum" unless $cust_svc;
248 $svcpart = $cust_svc->svcpart;
250 $svcpart = $self->getfield('svcpart');
252 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
253 return "Unkonwn svcpart" unless $part_svc;
255 #set default/fixed/whatever fields from part_svc
256 my $table = $self->table;
257 foreach my $field ( grep { $_ ne 'svcnum' } fields($table) ) {
258 my $part_svc_column = $part_svc->part_svc_column($field);
259 if ( $part_svc_column->columnflag eq $x ) {
260 $self->setfield( $field, $part_svc_column->columnvalue );
270 Returns the cust_svc record associated with this svc_ record, as a FS::cust_svc
271 object (see L<FS::cust_svc>).
277 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
282 Runs export_suspend callbacks.
289 local $SIG{HUP} = 'IGNORE';
290 local $SIG{INT} = 'IGNORE';
291 local $SIG{QUIT} = 'IGNORE';
292 local $SIG{TERM} = 'IGNORE';
293 local $SIG{TSTP} = 'IGNORE';
294 local $SIG{PIPE} = 'IGNORE';
296 my $oldAutoCommit = $FS::UID::AutoCommit;
297 local $FS::UID::AutoCommit = 0;
301 unless ( $noexport_hack ) {
302 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
303 my $error = $part_export->export_suspend($self);
305 $dbh->rollback if $oldAutoCommit;
306 return "error exporting to ". $part_export->exporttype.
307 " (transaction rolled back): $error";
312 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
319 Runs export_unsuspend callbacks.
326 local $SIG{HUP} = 'IGNORE';
327 local $SIG{INT} = 'IGNORE';
328 local $SIG{QUIT} = 'IGNORE';
329 local $SIG{TERM} = 'IGNORE';
330 local $SIG{TSTP} = 'IGNORE';
331 local $SIG{PIPE} = 'IGNORE';
333 my $oldAutoCommit = $FS::UID::AutoCommit;
334 local $FS::UID::AutoCommit = 0;
338 unless ( $noexport_hack ) {
339 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
340 my $error = $part_export->export_unsuspend($self);
342 $dbh->rollback if $oldAutoCommit;
343 return "error exporting to ". $part_export->exporttype.
344 " (transaction rolled back): $error";
349 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
356 Stub - returns false (no error) so derived classes don't need to define these
357 methods. Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
367 $Id: svc_Common.pm,v 1.12 2002-06-14 11:22:53 ivan Exp $
371 The setfixed method return value.
375 L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, schema.html
376 from the base documentation.