2 use base qw(FS::o2m_Common FS::Record);
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;
16 FS::UID->install_callback(sub {
17 # preload the cache and make sure all modules load
18 my $svc_defs = FS::part_svc->_svc_defs;
25 FS::part_svc - Object methods for part_svc objects
31 $record = new FS::part_svc \%hash
32 $record = new FS::part_svc { 'column' => 'value' };
34 $error = $record->insert;
35 $error = $record->insert( [ 'pseudofield' ] );
36 $error = $record->insert( [ 'pseudofield' ], \%exportnums );
38 $error = $new_record->replace($old_record);
39 $error = $new_record->replace($old_record, '1.3-COMPAT', [ 'pseudofield' ] );
40 $error = $new_record->replace($old_record, '1.3-COMPAT', [ 'pseudofield' ], \%exportnums );
42 $error = $record->delete;
44 $error = $record->check;
48 An FS::part_svc represents a service definition. FS::part_svc inherits from
49 FS::Record. The following fields are currently supported:
53 =item svcpart - primary key (assigned automatically for new service definitions)
55 =item svc - text name of this service definition
57 =item svcdb - table used for this service. See L<FS::svc_acct>,
58 L<FS::svc_domain>, and L<FS::svc_forward>, among others.
60 =item classnum - Optional service class (see L<FS::part_svc_class>)
62 =item disabled - Disabled flag, empty or `Y'
64 =item preserve - Preserve after cancellation, empty or 'Y'
66 =item selfservice_access - Access allowed to the service via self-service:
67 empty for full access, "readonly" for read-only, "hidden" to hide it entirely
69 =item restrict_edit_password - Require the "Provision customer service" access
70 right to change the password field, rather than just "Edit password". Only
71 relevant to svc_acct for now.
73 =item has_router - Allow the service to have an L<FS::router> connected
74 through it. Probably only relevant to svc_broadband, svc_acct, and svc_dsl
85 Creates a new service definition. To add the service definition to the
86 database, see L<"insert">.
90 sub table { 'part_svc'; }
92 =item insert [ EXTRA_FIELDS_ARRAYREF [ , EXPORTNUMS_HASHREF [ , JOB ] ] ]
94 Adds this service definition to the database. If there is an error, returns
95 the error, otherwise returns false.
97 The following pseudo-fields may be defined, and will be maintained in
98 the part_svc_column table appropriately (see L<FS::part_svc_column>).
102 =item I<svcdb>__I<field> - Default or fixed value for I<field> in I<svcdb>.
104 =item I<svcdb>__I<field>_label
106 =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.
108 =item I<svcdb>__I<field>_required - I<field> should always have a true value
112 If you want to add part_svc_column records for fields that do not exist as
113 fields in the I<svcdb> table, make sure to list then in
114 EXTRA_FIELDS_ARRAYREF also.
116 If EXPORTNUMS_HASHREF is specified (keys are exportnums and values are
117 boolean), the appopriate export_svc records will be inserted.
126 @fields = @{shift(@_)} if @_;
127 my $exportnums = shift || {};
131 local $SIG{HUP} = 'IGNORE';
132 local $SIG{INT} = 'IGNORE';
133 local $SIG{QUIT} = 'IGNORE';
134 local $SIG{TERM} = 'IGNORE';
135 local $SIG{TSTP} = 'IGNORE';
136 local $SIG{PIPE} = 'IGNORE';
138 my $oldAutoCommit = $FS::UID::AutoCommit;
139 local $FS::UID::AutoCommit = 0;
142 my $error = $self->SUPER::insert;
144 $dbh->rollback if $oldAutoCommit;
148 # add part_svc_column records
150 my $svcdb = $self->svcdb;
151 foreach my $field (fields($svcdb), @fields) {
152 next if $field eq 'svcnum';
153 my $prefix = $svcdb.'__';
154 if ( defined( $self->getfield($prefix.$field.'_flag'))
155 or defined($self->getfield($prefix.$field.'_required'))
156 or length($self->getfield($prefix.$field.'_label'))
158 my $part_svc_column = $self->part_svc_column($field);
159 my $previous = qsearchs('part_svc_column', {
160 'svcpart' => $self->svcpart,
161 'columnname' => $field,
164 my $flag = $self->getfield($prefix.$field.'_flag');
165 my $label = $self->getfield($prefix.$field.'_label');
166 my $required = $self->getfield($prefix.$field.'_required') ? 'Y' : '';
167 if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) {
169 if ( uc($flag) =~ /^([A-Z])$/ ) {
170 my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
172 $part_svc_column->setfield('columnflag', $1);
173 $part_svc_column->setfield('columnvalue',
174 &$parser($self->getfield($prefix.$field))
178 $part_svc_column->setfield('columnlabel', $label)
179 if $label !~ /^\s*$/;
181 $part_svc_column->setfield('required', $required);
184 $error = $part_svc_column->replace($previous);
186 $error = $part_svc_column->insert;
190 $error = $previous ? $previous->delete : '';
193 $dbh->rollback if $oldAutoCommit;
200 # add export_svc records
201 my @exportnums = grep $exportnums->{$_}, keys %$exportnums;
202 my $slice = 100/scalar(@exportnums) if @exportnums;
204 foreach my $exportnum ( @exportnums ) {
205 my $export_svc = new FS::export_svc ( {
206 'exportnum' => $exportnum,
207 'svcpart' => $self->svcpart,
208 'role' => $exportnums->{$exportnum},
210 $error = $export_svc->insert($job, $slice*$done++, $slice);
212 $dbh->rollback if $oldAutoCommit;
217 # XXX shouldn't this update fixed values?
219 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
226 Currently unimplemented. Set the "disabled" field instead.
231 return "Can't (yet?) delete service definitions.";
232 # check & make sure the svcpart isn't in cust_svc or pkg_svc (in any packages)?
235 =item replace OLD_RECORD [ '1.3-COMPAT' [ , EXTRA_FIELDS_ARRAYREF [ , EXPORTNUMS_HASHREF [ , JOB ] ] ] ]
237 Replaces OLD_RECORD with this one in the database. If there is an error,
238 returns the error, otherwise returns false.
242 TODOC: EXTRA_FIELDS_ARRAYREF (same as insert method)
249 my ( $new, $old ) = ( shift, shift );
254 if ( @_ && $_[0] eq '1.3-COMPAT' ) {
257 @fields = @{shift(@_)} if @_;
258 $exportnums = @_ ? shift : '';
261 return 'non-1.3-COMPAT interface not yet written';
265 return "Can't change svcdb for an existing service definition!"
266 unless $old->svcdb eq $new->svcdb;
268 local $SIG{HUP} = 'IGNORE';
269 local $SIG{INT} = 'IGNORE';
270 local $SIG{QUIT} = 'IGNORE';
271 local $SIG{TERM} = 'IGNORE';
272 local $SIG{TSTP} = 'IGNORE';
273 local $SIG{PIPE} = 'IGNORE';
275 my $oldAutoCommit = $FS::UID::AutoCommit;
276 local $FS::UID::AutoCommit = 0;
279 my $error = $new->SUPER::replace( $old );
281 $dbh->rollback if $oldAutoCommit;
285 if ( $compat eq '1.3' ) {
287 # maintain part_svc_column records
289 my $svcdb = $new->svcdb;
290 foreach my $field (fields($svcdb),@fields) {
291 next if $field eq 'svcnum';
292 my $prefix = $svcdb.'__';
293 if ( defined( $new->getfield($prefix.$field.'_flag'))
294 or defined($new->getfield($prefix.$field.'_required'))
295 or length($new->getfield($prefix.$field.'_label'))
297 my $part_svc_column = $new->part_svc_column($field);
298 my $previous = qsearchs('part_svc_column', {
299 'svcpart' => $new->svcpart,
300 'columnname' => $field,
303 my $flag = $new->getfield($svcdb.'__'.$field.'_flag');
304 my $label = $new->getfield($svcdb.'__'.$field.'_label');
305 my $required = $new->getfield($svcdb.'__'.$field.'_required') ? 'Y' : '';
307 if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) {
309 if ( uc($flag) =~ /^([A-Z])$/ ) {
310 $part_svc_column->setfield('columnflag', $1);
311 my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
313 $part_svc_column->setfield('columnvalue',
314 &$parser($new->getfield($svcdb.'__'.$field))
317 $part_svc_column->setfield('columnflag', '');
318 $part_svc_column->setfield('columnvalue', '');
321 $part_svc_column->setfield('columnlabel', $label)
322 if $label !~ /^\s*$/;
324 $part_svc_column->setfield('required', $required);
327 $error = $part_svc_column->replace($previous);
329 $error = $part_svc_column->insert;
332 $error = $previous ? $previous->delete : '';
335 $dbh->rollback if $oldAutoCommit;
341 # maintain export_svc records
343 if ( $exportnums ) { # hash of exportnum => role
345 #false laziness w/ edit/process/agent_type.cgi
346 #and, more importantly, with m2m_Common
347 my @new_export_svc = ();
348 foreach my $part_export ( qsearch('part_export', {}) ) {
349 my $exportnum = $part_export->exportnum;
351 'exportnum' => $exportnum,
352 'svcpart' => $new->svcpart,
354 my $export_svc = qsearchs('export_svc', $hashref);
357 my $old_role = $export_svc->role || 1; # 1 = null in the db
358 if ( ! $exportnums->{$exportnum}
359 or $old_role ne $exportnums->{$exportnum} ) {
361 $error = $export_svc->delete;
363 $dbh->rollback if $oldAutoCommit;
366 undef $export_svc; # on a role change, force it to be reinserted
370 if ( ! $export_svc && $exportnums->{$exportnum} ) {
371 # also applies if it's been undef'd because of role change
372 $hashref->{role} = $exportnums->{$exportnum};
373 push @new_export_svc, new FS::export_svc ( $hashref );
378 my $slice = 100/scalar(@new_export_svc) if @new_export_svc;
380 foreach my $export_svc (@new_export_svc) {
381 $error = $export_svc->insert($job, $slice*$done++, $slice);
383 $dbh->rollback if $oldAutoCommit;
387 $error = $job->update_statustext( int( $slice * $done ) );
389 $dbh->rollback if $oldAutoCommit;
398 $dbh->rollback if $oldAutoCommit;
399 return 'non-1.3-COMPAT interface not yet written';
403 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
410 Checks all fields to make sure this is a valid service definition. If there is
411 an error, returns the error, otherwise returns false. Called by the insert
421 $self->ut_numbern('svcpart')
422 || $self->ut_text('svc')
423 || $self->ut_alpha('svcdb')
424 || $self->ut_flag('disabled')
425 || $self->ut_flag('preserve')
426 || $self->ut_enum('selfservice_access', [ '', 'hidden', 'readonly' ] )
427 || $self->ut_foreign_keyn('classnum', 'part_svc_class', 'classnum' )
428 || $self->ut_flag('restrict_edit_password')
429 || $self->ut_flag('has_router')
431 return $error if $error;
433 my @fields = eval { fields( $self->svcdb ) }; #might die
434 return "Unknown svcdb: ". $self->svcdb. " (Error: $@)"
440 =item part_svc_column COLUMNNAME
442 Returns the part_svc_column object (see L<FS::part_svc_column>) for the given
443 COLUMNNAME, or a new part_svc_column object if none exists.
447 sub part_svc_column {
448 my( $self, $columnname) = @_;
450 qsearchs('part_svc_column', {
451 'svcpart' => $self->svcpart,
452 'columnname' => $columnname,
454 ) or new FS::part_svc_column {
455 'svcpart' => $self->svcpart,
456 'columnname' => $columnname,
460 =item all_part_svc_column
464 sub all_part_svc_column {
466 qsearch('part_svc_column', { 'svcpart' => $self->svcpart } );
469 =item part_export [ EXPORTTYPE ]
471 Returns a list of all exports (see L<FS::part_export>) for this service, or,
472 if an export type is specified, only returns exports of the given type.
479 $search{'exporttype'} = shift if @_;
480 map { $_ } #behavior of sort undefined in scalar context
481 sort { $a->weight <=> $b->weight }
482 map { qsearchs('part_export', { 'exportnum'=>$_->exportnum, %search } ) }
483 qsearch('export_svc', { 'svcpart'=>$self->svcpart } );
486 =item part_export_usage
488 Returns a list of any exports (see L<FS::part_export>) for this service that
489 are capable of reporting usage information.
493 sub part_export_usage {
495 grep $_->can('usage_sessions'), $self->part_export;
498 =item part_export_did
500 Returns a list of any exports (see L<FS::part_export>) for this service that
501 are capable of returing available DID (phone number) information.
505 sub part_export_did {
507 grep $_->can_get_dids, $self->part_export;
510 =item part_export_dsl_pull
512 Returns a list of any exports (see L<FS::part_export>) for this service that
513 are capable of pulling/pushing DSL orders.
517 sub part_export_dsl_pull {
519 grep $_->can('dsl_pull'), $self->part_export;
522 =item part_export_partsvc
524 Returns a list of any exports (see L<FS::part_export>) for this service that
525 are capable of pushing a change after part svc is changed.
529 sub part_export_partsvc {
531 grep $_->can('export_partsvc'), $self->part_export;
534 =item cust_svc [ PKGPART ]
536 Returns a list of associated customer services (FS::cust_svc records).
538 If a PKGPART is specified, returns the customer services which are contained
539 within packages of that type (see L<FS::part_pkg>). If PKGPARTis specified as
540 B<0>, returns unlinked customer services.
547 my $hashref = { 'svcpart' => $self->svcpart };
549 my( $addl_from, $extra_sql ) = ( '', '' );
552 if ( $pkgpart =~ /^(\d+)$/ ) {
553 $addl_from = 'LEFT JOIN cust_pkg USING ( pkgnum )';
554 $extra_sql = "AND pkgpart = $1";
555 } elsif ( $pkgpart eq '0' ) {
556 $hashref->{'pkgnum'} = '';
561 'table' => 'cust_svc',
562 'addl_from' => $addl_from,
563 'hashref' => $hashref,
564 'extra_sql' => $extra_sql,
568 =item num_cust_svc [ PKGPART ]
570 Returns the number of associated customer services (FS::cust_svc records).
572 If a PKGPART is specified, returns the number of customer services which are
573 contained within packages of that type (see L<FS::part_pkg>). If PKGPART
574 is specified as B<0>, returns the number of unlinked customer services.
581 return $self->{Hash}{num_cust_svc}
582 if !@_ && exists($self->{Hash}{num_cust_svc});
584 my @param = ( $self->svcpart );
586 my( $join, $and ) = ( '', '' );
590 $join = 'LEFT JOIN cust_pkg USING ( pkgnum )';
591 $and = 'AND pkgpart = ?';
592 push @param, $pkgpart;
593 } elsif ( $pkgpart eq '0' ) {
594 $and = 'AND pkgnum IS NULL';
598 my $sth = dbh->prepare(
599 "SELECT COUNT(*) FROM cust_svc $join WHERE svcpart = ? $and"
600 ) or die dbh->errstr;
601 $sth->execute(@param)
603 $sth->fetchrow_arrayref->[0];
606 =item num_cust_svc_cancelled
608 Returns the number of associated customer services that are
609 attached to cancelled packages.
613 sub num_cust_svc_cancelled {
615 my $sth = dbh->prepare(
616 "SELECT COUNT(*) FROM cust_svc
617 LEFT JOIN cust_pkg USING ( pkgnum )
619 AND cust_pkg.cancel IS NOT NULL"
620 ) or die dbh->errstr;
621 $sth->execute($self->svcpart)
623 $sth->fetchrow_arrayref->[0];
628 Returns a list of associated FS::svc_* records.
634 map { $_->svc_x } $self->cust_svc;
637 =item svc_locale LOCALE
639 Returns a customer-viewable service definition label in the chosen LOCALE.
640 If there is no entry for that locale or if LOCALE is empty, returns
646 my( $self, $locale ) = @_;
647 return $self->svc unless $locale;
648 my $part_svc_msgcat = qsearchs('part_svc_msgcat', {
649 svcpart => $self->svcpart,
651 }) or return $self->svc;
652 $part_svc_msgcat->svc;
667 return $svc_defs if $svc_defs; #cache
669 my $conf = new FS::Conf;
671 #false laziness w/part_pkg.pm::plan_info
674 foreach my $INC ( @INC ) {
675 warn "globbing $INC/FS/svc_*.pm\n" if $DEBUG;
676 foreach my $file ( glob("$INC/FS/svc_*.pm") ) {
678 warn "attempting to load service table info from $file\n" if $DEBUG;
679 $file =~ /\/(\w+)\.pm$/ or do {
680 warn "unrecognized file in $INC/FS/: $file\n";
685 if ( $mod =~ /^svc_[A-Z]/ or $mod =~ /^(svc_acct_pop|svc_export_machine)$/ ) {
686 warn "skipping FS::$mod" if $DEBUG;
690 eval "use FS::$mod;";
692 die "error using FS::$mod (skipping): $@\n" if $@;
695 unless ( UNIVERSAL::can("FS::$mod", 'table_info') ) {
696 warn "FS::$mod has no table_info method; skipping";
700 my $info = "FS::$mod"->table_info;
701 unless ( keys %$info ) {
702 warn "FS::$mod->table_info doesn't return info, skipping\n";
705 warn "got info from FS::$mod: $info\n" if $DEBUG;
706 if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
707 warn "skipping disabled service FS::$mod" if $DEBUG;
711 foreach ("FS::$mod"->virtual_fields_hash) {
712 $info->{'fields'}->{$_->{'name'}} = $_->{'label'};
717 # all svc_* modules are required to have h_svc_* modules for invoice
718 # display. check for them as early as possible.
719 eval "use FS::h_$mod;";
721 die "couldn't load history record module h_$mod: $@\n";
727 tie my %svc_defs, 'Tie::IxHash',
728 map { $_ => $info{$_}->{'fields'} }
729 sort { $info{$a}->{'display_weight'} <=> $info{$b}->{'display_weight'} }
733 tie my %svc_info, 'Tie::IxHash',
734 map { $_ => $info{$_} }
735 sort { $info{$a}->{'display_weight'} <=> $info{$b}->{'display_weight'} }
739 $svc_info = \%svc_info; #access via svc_table_info
740 $svc_defs = \%svc_defs; #cache
746 Returns a list of all svc_ tables.
752 my $svc_defs = $class->_svc_defs;
753 grep { defined( dbdef->table($_) ) } keys %$svc_defs;
756 =item svc_table_fields TABLE
758 Given a table name, returns a hashref of field names. The field names
759 returned are those with additional (service-definition related) information,
760 not necessarily all database fields of the table. Pseudo-fields may also
761 be returned (i.e. svc_acct.usergroup).
763 Each value of the hashref is another hashref, which can have one or more of
768 =item label - Description of the field
770 =item def_label - Optional description of the field in the context of service definitions
772 =item type - Currently "text", "select", "checkbox", "textarea", "disabled",
773 some components specified by "select-.*.html", and a bunch more...
775 =item disable_default - This field should not allow a default value in service definitions
777 =item disable_fixed - This field should not allow a fixed value in service definitions
779 =item disable_inventory - This field should not allow inventory values in service definitions
781 =item select_list - If type is "text", this can be a listref of possible values.
783 =item select_table - An alternative to select_list, this defines a database table with the possible choices.
785 =item select_key - Used with select_table, this is the field name of keys
787 =item select_label - Used with select_table, this is the field name of labels
789 =item select_allow_empty - Used with select_table, adds an empty option
791 =item required - This field should always have a true value (do not use with type checkbox or disabled)
797 #maybe this should move and be a class method in svc_Common.pm
798 sub svc_table_fields {
799 my($class, $table) = @_;
800 my $svc_defs = $class->_svc_defs;
801 my $def = $svc_defs->{$table};
803 foreach ( grep !ref($def->{$_}), keys %$def ) {
805 #normalize the shortcut in %info hash
806 $def->{$_} = { 'label' => $def->{$_} };
808 $def->{$_}{'type'} ||= 'text';
815 =item svc_table_info TABLE
817 Returns table_info for TABLE from cache, or empty
818 hashref if none is found.
820 Caution: caches table_info for ALL services when run;
821 access a service's table_info directly unless you know
822 you're loading them all.
824 Caution: does not standardize fields into hashrefs;
825 use L</svc_table_fields> to access fields.
832 $class->_svc_defs; #creates cache if needed
833 return $svc_info->{$table} || {};
844 Job-queue processor for web interface adds/edits
852 warn Dumper($param) if $DEBUG;
854 my $old = qsearchs('part_svc', { 'svcpart' => $param->{'svcpart'} })
855 if $param->{'svcpart'};
857 #unmunge cgp_accessmodes (falze laziness-ish w/edit/process/svc_acct.cgi)
858 $param->{'svc_acct__cgp_accessmodes'} ||=
860 grep { $_ !~ /^(flag|label)$/ }
861 map { /^svc_acct__cgp_accessmodes_([\w\/]+)$/ or die "no way"; $1; }
863 grep /^svc_acct__cgp_accessmodes_([\w\/]+)$/,
868 my $new = new FS::part_svc ( {
871 # } qw(svcpart svc svcdb)
872 } ( fields('part_svc'),
873 map { my $svcdb = $_;
874 my @fields = fields($svcdb);
875 push @fields, 'usergroup' if $svcdb eq 'svc_acct'
876 or $svcdb eq 'svc_broadband'; #kludge
879 my $f = $svcdb.'__'.$_;
880 my $flag = $param->{ $f.'_flag' } || ''; #silence warnings
881 if ( $flag =~ /^[MAHP]$/ ) {
882 $param->{ $f } = delete( $param->{ $f.'_classnum' } );
884 if ( ( $flag =~ /^[MAHSP]$/ or $_ eq 'usergroup' )
885 and ref($param->{ $f }) ) {
886 $param->{ $f } = join(',', @{ $param->{ $f } });
888 ( $f, $f.'_flag', $f.'_label', $f.'_required' );
892 } FS::part_svc->svc_tables()
897 map { $_->exportnum => ( $param->{'exportnum'.$_->exportnum} || '') }
898 qsearch('part_export', {} );
899 foreach my $exportnum (%exportnums) {
900 my $role = $param->{'exportnum'.$exportnum.'_role'};
901 # role is undef if the export has no role selector
902 if ( $exportnums{$exportnum} && $role ) {
903 $exportnums{$exportnum} = $role;
907 ## make sure export required fields are marked required.
909 foreach (keys %exportnums) {
910 my $export = qsearchs('part_export', { 'exportnum' => $_ })
913 push @required_fields, $export->required_fields if $export->can('required_fields');
916 foreach (@required_fields) { $new->set($_, 'Y'); }
919 if ( $param->{'svcpart'} ) {
920 $error = $new->replace( $old,
921 '1.3-COMPAT', #totally bunk, as jeff noted
927 $error = $new->insert( [ 'usergroup' ],
931 $param->{'svcpart'} = $new->getfield('svcpart');
934 $error ||= $new->process_o2m(
935 'table' => 'part_svc_msgcat',
937 'fields' => [ 'locale', 'svc' ],
940 die "$error\n" if $error;
942 foreach my $part_svc_export ( $new->part_export_partsvc ) {
943 $error = $part_svc_export->export_partsvc($new);
945 return $error if $error;
948 =item process_bulk_cust_svc
950 Job-queue processor for web interface bulk customer service changes
955 sub process_bulk_cust_svc {
958 warn Dumper($param) if $DEBUG;
960 local($FS::svc_Common::noexport_hack) = 1
961 if $param->{'noexport'};
964 qsearchs('part_svc', { 'svcpart' => $param->{'old_svcpart'} } );
966 die "Must select a new service definition\n" unless $param->{'new_svcpart'};
968 #the rest should be abstracted out to to its own subroutine?
970 local $SIG{HUP} = 'IGNORE';
971 local $SIG{INT} = 'IGNORE';
972 local $SIG{QUIT} = 'IGNORE';
973 local $SIG{TERM} = 'IGNORE';
974 local $SIG{TSTP} = 'IGNORE';
975 local $SIG{PIPE} = 'IGNORE';
977 my $oldAutoCommit = $FS::UID::AutoCommit;
978 local $FS::UID::AutoCommit = 0;
981 local( $FS::cust_svc::ignore_quantity ) = 1;
983 my $total = $old_part_svc->num_cust_svc( $param->{'pkgpart'} );
986 foreach my $old_cust_svc ( $old_part_svc->cust_svc( $param->{'pkgpart'} ) ) {
988 my $new_cust_svc = new FS::cust_svc { $old_cust_svc->hash };
990 $new_cust_svc->svcpart( $param->{'new_svcpart'} );
991 my $error = $new_cust_svc->replace($old_cust_svc);
993 $dbh->rollback if $oldAutoCommit;
994 die "$error\n" if $error;
997 $error = $job->update_statustext( int( 100 * ++$n / $total ) );
999 $dbh->rollback if $oldAutoCommit;
1000 die $error if $error;
1005 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
1011 sub _upgrade_data { #class method
1012 my ($class, %opts) = @_;
1014 my @part_svc_column = qsearch('part_svc_column', { 'columnname' => 'usergroup' });
1015 foreach my $col ( @part_svc_column ) {
1016 next if $col->columnvalue =~ /^[\d,]+$/ || !$col->columnvalue;
1017 my @groupnames = split(',',$col->columnvalue);
1020 foreach my $groupname ( @groupnames ) {
1021 my $g = qsearchs('radius_group', { 'groupname' => $groupname } );
1023 $g = new FS::radius_group {
1024 'groupname' => $groupname,
1025 'description' => $groupname,
1027 $error = $g->insert;
1028 die "Error inserting new radius_group for service definition group \"$groupname\": $error"
1031 push @groupnums, $g->groupnum;
1033 $col->columnvalue(join(',',@groupnums));
1034 $error = $col->replace;
1035 die $error if $error;
1038 my @badlabels = qsearch({
1039 'table' => 'part_svc_column',
1041 'extra_sql' => 'WHERE columnlabel IN ('.
1042 "'Descriptive label for this particular device.',".
1043 "'IP address. Leave blank for automatic assignment.',".
1044 "'Maximum upload speed for this service in Kbps. 0 denotes unlimited.',".
1045 "'Maximum download speed for this service in Kbps. 0 denotes unlimited.')"
1047 foreach my $col ( @badlabels ) {
1048 $col->columnlabel('');
1049 my $error = $col->replace;
1050 die $error if $error;
1057 Delete is unimplemented.
1059 The list of svc_* tables is no longer hardcoded, but svc_acct_pop is skipped
1060 as a special case until it is renamed.
1062 all_part_svc_column methods should be documented
1066 L<FS::Record>, L<FS::part_svc_column>, L<FS::part_pkg>, L<FS::pkg_svc>,
1067 L<FS::cust_svc>, L<FS::svc_acct>, L<FS::svc_forward>, L<FS::svc_domain>,
1068 schema.html from the base documentation.