1 package FS::svc_Common;
4 use vars qw( @ISA $noexport_hack );
5 use FS::Record qw( qsearchs fields dbh );
9 @ISA = qw( FS::Record );
13 FS::svc_Common - Object method for all svc_ records
19 @ISA = qw( FS::svc_Common );
23 FS::svc_Common is intended as a base class for table-specific classes to
24 inherit from, i.e. FS::svc_acct. FS::svc_Common inherits from FS::Record.
32 Adds this record to the database. If there is an error, returns the error,
33 otherwise returns false.
35 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
36 defined. An FS::cust_svc record will be created and inserted.
44 local $SIG{HUP} = 'IGNORE';
45 local $SIG{INT} = 'IGNORE';
46 local $SIG{QUIT} = 'IGNORE';
47 local $SIG{TERM} = 'IGNORE';
48 local $SIG{TSTP} = 'IGNORE';
49 local $SIG{PIPE} = 'IGNORE';
51 my $oldAutoCommit = $FS::UID::AutoCommit;
52 local $FS::UID::AutoCommit = 0;
55 $error = $self->check;
56 return $error if $error;
58 my $svcnum = $self->svcnum;
61 $cust_svc = new FS::cust_svc ( {
62 #hua?# 'svcnum' => $svcnum,
63 'pkgnum' => $self->pkgnum,
64 'svcpart' => $self->svcpart,
66 $error = $cust_svc->insert;
68 $dbh->rollback if $oldAutoCommit;
71 $svcnum = $self->svcnum($cust_svc->svcnum);
73 $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
74 unless ( $cust_svc ) {
75 $dbh->rollback if $oldAutoCommit;
76 return "no cust_svc record found for svcnum ". $self->svcnum;
78 $self->pkgnum($cust_svc->pkgnum);
79 $self->svcpart($cust_svc->svcpart);
82 $error = $self->SUPER::insert;
84 $dbh->rollback if $oldAutoCommit;
89 unless ( $noexport_hack ) {
90 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
91 my $error = $part_export->export_insert($self);
93 $dbh->rollback if $oldAutoCommit;
94 return "exporting to ". $part_export->exporttype.
95 " (transaction rolled back): $error";
100 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
107 Deletes this account from the database. If there is an error, returns the
108 error, otherwise returns false.
110 The corresponding FS::cust_svc record will be deleted as well.
118 local $SIG{HUP} = 'IGNORE';
119 local $SIG{INT} = 'IGNORE';
120 local $SIG{QUIT} = 'IGNORE';
121 local $SIG{TERM} = 'IGNORE';
122 local $SIG{TSTP} = 'IGNORE';
123 local $SIG{PIPE} = 'IGNORE';
125 my $svcnum = $self->svcnum;
127 my $oldAutoCommit = $FS::UID::AutoCommit;
128 local $FS::UID::AutoCommit = 0;
131 $error = $self->SUPER::delete;
132 return $error if $error;
135 unless ( $noexport_hack ) {
136 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
137 my $error = $part_export->export_delete($self);
139 $dbh->rollback if $oldAutoCommit;
140 return "exporting to ". $part_export->exporttype.
141 " (transaction rolled back): $error";
146 return $error if $error;
148 my $cust_svc = $self->cust_svc;
149 $error = $cust_svc->delete;
150 return $error if $error;
152 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
157 =item replace OLD_RECORD
159 Replaces OLD_RECORD with this one. If there is an error, returns the error,
160 otherwise returns false.
165 my ($new, $old) = (shift, shift);
167 local $SIG{HUP} = 'IGNORE';
168 local $SIG{INT} = 'IGNORE';
169 local $SIG{QUIT} = 'IGNORE';
170 local $SIG{TERM} = 'IGNORE';
171 local $SIG{TSTP} = 'IGNORE';
172 local $SIG{PIPE} = 'IGNORE';
174 my $oldAutoCommit = $FS::UID::AutoCommit;
175 local $FS::UID::AutoCommit = 0;
178 my $error = $new->SUPER::replace($old);
180 $dbh->rollback if $oldAutoCommit;
185 unless ( $noexport_hack ) {
186 foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
187 my $error = $part_export->export_replace($new,$old);
189 $dbh->rollback if $oldAutoCommit;
190 return "error exporting to ". $part_export->exporttype.
191 " (transaction rolled back): $error";
196 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
203 Sets any fixed fields for this service (see L<FS::part_svc>). If there is an
204 error, returns the error, otherwise returns the FS::part_svc object (use ref()
205 to test the return). Usually called by the check method.
216 Sets all fields to their defaults (see L<FS::part_svc>), overriding their
217 current values. If there is an error, returns the error, otherwise returns
218 the FS::part_svc object (use ref() to test the return).
234 $self->ut_numbern('svcnum')
236 return $error if $error;
240 if ( $self->svcnum ) {
241 my $cust_svc = $self->cust_svc;
242 return "Unknown svcnum" unless $cust_svc;
243 $svcpart = $cust_svc->svcpart;
245 $svcpart = $self->getfield('svcpart');
247 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
248 return "Unkonwn svcpart" unless $part_svc;
250 #set default/fixed/whatever fields from part_svc
251 my $table = $self->table;
252 foreach my $field ( grep { $_ ne 'svcnum' } fields($table) ) {
253 my $part_svc_column = $part_svc->part_svc_column($field);
254 if ( $part_svc_column->columnflag eq $x ) {
255 $self->setfield( $field, $part_svc_column->columnvalue );
265 Returns the cust_svc record associated with this svc_ record, as a FS::cust_svc
266 object (see L<FS::cust_svc>).
272 qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
277 Runs export_suspend callbacks.
284 local $SIG{HUP} = 'IGNORE';
285 local $SIG{INT} = 'IGNORE';
286 local $SIG{QUIT} = 'IGNORE';
287 local $SIG{TERM} = 'IGNORE';
288 local $SIG{TSTP} = 'IGNORE';
289 local $SIG{PIPE} = 'IGNORE';
291 my $oldAutoCommit = $FS::UID::AutoCommit;
292 local $FS::UID::AutoCommit = 0;
296 unless ( $noexport_hack ) {
297 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
298 my $error = $part_export->export_suspend($self);
300 $dbh->rollback if $oldAutoCommit;
301 return "error exporting to ". $part_export->exporttype.
302 " (transaction rolled back): $error";
307 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
314 Runs export_unsuspend callbacks.
321 local $SIG{HUP} = 'IGNORE';
322 local $SIG{INT} = 'IGNORE';
323 local $SIG{QUIT} = 'IGNORE';
324 local $SIG{TERM} = 'IGNORE';
325 local $SIG{TSTP} = 'IGNORE';
326 local $SIG{PIPE} = 'IGNORE';
328 my $oldAutoCommit = $FS::UID::AutoCommit;
329 local $FS::UID::AutoCommit = 0;
333 unless ( $noexport_hack ) {
334 foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
335 my $error = $part_export->export_unsuspend($self);
337 $dbh->rollback if $oldAutoCommit;
338 return "error exporting to ". $part_export->exporttype.
339 " (transaction rolled back): $error";
344 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
351 Stub - returns false (no error) so derived classes don't need to define these
352 methods. Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
362 $Id: svc_Common.pm,v 1.11 2002-06-11 03:25:03 ivan Exp $
366 The setfixed method return value.
370 L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, schema.html
371 from the base documentation.