3 use base qw(FS::o2m_Common FS::Record);
5 use vars qw( @ISA $DEBUG );
7 use FS::Record qw( qsearch qsearchs fields dbh );
8 use FS::Schema qw( dbdef );
9 use FS::part_svc_column;
13 use FS::part_svc_class;
14 use FS::part_svc_msgcat;
20 FS::part_svc - Object methods for part_svc objects
26 $record = new FS::part_svc \%hash
27 $record = new FS::part_svc { 'column' => 'value' };
29 $error = $record->insert;
30 $error = $record->insert( [ 'pseudofield' ] );
31 $error = $record->insert( [ 'pseudofield' ], \%exportnums );
33 $error = $new_record->replace($old_record);
34 $error = $new_record->replace($old_record, '1.3-COMPAT', [ 'pseudofield' ] );
35 $error = $new_record->replace($old_record, '1.3-COMPAT', [ 'pseudofield' ], \%exportnums );
37 $error = $record->delete;
39 $error = $record->check;
43 An FS::part_svc represents a service definition. FS::part_svc inherits from
44 FS::Record. The following fields are currently supported:
48 =item svcpart - primary key (assigned automatically for new service definitions)
50 =item svc - text name of this service definition
52 =item svcdb - table used for this service. See L<FS::svc_acct>,
53 L<FS::svc_domain>, and L<FS::svc_forward>, among others.
55 =item classnum - Optional service class (see L<FS::svc_class>)
57 =item disabled - Disabled flag, empty or `Y'
59 =item preserve - Preserve after cancellation, empty or 'Y'
61 =item selfservice_access - Access allowed to the service via self-service:
62 empty for full access, "readonly" for read-only, "hidden" to hide it entirely
64 =item restrict_edit_password - Require the "Provision customer service" access
65 right to change the password field, rather than just "Edit password". Only
66 relevant to svc_acct for now.
68 =item has_router - Allow the service to have an L<FS::router> connected
69 through it. Probably only relevant to svc_broadband, svc_acct, and svc_dsl
80 Creates a new service definition. To add the service definition to the
81 database, see L<"insert">.
85 sub table { 'part_svc'; }
87 =item insert [ EXTRA_FIELDS_ARRAYREF [ , EXPORTNUMS_HASHREF [ , JOB ] ] ]
89 Adds this service definition to the database. If there is an error, returns
90 the error, otherwise returns false.
92 The following pseudo-fields may be defined, and will be maintained in
93 the part_svc_column table appropriately (see L<FS::part_svc_column>).
97 =item I<svcdb>__I<field> - Default or fixed value for I<field> in I<svcdb>.
99 =item I<svcdb>__I<field>_label
101 =item I<svcdb>__I<field>_flag - defines I<svcdb>__I<field> action: null or empty (no default), `D' for default, `F' for fixed (unchangeable), , `S' for selectable choice, `M' for manual selection from inventory, or `A' for automatic selection from inventory. For virtual fields, can also be 'X' for excluded.
103 =item I<svcdb>__I<field>_required - I<field> should always have a true value
107 If you want to add part_svc_column records for fields that do not exist as
108 fields in the I<svcdb> table, make sure to list then in
109 EXTRA_FIELDS_ARRAYREF also.
111 If EXPORTNUMS_HASHREF is specified (keys are exportnums and values are
112 boolean), the appopriate export_svc records will be inserted.
121 @fields = @{shift(@_)} if @_;
122 my $exportnums = shift || {};
126 local $SIG{HUP} = 'IGNORE';
127 local $SIG{INT} = 'IGNORE';
128 local $SIG{QUIT} = 'IGNORE';
129 local $SIG{TERM} = 'IGNORE';
130 local $SIG{TSTP} = 'IGNORE';
131 local $SIG{PIPE} = 'IGNORE';
133 my $oldAutoCommit = $FS::UID::AutoCommit;
134 local $FS::UID::AutoCommit = 0;
137 my $error = $self->SUPER::insert;
139 $dbh->rollback if $oldAutoCommit;
143 # add part_svc_column records
145 my $svcdb = $self->svcdb;
146 foreach my $field (fields($svcdb), @fields) {
147 next if $field eq 'svcnum';
148 my $prefix = $svcdb.'__';
149 if ( defined( $self->getfield($prefix.$field.'_flag'))
150 or defined($self->getfield($prefix.$field.'_required'))
151 or length($self->getfield($prefix.$field.'_label'))
153 my $part_svc_column = $self->part_svc_column($field);
154 my $previous = qsearchs('part_svc_column', {
155 'svcpart' => $self->svcpart,
156 'columnname' => $field,
159 my $flag = $self->getfield($prefix.$field.'_flag');
160 my $label = $self->getfield($prefix.$field.'_label');
161 my $required = $self->getfield($prefix.$field.'_required') ? 'Y' : '';
162 if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) {
164 if ( uc($flag) =~ /^([A-Z])$/ ) {
165 my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
167 $part_svc_column->setfield('columnflag', $1);
168 $part_svc_column->setfield('columnvalue',
169 &$parser($self->getfield($prefix.$field))
173 $part_svc_column->setfield('columnlabel', $label)
174 if $label !~ /^\s*$/;
176 $part_svc_column->setfield('required', $required);
179 $error = $part_svc_column->replace($previous);
181 $error = $part_svc_column->insert;
185 $error = $previous ? $previous->delete : '';
188 $dbh->rollback if $oldAutoCommit;
195 # add export_svc records
196 my @exportnums = grep $exportnums->{$_}, keys %$exportnums;
197 my $slice = 100/scalar(@exportnums) if @exportnums;
199 foreach my $exportnum ( @exportnums ) {
200 my $export_svc = new FS::export_svc ( {
201 'exportnum' => $exportnum,
202 'svcpart' => $self->svcpart,
203 'role' => $exportnums->{$exportnum},
205 $error = $export_svc->insert($job, $slice*$done++, $slice);
207 $dbh->rollback if $oldAutoCommit;
212 # XXX shouldn't this update fixed values?
214 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
221 Currently unimplemented. Set the "disabled" field instead.
226 return "Can't (yet?) delete service definitions.";
227 # check & make sure the svcpart isn't in cust_svc or pkg_svc (in any packages)?
230 =item replace OLD_RECORD [ '1.3-COMPAT' [ , EXTRA_FIELDS_ARRAYREF [ , EXPORTNUMS_HASHREF [ , JOB ] ] ] ]
232 Replaces OLD_RECORD with this one in the database. If there is an error,
233 returns the error, otherwise returns false.
237 TODOC: EXTRA_FIELDS_ARRAYREF (same as insert method)
244 my ( $new, $old ) = ( shift, shift );
249 if ( @_ && $_[0] eq '1.3-COMPAT' ) {
252 @fields = @{shift(@_)} if @_;
253 $exportnums = @_ ? shift : '';
256 return 'non-1.3-COMPAT interface not yet written';
260 return "Can't change svcdb for an existing service definition!"
261 unless $old->svcdb eq $new->svcdb;
263 local $SIG{HUP} = 'IGNORE';
264 local $SIG{INT} = 'IGNORE';
265 local $SIG{QUIT} = 'IGNORE';
266 local $SIG{TERM} = 'IGNORE';
267 local $SIG{TSTP} = 'IGNORE';
268 local $SIG{PIPE} = 'IGNORE';
270 my $oldAutoCommit = $FS::UID::AutoCommit;
271 local $FS::UID::AutoCommit = 0;
274 my $error = $new->SUPER::replace( $old );
276 $dbh->rollback if $oldAutoCommit;
280 if ( $compat eq '1.3' ) {
282 # maintain part_svc_column records
284 my $svcdb = $new->svcdb;
285 foreach my $field (fields($svcdb),@fields) {
286 next if $field eq 'svcnum';
287 my $prefix = $svcdb.'__';
288 if ( defined( $new->getfield($prefix.$field.'_flag'))
289 or defined($new->getfield($prefix.$field.'_required'))
290 or length($new->getfield($prefix.$field.'_label'))
292 my $part_svc_column = $new->part_svc_column($field);
293 my $previous = qsearchs('part_svc_column', {
294 'svcpart' => $new->svcpart,
295 'columnname' => $field,
298 my $flag = $new->getfield($svcdb.'__'.$field.'_flag');
299 my $label = $new->getfield($svcdb.'__'.$field.'_label');
300 my $required = $new->getfield($svcdb.'__'.$field.'_required') ? 'Y' : '';
302 if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) {
304 if ( uc($flag) =~ /^([A-Z])$/ ) {
305 $part_svc_column->setfield('columnflag', $1);
306 my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
308 $part_svc_column->setfield('columnvalue',
309 &$parser($new->getfield($svcdb.'__'.$field))
312 $part_svc_column->setfield('columnflag', '');
313 $part_svc_column->setfield('columnvalue', '');
316 $part_svc_column->setfield('columnlabel', $label)
317 if $label !~ /^\s*$/;
319 $part_svc_column->setfield('required', $required);
322 $error = $part_svc_column->replace($previous);
324 $error = $part_svc_column->insert;
327 $error = $previous ? $previous->delete : '';
330 $dbh->rollback if $oldAutoCommit;
336 # maintain export_svc records
338 if ( $exportnums ) { # hash of exportnum => role
340 #false laziness w/ edit/process/agent_type.cgi
341 #and, more importantly, with m2m_Common
342 my @new_export_svc = ();
343 foreach my $part_export ( qsearch('part_export', {}) ) {
344 my $exportnum = $part_export->exportnum;
346 'exportnum' => $exportnum,
347 'svcpart' => $new->svcpart,
349 my $export_svc = qsearchs('export_svc', $hashref);
352 my $old_role = $export_svc->role || 1; # 1 = null in the db
353 if ( ! $exportnums->{$exportnum}
354 or $old_role ne $exportnums->{$exportnum} ) {
356 $error = $export_svc->delete;
358 $dbh->rollback if $oldAutoCommit;
361 undef $export_svc; # on a role change, force it to be reinserted
365 if ( ! $export_svc && $exportnums->{$exportnum} ) {
366 # also applies if it's been undef'd because of role change
367 $hashref->{role} = $exportnums->{$exportnum};
368 push @new_export_svc, new FS::export_svc ( $hashref );
373 my $slice = 100/scalar(@new_export_svc) if @new_export_svc;
375 foreach my $export_svc (@new_export_svc) {
376 $error = $export_svc->insert($job, $slice*$done++, $slice);
378 $dbh->rollback if $oldAutoCommit;
382 $error = $job->update_statustext( int( $slice * $done ) );
384 $dbh->rollback if $oldAutoCommit;
393 $dbh->rollback if $oldAutoCommit;
394 return 'non-1.3-COMPAT interface not yet written';
398 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
405 Checks all fields to make sure this is a valid service definition. If there is
406 an error, returns the error, otherwise returns false. Called by the insert
416 $self->ut_numbern('svcpart')
417 || $self->ut_text('svc')
418 || $self->ut_alpha('svcdb')
419 || $self->ut_flag('disabled')
420 || $self->ut_flag('preserve')
421 || $self->ut_enum('selfservice_access', [ '', 'hidden', 'readonly' ] )
422 || $self->ut_foreign_keyn('classnum', 'part_svc_class', 'classnum' )
423 || $self->ut_flag('restrict_edit_password')
424 || $self->ut_flag('has_router')
426 return $error if $error;
428 my @fields = eval { fields( $self->svcdb ) }; #might die
429 return "Unknown svcdb: ". $self->svcdb. " (Error: $@)"
435 =item part_svc_column COLUMNNAME
437 Returns the part_svc_column object (see L<FS::part_svc_column>) for the given
438 COLUMNNAME, or a new part_svc_column object if none exists.
442 sub part_svc_column {
443 my( $self, $columnname) = @_;
445 qsearchs('part_svc_column', {
446 'svcpart' => $self->svcpart,
447 'columnname' => $columnname,
449 ) or new FS::part_svc_column {
450 'svcpart' => $self->svcpart,
451 'columnname' => $columnname,
455 =item all_part_svc_column
459 sub all_part_svc_column {
461 qsearch('part_svc_column', { 'svcpart' => $self->svcpart } );
464 =item part_export [ EXPORTTYPE ]
466 Returns a list of all exports (see L<FS::part_export>) for this service, or,
467 if an export type is specified, only returns exports of the given type.
474 $search{'exporttype'} = shift if @_;
475 map { $_ } #behavior of sort undefined in scalar context
476 sort { $a->weight <=> $b->weight }
477 map { qsearchs('part_export', { 'exportnum'=>$_->exportnum, %search } ) }
478 qsearch('export_svc', { 'svcpart'=>$self->svcpart } );
481 =item part_export_usage
483 Returns a list of any exports (see L<FS::part_export>) for this service that
484 are capable of reporting usage information.
488 sub part_export_usage {
490 grep $_->can('usage_sessions'), $self->part_export;
493 =item part_export_did
495 Returns a list of any exports (see L<FS::part_export>) for this service that
496 are capable of returing available DID (phone number) information.
500 sub part_export_did {
502 grep $_->can('get_dids'), $self->part_export;
505 =item part_export_dsl_pull
507 Returns a list of any exports (see L<FS::part_export>) for this service that
508 are capable of pulling/pushing DSL orders.
512 sub part_export_dsl_pull {
514 grep $_->can('dsl_pull'), $self->part_export;
517 =item part_export_partsvc
519 Returns a list of any exports (see L<FS::part_export>) for this service that
520 are capable of pushing a change after part svc is changed.
524 sub part_export_partsvc {
526 grep $_->can('export_partsvc'), $self->part_export;
529 =item cust_svc [ PKGPART ]
531 Returns a list of associated customer services (FS::cust_svc records).
533 If a PKGPART is specified, returns the customer services which are contained
534 within packages of that type (see L<FS::part_pkg>). If PKGPARTis specified as
535 B<0>, returns unlinked customer services.
542 my $hashref = { 'svcpart' => $self->svcpart };
544 my( $addl_from, $extra_sql ) = ( '', '' );
547 if ( $pkgpart =~ /^(\d+)$/ ) {
548 $addl_from = 'LEFT JOIN cust_pkg USING ( pkgnum )';
549 $extra_sql = "AND pkgpart = $1";
550 } elsif ( $pkgpart eq '0' ) {
551 $hashref->{'pkgnum'} = '';
556 'table' => 'cust_svc',
557 'addl_from' => $addl_from,
558 'hashref' => $hashref,
559 'extra_sql' => $extra_sql,
563 =item num_cust_svc [ PKGPART ]
565 Returns the number of associated customer services (FS::cust_svc records).
567 If a PKGPART is specified, returns the number of customer services which are
568 contained within packages of that type (see L<FS::part_pkg>). If PKGPART
569 is specified as B<0>, returns the number of unlinked customer services.
576 return $self->{Hash}{num_cust_svc}
577 if !@_ && exists($self->{Hash}{num_cust_svc});
579 my @param = ( $self->svcpart );
581 my( $join, $and ) = ( '', '' );
585 $join = 'LEFT JOIN cust_pkg USING ( pkgnum )';
586 $and = 'AND pkgpart = ?';
587 push @param, $pkgpart;
588 } elsif ( $pkgpart eq '0' ) {
589 $and = 'AND pkgnum IS NULL';
593 my $sth = dbh->prepare(
594 "SELECT COUNT(*) FROM cust_svc $join WHERE svcpart = ? $and"
595 ) or die dbh->errstr;
596 $sth->execute(@param)
598 $sth->fetchrow_arrayref->[0];
601 =item num_cust_svc_cancelled
603 Returns the number of associated customer services that are
604 attached to cancelled packages.
608 sub num_cust_svc_cancelled {
610 my $sth = dbh->prepare(
611 "SELECT COUNT(*) FROM cust_svc
612 LEFT JOIN cust_pkg USING ( pkgnum )
614 AND cust_pkg.cancel IS NOT NULL"
615 ) or die dbh->errstr;
616 $sth->execute($self->svcpart)
618 $sth->fetchrow_arrayref->[0];
623 Returns a list of associated FS::svc_* records.
629 map { $_->svc_x } $self->cust_svc;
632 =item svc_locale LOCALE
634 Returns a customer-viewable service definition label in the chosen LOCALE.
635 If there is no entry for that locale or if LOCALE is empty, returns
641 my( $self, $locale ) = @_;
642 return $self->svc unless $locale;
643 my $part_svc_msgcat = qsearchs('part_svc_msgcat', {
644 svcpart => $self->svcpart,
646 }) or return $self->svc;
647 $part_svc_msgcat->svc;
651 sub part_svc_msgcat {
653 qsearch('part_svc_msgcat', { 'svcpart' => $self->svcpart });
668 return $svc_defs if $svc_defs; #cache
670 my $conf = new FS::Conf;
672 #false laziness w/part_pkg.pm::plan_info
675 foreach my $INC ( @INC ) {
676 warn "globbing $INC/FS/svc_*.pm\n" if $DEBUG;
677 foreach my $file ( glob("$INC/FS/svc_*.pm") ) {
679 warn "attempting to load service table info from $file\n" if $DEBUG;
680 $file =~ /\/(\w+)\.pm$/ or do {
681 warn "unrecognized file in $INC/FS/: $file\n";
686 if ( $mod =~ /^svc_[A-Z]/ or $mod =~ /^(svc_acct_pop|svc_export_machine)$/ ) {
687 warn "skipping FS::$mod" if $DEBUG;
691 eval "use FS::$mod;";
693 die "error using FS::$mod (skipping): $@\n" if $@;
696 unless ( UNIVERSAL::can("FS::$mod", 'table_info') ) {
697 warn "FS::$mod has no table_info method; skipping";
701 my $info = "FS::$mod"->table_info;
702 unless ( keys %$info ) {
703 warn "FS::$mod->table_info doesn't return info, skipping\n";
706 warn "got info from FS::$mod: $info\n" if $DEBUG;
707 if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
708 warn "skipping disabled service FS::$mod" if $DEBUG;
715 tie my %svc_defs, 'Tie::IxHash',
716 map { $_ => $info{$_}->{'fields'} }
717 sort { $info{$a}->{'display_weight'} <=> $info{$b}->{'display_weight'} }
721 tie my %svc_info, 'Tie::IxHash',
722 map { $_ => $info{$_} }
723 sort { $info{$a}->{'display_weight'} <=> $info{$b}->{'display_weight'} }
727 $svc_info = \%svc_info; #access via svc_table_info
728 $svc_defs = \%svc_defs; #cache
734 Returns a list of all svc_ tables.
740 my $svc_defs = $class->_svc_defs;
741 grep { defined( dbdef->table($_) ) } keys %$svc_defs;
744 =item svc_table_fields TABLE
746 Given a table name, returns a hashref of field names. The field names
747 returned are those with additional (service-definition related) information,
748 not necessarily all database fields of the table. Pseudo-fields may also
749 be returned (i.e. svc_acct.usergroup).
751 Each value of the hashref is another hashref, which can have one or more of
756 =item label - Description of the field
758 =item def_label - Optional description of the field in the context of service definitions
760 =item type - Currently "text", "select", "checkbox", "textarea", "disabled",
761 some components specified by "select-.*.html", and a bunch more...
763 =item disable_default - This field should not allow a default value in service definitions
765 =item disable_fixed - This field should not allow a fixed value in service definitions
767 =item disable_inventory - This field should not allow inventory values in service definitions
769 =item select_list - If type is "text", this can be a listref of possible values.
771 =item select_table - An alternative to select_list, this defines a database table with the possible choices.
773 =item select_key - Used with select_table, this is the field name of keys
775 =item select_label - Used with select_table, this is the field name of labels
777 =item select_allow_empty - Used with select_table, adds an empty option
779 =item required - This field should always have a true value (do not use with type checkbox or disabled)
785 #maybe this should move and be a class method in svc_Common.pm
786 sub svc_table_fields {
787 my($class, $table) = @_;
788 my $svc_defs = $class->_svc_defs;
789 my $def = $svc_defs->{$table};
791 foreach ( grep !ref($def->{$_}), keys %$def ) {
793 #normalize the shortcut in %info hash
794 $def->{$_} = { 'label' => $def->{$_} };
796 $def->{$_}{'type'} ||= 'text';
803 =item svc_table_info TABLE
805 Returns table_info for TABLE from cache, or empty
806 hashref if none is found.
808 Caution: caches table_info for ALL services when run;
809 access a service's table_info directly unless you know
810 you're loading them all.
812 Caution: does not standardize fields into hashrefs;
813 use L</svc_table_fields> to access fields.
820 $class->_svc_defs; #creates cache if needed
821 return $svc_info->{$table} || {};
832 Job-queue processor for web interface adds/edits
836 use Storable qw(thaw);
842 my $param = thaw(decode_base64(shift));
843 warn Dumper($param) if $DEBUG;
845 my $old = qsearchs('part_svc', { 'svcpart' => $param->{'svcpart'} })
846 if $param->{'svcpart'};
848 #unmunge cgp_accessmodes (falze laziness-ish w/edit/process/svc_acct.cgi)
849 $param->{'svc_acct__cgp_accessmodes'} ||=
851 grep { $_ !~ /^(flag|label)$/ }
852 map { /^svc_acct__cgp_accessmodes_([\w\/]+)$/ or die "no way"; $1; }
854 grep /^svc_acct__cgp_accessmodes_([\w\/]+)$/,
859 my $new = new FS::part_svc ( {
862 # } qw(svcpart svc svcdb)
863 } ( fields('part_svc'),
864 map { my $svcdb = $_;
865 my @fields = fields($svcdb);
866 push @fields, 'usergroup' if $svcdb eq 'svc_acct'
867 or $svcdb eq 'svc_broadband'; #kludge
870 my $f = $svcdb.'__'.$_;
871 my $flag = $param->{ $f.'_flag' } || ''; #silence warnings
872 if ( $flag =~ /^[MAHP]$/ ) {
873 $param->{ $f } = delete( $param->{ $f.'_classnum' } );
875 if ( ( $flag =~ /^[MAHSP]$/ or $_ eq 'usergroup' )
876 and ref($param->{ $f }) ) {
877 $param->{ $f } = join(',', @{ $param->{ $f } });
879 ( $f, $f.'_flag', $f.'_label', $f.'_required' );
883 } FS::part_svc->svc_tables()
888 map { $_->exportnum => ( $param->{'exportnum'.$_->exportnum} || '') }
889 qsearch('part_export', {} );
890 foreach my $exportnum (%exportnums) {
891 my $role = $param->{'exportnum'.$exportnum.'_role'};
892 # role is undef if the export has no role selector
893 if ( $exportnums{$exportnum} && $role ) {
894 $exportnums{$exportnum} = $role;
898 if ( $param->{'svcpart'} ) {
899 $error = $new->replace( $old,
900 '1.3-COMPAT', #totally bunk, as jeff noted
906 $error = $new->insert( [ 'usergroup' ],
910 $param->{'svcpart'} = $new->getfield('svcpart');
913 $error ||= $new->process_o2m(
914 'table' => 'part_svc_msgcat',
916 'fields' => [ 'locale', 'svc' ],
919 die "$error\n" if $error;
921 foreach my $part_svc_export ( $new->part_export_partsvc ) {
922 $error = $part_svc_export->export_partsvc($new);
924 return $error if $error;
927 =item process_bulk_cust_svc
929 Job-queue processor for web interface bulk customer service changes
933 use Storable qw(thaw);
936 sub process_bulk_cust_svc {
939 my $param = thaw(decode_base64(shift));
940 warn Dumper($param) if $DEBUG;
942 local($FS::svc_Common::noexport_hack) = 1
943 if $param->{'noexport'};
946 qsearchs('part_svc', { 'svcpart' => $param->{'old_svcpart'} } );
948 die "Must select a new service definition\n" unless $param->{'new_svcpart'};
950 #the rest should be abstracted out to to its own subroutine?
952 local $SIG{HUP} = 'IGNORE';
953 local $SIG{INT} = 'IGNORE';
954 local $SIG{QUIT} = 'IGNORE';
955 local $SIG{TERM} = 'IGNORE';
956 local $SIG{TSTP} = 'IGNORE';
957 local $SIG{PIPE} = 'IGNORE';
959 my $oldAutoCommit = $FS::UID::AutoCommit;
960 local $FS::UID::AutoCommit = 0;
963 local( $FS::cust_svc::ignore_quantity ) = 1;
965 my $total = $old_part_svc->num_cust_svc( $param->{'pkgpart'} );
968 foreach my $old_cust_svc ( $old_part_svc->cust_svc( $param->{'pkgpart'} ) ) {
970 my $new_cust_svc = new FS::cust_svc { $old_cust_svc->hash };
972 $new_cust_svc->svcpart( $param->{'new_svcpart'} );
973 my $error = $new_cust_svc->replace($old_cust_svc);
975 $dbh->rollback if $oldAutoCommit;
976 die "$error\n" if $error;
979 $error = $job->update_statustext( int( 100 * ++$n / $total ) );
981 $dbh->rollback if $oldAutoCommit;
982 die $error if $error;
987 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
993 sub _upgrade_data { #class method
994 my ($class, %opts) = @_;
996 my @part_svc_column = qsearch('part_svc_column', { 'columnname' => 'usergroup' });
997 foreach my $col ( @part_svc_column ) {
998 next if $col->columnvalue =~ /^[\d,]+$/ || !$col->columnvalue;
999 my @groupnames = split(',',$col->columnvalue);
1002 foreach my $groupname ( @groupnames ) {
1003 my $g = qsearchs('radius_group', { 'groupname' => $groupname } );
1005 $g = new FS::radius_group {
1006 'groupname' => $groupname,
1007 'description' => $groupname,
1009 $error = $g->insert;
1010 die "Error inserting new radius_group for service definition group \"$groupname\": $error"
1013 push @groupnums, $g->groupnum;
1015 $col->columnvalue(join(',',@groupnums));
1016 $error = $col->replace;
1017 die $error if $error;
1020 my @badlabels = qsearch({
1021 'table' => 'part_svc_column',
1023 'extra_sql' => 'WHERE columnlabel IN ('.
1024 "'Descriptive label for this particular device.',".
1025 "'IP address. Leave blank for automatic assignment.',".
1026 "'Maximum upload speed for this service in Kbps. 0 denotes unlimited.',".
1027 "'Maximum download speed for this service in Kbps. 0 denotes unlimited.')"
1029 foreach my $col ( @badlabels ) {
1030 $col->columnlabel('');
1031 my $error = $col->replace;
1032 die $error if $error;
1039 Delete is unimplemented.
1041 The list of svc_* tables is no longer hardcoded, but svc_acct_pop is skipped
1042 as a special case until it is renamed.
1044 all_part_svc_column methods should be documented
1048 L<FS::Record>, L<FS::part_svc_column>, L<FS::part_pkg>, L<FS::pkg_svc>,
1049 L<FS::cust_svc>, L<FS::svc_acct>, L<FS::svc_forward>, L<FS::svc_domain>,
1050 schema.html from the base documentation.