5 use FS::Record qw( qsearch qsearchs fields dbh );
6 use FS::part_svc_column;
12 FS::part_svc - Object methods for part_svc objects
18 $record = new FS::part_svc \%hash
19 $record = new FS::part_svc { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::part_svc represents a service definition. FS::part_svc inherits from
32 FS::Record. The following fields are currently supported:
36 =item svcpart - primary key (assigned automatically for new service definitions)
38 =item svc - text name of this service definition
40 =item svcdb - table used for this service. See L<FS::svc_acct>,
41 L<FS::svc_domain>, and L<FS::svc_forward>, among others.
43 =item disabled - Disabled flag, empty or `Y'
53 Creates a new service definition. To add the service definition to the
54 database, see L<"insert">.
58 sub table { 'part_svc'; }
62 Adds this service definition to the database. If there is an error, returns
63 the error, otherwise returns false.
65 =item I<svcdb>__I<field> - Default or fixed value for I<field> in I<svcdb>.
67 =item I<svcdb>__I<field>_flag - defines I<svcdb>__I<field> action: null, `D' for default, or `F' for fixed
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 my $error = $self->SUPER::insert;
87 $dbh->rollback if $oldAutoCommit;
91 my $svcdb = $self->svcdb;
92 # my @rows = map { /^${svcdb}__(.*)$/; $1 }
98 && defined( $self->getfield($svcdb.'__'.$_.'_flag') )
101 my $part_svc_column = $self->part_svc_column($field);
102 my $previous = qsearchs('part_svc_column', {
103 'svcpart' => $self->svcpart,
104 'columnname' => $field,
107 my $flag = $self->getfield($svcdb.'__'.$field.'_flag');
108 if ( uc($flag) =~ /^([DF])$/ ) {
109 $part_svc_column->setfield('columnflag', $1);
110 $part_svc_column->setfield('columnvalue',
111 $self->getfield($svcdb.'__'.$field)
114 $error = $part_svc_column->replace($previous);
116 $error = $part_svc_column->insert;
119 $error = $previous ? $previous->delete : '';
122 $dbh->rollback if $oldAutoCommit;
128 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
135 Currently unimplemented.
140 return "Can't (yet?) delete service definitions.";
141 # check & make sure the svcpart isn't in cust_svc or pkg_svc (in any packages)?
144 =item replace OLD_RECORD
146 Replaces OLD_RECORD with this one in the database. If there is an error,
147 returns the error, otherwise returns false.
152 my ( $new, $old ) = ( shift, shift );
154 return "Can't change svcdb for an existing service definition!"
155 unless $old->svcdb eq $new->svcdb;
157 local $SIG{HUP} = 'IGNORE';
158 local $SIG{INT} = 'IGNORE';
159 local $SIG{QUIT} = 'IGNORE';
160 local $SIG{TERM} = 'IGNORE';
161 local $SIG{TSTP} = 'IGNORE';
162 local $SIG{PIPE} = 'IGNORE';
164 my $oldAutoCommit = $FS::UID::AutoCommit;
165 local $FS::UID::AutoCommit = 0;
168 my $error = $new->SUPER::replace( $old );
170 $dbh->rollback if $oldAutoCommit;
174 if ( @_ && $_[0] eq '1.3-COMPAT' ) {
175 my $svcdb = $new->svcdb;
177 grep { $_ ne 'svcnum'
178 && defined( $new->getfield($svcdb.'__'.$_.'_flag') )
181 my $part_svc_column = $new->part_svc_column($field);
182 my $previous = qsearchs('part_svc_column', {
183 'svcpart' => $new->svcpart,
184 'columnname' => $field,
187 my $flag = $new->getfield($svcdb.'__'.$field.'_flag');
188 if ( uc($flag) =~ /^([DF])$/ ) {
189 $part_svc_column->setfield('columnflag', $1);
190 $part_svc_column->setfield('columnvalue',
191 $new->getfield($svcdb.'__'.$field)
194 $error = $part_svc_column->replace($previous);
196 $error = $part_svc_column->insert;
199 $error = $previous ? $previous->delete : '';
202 $dbh->rollback if $oldAutoCommit;
207 $dbh->rollback if $oldAutoCommit;
208 return 'non-1.3-COMPAT interface not yet written';
212 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
219 Checks all fields to make sure this is a valid service definition. If there is
220 an error, returns the error, otherwise returns false. Called by the insert
227 my $recref = $self->hashref;
231 $self->ut_numbern('svcpart')
232 || $self->ut_text('svc')
233 || $self->ut_alpha('svcdb')
234 || $self->ut_enum('disabled', [ '', 'Y' ] )
236 return $error if $error;
238 my @fields = eval { fields( $recref->{svcdb} ) }; #might die
239 return "Unknown svcdb!" unless @fields;
241 ##REPLACED BY part_svc_column
243 # foreach $svcdb ( qw(
244 # svc_acct svc_acct_sm svc_domain
246 # my @rows = map { /^${svcdb}__(.*)$/; $1 }
248 # grep /^${svcdb}__/,
249 # fields('part_svc');
250 # foreach my $row (@rows) {
251 # unless ( $svcdb eq $recref->{svcdb} ) {
252 # $recref->{$svcdb.'__'.$row}='';
253 # $recref->{$svcdb.'__'.$row.'_flag'}='';
256 # $recref->{$svcdb.'__'.$row.'_flag'} =~ /^([DF]?)$/
257 # or return "Illegal flag for $svcdb $row";
258 # $recref->{$svcdb.'__'.$row.'_flag'} = $1;
260 # my $error = $self->ut_anything($svcdb.'__'.$row);
261 # return $error if $error;
269 =item part_svc_column COLUMNNAME
271 Returns the part_svc_column object (see L<FS::part_svc_column>) for the given
272 COLUMNNAME, or a new part_svc_column object if none exists.
276 sub part_svc_column {
278 my $columnname = shift;
279 qsearchs('part_svc_column', {
280 'svcpart' => $self->svcpart,
281 'columnname' => $columnname,
283 ) or new FS::part_svc_column {
284 'svcpart' => $self->svcpart,
285 'columnname' => $columnname,
289 =item all_part_svc_column
293 sub all_part_svc_column {
295 qsearch('part_svc_column', { 'svcpart' => $self->svcpart } );
302 $Id: part_svc.pm,v 1.9 2002-01-28 06:57:23 ivan Exp $
306 Delete is unimplemented.
308 The list of svc_* tables is hardcoded. When svc_acct_pop is renamed, this
313 L<FS::Record>, L<FS::part_svc_column>, L<FS::part_pkg>, L<FS::pkg_svc>,
314 L<FS::cust_svc>, L<FS::svc_acct>, L<FS::svc_forward>, L<FS::svc_domain>,
315 schema.html from the base documentation.