5 use FS::Record qw( 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 I<svcdb>__I<field> - Default or fixed value for I<field> in I<svcdb>.
45 =item I<svcdb>__I<field>_flag - defines I<svcdb>__I<field> action: null, `D' for default, or `F' for fixed
55 Creates a new service definition. To add the service definition to the
56 database, see L<"insert">.
60 sub table { 'part_svc'; }
64 Adds this service definition to the database. If there is an error, returns
65 the error, otherwise returns false.
66 =item I<svcdb>__I<field> - Default or fixed value for I<field> in I<svcdb>.
68 =item I<svcdb>__I<field>_flag - defines I<svcdb>__I<field> action: null, `D' for default, or `F' for fixed
75 local $SIG{HUP} = 'IGNORE';
76 local $SIG{INT} = 'IGNORE';
77 local $SIG{QUIT} = 'IGNORE';
78 local $SIG{TERM} = 'IGNORE';
79 local $SIG{TSTP} = 'IGNORE';
80 local $SIG{PIPE} = 'IGNORE';
82 my $oldAutoCommit = $FS::UID::AutoCommit;
83 local $FS::UID::AutoCommit = 0;
86 my $error = $self->SUPER::insert;
88 $dbh->rollback if $oldAutoCommit;
92 my $svcdb = $self->svcdb;
93 # my @rows = map { /^${svcdb}__(.*)$/; $1 }
99 && defined( $self->getfield($svcdb.'__'.$_.'_flag') )
102 my $part_svc_column = $self->part_svc_column($field);
103 my $previous = qsearchs('part_svc_column', {
104 'svcpart' => $self->svcpart,
105 'columnname' => $field,
108 my $flag = $self->getfield($svcdb.'__'.$field.'_flag');
109 if ( uc($flag) =~ /^([DF])$/ ) {
110 $part_svc_column->setfield('columnflag', $1);
111 $part_svc_column->setfield('columnvalue',
112 $self->getfield($svcdb.'__'.$field)
115 $error = $part_svc_column->replace($previous);
117 $error = $part_svc_column->insert;
120 $error = $part_svc_column->delete;
123 $dbh->rollback if $oldAutoCommit;
129 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
136 Currently unimplemented.
141 return "Can't (yet?) delete service definitions.";
142 # check & make sure the svcpart isn't in cust_svc or pkg_svc (in any packages)?
145 =item replace OLD_RECORD
147 Replaces OLD_RECORD with this one in the database. If there is an error,
148 returns the error, otherwise returns false.
153 my ( $new, $old ) = ( shift, shift );
155 return "Can't change svcdb for an existing service definition!"
156 unless $old->svcdb eq $new->svcdb;
158 $new->SUPER::replace( $old );
163 Checks all fields to make sure this is a valid service definition. If there is
164 an error, returns the error, otherwise returns false. Called by the insert
171 my $recref = $self->hashref;
175 $self->ut_numbern('svcpart')
176 || $self->ut_text('svc')
177 || $self->ut_alpha('svcdb')
179 return $error if $error;
181 my @fields = eval { fields( $recref->{svcdb} ) }; #might die
182 return "Unknown svcdb!" unless @fields;
185 # foreach $svcdb ( qw(
186 # svc_acct svc_acct_sm svc_domain
188 # my @rows = map { /^${svcdb}__(.*)$/; $1 }
190 # grep /^${svcdb}__/,
191 # fields('part_svc');
192 # foreach my $row (@rows) {
193 # unless ( $svcdb eq $recref->{svcdb} ) {
194 # $recref->{$svcdb.'__'.$row}='';
195 # $recref->{$svcdb.'__'.$row.'_flag'}='';
198 # $recref->{$svcdb.'__'.$row.'_flag'} =~ /^([DF]?)$/
199 # or return "Illegal flag for $svcdb $row";
200 # $recref->{$svcdb.'__'.$row.'_flag'} = $1;
202 # my $error = $self->ut_anything($svcdb.'__'.$row);
203 # return $error if $error;
211 =item part_svc_column COLUMNNAME
213 Returns the part_svc_column object (see L<FS::part_svc_column>) for the given
214 COLUMNNAME, or a new part_svc_column object if none exists.
218 sub part_svc_column {
220 my $columnname = shift;
221 qsearchs('part_svc_column', {
222 'svcpart' => $self->svcpart,
223 'columnname' => $columnname,
225 ) or new FS::part_svc_column {
226 'svcpart' => $self->svcpart,
227 'columnname' => $columnname,
235 $Id: part_svc.pm,v 1.3 2001-09-06 20:41:59 ivan Exp $
239 Delete is unimplemented.
241 The list of svc_* tables is hardcoded. When svc_acct_pop is renamed, this
246 L<FS::Record>, L<FS::part_pkg>, L<FS::pkg_svc>, L<FS::cust_svc>,
247 L<FS::svc_acct>, L<FS::svc_forward>, L<FS::svc_domain>, schema.html from the