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 [ OBJECTS_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.
42 If an arrayref of FS::tablename objects (for example, FS::acct_snarf objects)
43 is passed as the optional second parameter, they will have their svcnum fields
44 set and will be inserted after this record, but before any exports are run.
50 local $FS::queue::jobnums = shift if @_;
51 my $objects = scalar(@_) ? shift : [];
54 local $SIG{HUP} = 'IGNORE';
55 local $SIG{INT} = 'IGNORE';
56 local $SIG{QUIT} = 'IGNORE';
57 local $SIG{TERM} = 'IGNORE';
58 local $SIG{TSTP} = 'IGNORE';
59 local $SIG{PIPE} = 'IGNORE';
61 my $oldAutoCommit = $FS::UID::AutoCommit;
62 local $FS::UID::AutoCommit = 0;
65 $error = $self->check;
66 return $error if $error;
68 my $svcnum = $self->svcnum;
69 my $cust_svc = $svcnum ? qsearchs('cust_svc',{'svcnum'=>$self->svcnum}) : '';
71 if ( !$svcnum or !$cust_svc ) {
72 $cust_svc = new FS::cust_svc ( {
73 #hua?# 'svcnum' => $svcnum,
74 'svcnum' => $self->svcnum,
75 'pkgnum' => $self->pkgnum,
76 'svcpart' => $self->svcpart,
78 $error = $cust_svc->insert;
80 $dbh->rollback if $oldAutoCommit;
83 $svcnum = $self->svcnum($cust_svc->svcnum);
85 #$cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
86 unless ( $cust_svc ) {
87 $dbh->rollback if $oldAutoCommit;
88 return "no cust_svc record found for svcnum ". $self->svcnum;
90 $self->pkgnum($cust_svc->pkgnum);
91 $self->svcpart($cust_svc->svcpart);
94 $error = $self->SUPER::insert;
96 $dbh->rollback if $oldAutoCommit;
100 foreach my $object ( @$objects ) {
101 $object->svcnum($self->svcnum);
102 $error = $object->insert;
104 $dbh->rollback if $oldAutoCommit;
110 unless ( $noexport_hack ) {
111 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
112 my $error = $part_export->export_insert($self);
114 $dbh->rollback if $oldAutoCommit;
115 return "exporting to ". $part_export->exporttype.
116 " (transaction rolled back): $error";
121 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
128 Deletes this account from the database. If there is an error, returns the
129 error, otherwise returns false.
131 The corresponding FS::cust_svc record will be deleted as well.
139 local $SIG{HUP} = 'IGNORE';
140 local $SIG{INT} = 'IGNORE';
141 local $SIG{QUIT} = 'IGNORE';
142 local $SIG{TERM} = 'IGNORE';
143 local $SIG{TSTP} = 'IGNORE';
144 local $SIG{PIPE} = 'IGNORE';
146 my $svcnum = $self->svcnum;
148 my $oldAutoCommit = $FS::UID::AutoCommit;
149 local $FS::UID::AutoCommit = 0;
152 $error = $self->SUPER::delete;
153 return $error if $error;
156 unless ( $noexport_hack ) {
157 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
158 my $error = $part_export->export_delete($self);
160 $dbh->rollback if $oldAutoCommit;
161 return "exporting to ". $part_export->exporttype.
162 " (transaction rolled back): $error";
167 return $error if $error;
169 my $cust_svc = $self->cust_svc;
170 $error = $cust_svc->delete;
171 return $error if $error;
173 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
178 =item replace OLD_RECORD
180 Replaces OLD_RECORD with this one. If there is an error, returns the error,
181 otherwise returns false.
186 my ($new, $old) = (shift, shift);
188 local $SIG{HUP} = 'IGNORE';
189 local $SIG{INT} = 'IGNORE';
190 local $SIG{QUIT} = 'IGNORE';
191 local $SIG{TERM} = 'IGNORE';
192 local $SIG{TSTP} = 'IGNORE';
193 local $SIG{PIPE} = 'IGNORE';
195 my $oldAutoCommit = $FS::UID::AutoCommit;
196 local $FS::UID::AutoCommit = 0;
199 my $error = $new->SUPER::replace($old);
201 $dbh->rollback if $oldAutoCommit;
206 unless ( $noexport_hack ) {
207 foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
208 my $error = $part_export->export_replace($new,$old);
210 $dbh->rollback if $oldAutoCommit;
211 return "error exporting to ". $part_export->exporttype.
212 " (transaction rolled back): $error";
217 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
224 Sets any fixed fields for this service (see L<FS::part_svc>). If there is an
225 error, returns the error, otherwise returns the FS::part_svc object (use ref()
226 to test the return). Usually called by the check method.
237 Sets all fields to their defaults (see L<FS::part_svc>), overriding their
238 current values. If there is an error, returns the error, otherwise returns
239 the FS::part_svc object (use ref() to test the return).
255 $self->ut_numbern('svcnum')
257 return $error if $error;
261 if ( $self->svcnum && qsearchs('cust_svc', {'svcnum'=>$self->svcnum}) ) {
262 my $cust_svc = $self->cust_svc;
263 return "Unknown svcnum" unless $cust_svc;
264 $svcpart = $cust_svc->svcpart;
266 $svcpart = $self->getfield('svcpart');
268 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
269 return "Unkonwn svcpart" unless $part_svc;
271 #set default/fixed/whatever fields from part_svc
272 my $table = $self->table;
273 foreach my $field ( grep { $_ ne 'svcnum' } fields($table) ) {
274 my $part_svc_column = $part_svc->part_svc_column($field);
275 if ( $part_svc_column->columnflag eq $x ) {
276 $self->setfield( $field, $part_svc_column->columnvalue );
286 Returns the cust_svc record associated with this svc_ record, as a FS::cust_svc
287 object (see L<FS::cust_svc>).
293 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
298 Runs export_suspend callbacks.
305 local $SIG{HUP} = 'IGNORE';
306 local $SIG{INT} = 'IGNORE';
307 local $SIG{QUIT} = 'IGNORE';
308 local $SIG{TERM} = 'IGNORE';
309 local $SIG{TSTP} = 'IGNORE';
310 local $SIG{PIPE} = 'IGNORE';
312 my $oldAutoCommit = $FS::UID::AutoCommit;
313 local $FS::UID::AutoCommit = 0;
317 unless ( $noexport_hack ) {
318 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
319 my $error = $part_export->export_suspend($self);
321 $dbh->rollback if $oldAutoCommit;
322 return "error exporting to ". $part_export->exporttype.
323 " (transaction rolled back): $error";
328 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
335 Runs export_unsuspend callbacks.
342 local $SIG{HUP} = 'IGNORE';
343 local $SIG{INT} = 'IGNORE';
344 local $SIG{QUIT} = 'IGNORE';
345 local $SIG{TERM} = 'IGNORE';
346 local $SIG{TSTP} = 'IGNORE';
347 local $SIG{PIPE} = 'IGNORE';
349 my $oldAutoCommit = $FS::UID::AutoCommit;
350 local $FS::UID::AutoCommit = 0;
354 unless ( $noexport_hack ) {
355 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
356 my $error = $part_export->export_unsuspend($self);
358 $dbh->rollback if $oldAutoCommit;
359 return "error exporting to ". $part_export->exporttype.
360 " (transaction rolled back): $error";
365 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
372 Stub - returns false (no error) so derived classes don't need to define these
373 methods. Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
383 $Id: svc_Common.pm,v 1.12.4.4 2003-11-12 12:29:55 ivan Exp $
387 The setfixed method return value.
391 L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, schema.html
392 from the base documentation.