1 package FS::svc_Common;
4 use vars qw( @ISA $noexport_hack $DEBUG );
5 use FS::Record qw( qsearchs fields dbh );
10 @ISA = qw( FS::Record );
17 FS::svc_Common - Object method for all svc_ records
23 @ISA = qw( FS::svc_Common );
27 FS::svc_Common is intended as a base class for table-specific classes to
28 inherit from, i.e. FS::svc_acct. FS::svc_Common inherits from FS::Record.
34 =item insert [ , OPTION => VALUE ... ]
36 Adds this record to the database. If there is an error, returns the error,
37 otherwise returns false.
39 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
40 defined. An FS::cust_svc record will be created and inserted.
42 Currently available options are: I<jobnums>, I<child_objects> and
45 If I<jobnum> is set to an array reference, the jobnums of any export jobs will
46 be added to the referenced array.
48 If I<child_objects> is set to an array reference of FS::tablename objects (for
49 example, FS::acct_snarf objects), they will have their svcnum fieldsset and
50 will be inserted after this record, but before any exports are run.
52 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
53 jobnums), all provisioning jobs will have a dependancy on the supplied
54 jobnum(s) (they will not run until the specific job(s) complete(s)).
61 warn "FS::svc_Common::insert called with options ".
62 join(', ', map { "$_: $options{$_}" } keys %options ). "\n"
66 local $FS::queue::jobnums = \@jobnums;
67 warn "FS::svc_Common::insert: set \$FS::queue::jobnums to $FS::queue::jobnums"
69 my $objects = $options{'child_objects'} || [];
70 my $depend_jobnums = $options{'depend_jobnum'} || [];
71 $depend_jobnums = [ $depend_jobnums ] unless ref($depend_jobnums);
74 local $SIG{HUP} = 'IGNORE';
75 local $SIG{INT} = 'IGNORE';
76 local $SIG{QUIT} = 'IGNORE';
77 local $SIG{TERM} = 'IGNORE';
78 local $SIG{TSTP} = 'IGNORE';
79 local $SIG{PIPE} = 'IGNORE';
81 my $oldAutoCommit = $FS::UID::AutoCommit;
82 local $FS::UID::AutoCommit = 0;
85 $error = $self->check;
86 return $error if $error;
88 my $svcnum = $self->svcnum;
89 my $cust_svc = $svcnum ? qsearchs('cust_svc',{'svcnum'=>$self->svcnum}) : '';
91 if ( !$svcnum or !$cust_svc ) {
92 $cust_svc = new FS::cust_svc ( {
93 #hua?# 'svcnum' => $svcnum,
94 'svcnum' => $self->svcnum,
95 'pkgnum' => $self->pkgnum,
96 'svcpart' => $self->svcpart,
98 $error = $cust_svc->insert;
100 $dbh->rollback if $oldAutoCommit;
103 $svcnum = $self->svcnum($cust_svc->svcnum);
105 #$cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
106 unless ( $cust_svc ) {
107 $dbh->rollback if $oldAutoCommit;
108 return "no cust_svc record found for svcnum ". $self->svcnum;
110 $self->pkgnum($cust_svc->pkgnum);
111 $self->svcpart($cust_svc->svcpart);
114 $error = $self->SUPER::insert;
116 $dbh->rollback if $oldAutoCommit;
120 foreach my $object ( @$objects ) {
121 $object->svcnum($self->svcnum);
122 $error = $object->insert;
124 $dbh->rollback if $oldAutoCommit;
130 unless ( $noexport_hack ) {
132 warn "FS::svc_Common::insert: \$FS::queue::jobnums is $FS::queue::jobnums"
135 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
136 my $error = $part_export->export_insert($self);
138 $dbh->rollback if $oldAutoCommit;
139 return "exporting to ". $part_export->exporttype.
140 " (transaction rolled back): $error";
144 foreach my $depend_jobnum ( @$depend_jobnums ) {
145 warn "inserting dependancies on supplied job $depend_jobnum\n"
147 foreach my $jobnum ( @jobnums ) {
148 my $queue = qsearchs('queue', { 'jobnum' => $jobnum } );
149 warn "inserting dependancy for job $jobnum on $depend_jobnum\n"
151 my $error = $queue->depend_insert($depend_jobnum);
153 $dbh->rollback if $oldAutoCommit;
154 return "error queuing job dependancy: $error";
161 if ( exists $options{'jobnums'} ) {
162 push @{ $options{'jobnums'} }, @jobnums;
165 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
172 Deletes this account from the database. If there is an error, returns the
173 error, otherwise returns false.
175 The corresponding FS::cust_svc record will be deleted as well.
183 local $SIG{HUP} = 'IGNORE';
184 local $SIG{INT} = 'IGNORE';
185 local $SIG{QUIT} = 'IGNORE';
186 local $SIG{TERM} = 'IGNORE';
187 local $SIG{TSTP} = 'IGNORE';
188 local $SIG{PIPE} = 'IGNORE';
190 my $svcnum = $self->svcnum;
192 my $oldAutoCommit = $FS::UID::AutoCommit;
193 local $FS::UID::AutoCommit = 0;
196 $error = $self->SUPER::delete;
197 return $error if $error;
200 unless ( $noexport_hack ) {
201 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
202 my $error = $part_export->export_delete($self);
204 $dbh->rollback if $oldAutoCommit;
205 return "exporting to ". $part_export->exporttype.
206 " (transaction rolled back): $error";
211 return $error if $error;
213 my $cust_svc = $self->cust_svc;
214 $error = $cust_svc->delete;
215 return $error if $error;
217 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
222 =item replace OLD_RECORD
224 Replaces OLD_RECORD with this one. If there is an error, returns the error,
225 otherwise returns false.
230 my ($new, $old) = (shift, shift);
232 local $SIG{HUP} = 'IGNORE';
233 local $SIG{INT} = 'IGNORE';
234 local $SIG{QUIT} = 'IGNORE';
235 local $SIG{TERM} = 'IGNORE';
236 local $SIG{TSTP} = 'IGNORE';
237 local $SIG{PIPE} = 'IGNORE';
239 my $oldAutoCommit = $FS::UID::AutoCommit;
240 local $FS::UID::AutoCommit = 0;
243 my $error = $new->SUPER::replace($old);
245 $dbh->rollback if $oldAutoCommit;
250 unless ( $noexport_hack ) {
251 foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
252 my $error = $part_export->export_replace($new,$old);
254 $dbh->rollback if $oldAutoCommit;
255 return "error exporting to ". $part_export->exporttype.
256 " (transaction rolled back): $error";
261 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
268 Sets any fixed fields for this service (see L<FS::part_svc>). If there is an
269 error, returns the error, otherwise returns the FS::part_svc object (use ref()
270 to test the return). Usually called by the check method.
281 Sets all fields to their defaults (see L<FS::part_svc>), overriding their
282 current values. If there is an error, returns the error, otherwise returns
283 the FS::part_svc object (use ref() to test the return).
299 $self->ut_numbern('svcnum')
301 return $error if $error;
305 if ( $self->svcnum && qsearchs('cust_svc', {'svcnum'=>$self->svcnum}) ) {
306 my $cust_svc = $self->cust_svc;
307 return "Unknown svcnum" unless $cust_svc;
308 $svcpart = $cust_svc->svcpart;
310 $svcpart = $self->getfield('svcpart');
312 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
313 return "Unkonwn svcpart" unless $part_svc;
315 #set default/fixed/whatever fields from part_svc
316 my $table = $self->table;
317 foreach my $field ( grep { $_ ne 'svcnum' } fields($table) ) {
318 my $part_svc_column = $part_svc->part_svc_column($field);
319 if ( $part_svc_column->columnflag eq $x ) {
320 $self->setfield( $field, $part_svc_column->columnvalue );
330 Returns the cust_svc record associated with this svc_ record, as a FS::cust_svc
331 object (see L<FS::cust_svc>).
337 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
342 Runs export_suspend callbacks.
349 local $SIG{HUP} = 'IGNORE';
350 local $SIG{INT} = 'IGNORE';
351 local $SIG{QUIT} = 'IGNORE';
352 local $SIG{TERM} = 'IGNORE';
353 local $SIG{TSTP} = 'IGNORE';
354 local $SIG{PIPE} = 'IGNORE';
356 my $oldAutoCommit = $FS::UID::AutoCommit;
357 local $FS::UID::AutoCommit = 0;
361 unless ( $noexport_hack ) {
362 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
363 my $error = $part_export->export_suspend($self);
365 $dbh->rollback if $oldAutoCommit;
366 return "error exporting to ". $part_export->exporttype.
367 " (transaction rolled back): $error";
372 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
379 Runs export_unsuspend callbacks.
386 local $SIG{HUP} = 'IGNORE';
387 local $SIG{INT} = 'IGNORE';
388 local $SIG{QUIT} = 'IGNORE';
389 local $SIG{TERM} = 'IGNORE';
390 local $SIG{TSTP} = 'IGNORE';
391 local $SIG{PIPE} = 'IGNORE';
393 my $oldAutoCommit = $FS::UID::AutoCommit;
394 local $FS::UID::AutoCommit = 0;
398 unless ( $noexport_hack ) {
399 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
400 my $error = $part_export->export_unsuspend($self);
402 $dbh->rollback if $oldAutoCommit;
403 return "error exporting to ". $part_export->exporttype.
404 " (transaction rolled back): $error";
409 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
416 Stub - returns false (no error) so derived classes don't need to define these
417 methods. Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
423 =item clone_suspended
425 Constructor used by FS::part_export::_export_suspend fallback. Stub returning
426 same object for svc_ classes which don't implement a suspension fallback
427 (everything except svc_acct at the moment). Document better.
431 sub clone_suspended {
435 =item clone_kludge_unsuspend
437 Constructor used by FS::part_export::_export_unsuspend fallback. Stub returning
438 same object for svc_ classes which don't implement a suspension fallback
439 (everything except svc_acct at the moment). Document better.
443 sub clone_kludge_unsuspend {
451 $Id: svc_Common.pm,v 1.12.4.6 2004-03-03 13:44:27 ivan Exp $
455 The setfixed method return value.
459 L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, schema.html
460 from the base documentation.