1 package FS::part_export;
4 use vars qw( @ISA @EXPORT_OK $DEBUG %exports );
7 use FS::Record qw( qsearch qsearchs dbh );
10 use FS::part_export_option;
13 #for export modules, though they should probably just use it themselves
16 @ISA = qw( FS::option_Common );
17 @EXPORT_OK = qw(export_info);
23 FS::part_export - Object methods for part_export records
29 $record = new FS::part_export \%hash;
30 $record = new FS::part_export { 'column' => 'value' };
32 #($new_record, $options) = $template_recored->clone( $svcpart );
34 $error = $record->insert( { 'option' => 'value' } );
35 $error = $record->insert( \%options );
37 $error = $new_record->replace($old_record);
39 $error = $record->delete;
41 $error = $record->check;
45 An FS::part_export object represents an export of Freeside data to an external
46 provisioning system. FS::part_export inherits from FS::Record. The following
47 fields are currently supported:
51 =item exportnum - primary key
53 =item exportname - Descriptive name
55 =item machine - Machine name
57 =item exporttype - Export type
59 =item nodomain - blank or "Y" : usernames are exported to this service with no domain
69 Creates a new export. To add the export to the database, see L<"insert">.
71 Note that this stores the hash reference, not a distinct copy of the hash it
72 points to. You can ask the object for a copy with the I<hash> method.
76 # the new method can be inherited from FS::Record, if a table method is defined
78 sub table { 'part_export'; }
84 #An alternate constructor. Creates a new export by duplicating an existing
85 #export. The given svcpart is assigned to the new export.
87 #Returns a list consisting of the new export object and a hashref of options.
93 # my $class = ref($self);
94 # my %hash = $self->hash;
95 # $hash{'exportnum'} = '';
96 # $hash{'svcpart'} = shift;
97 # ( $class->new( \%hash ),
98 # { map { $_->optionname => $_->optionvalue }
99 # qsearch('part_export_option', { 'exportnum' => $self->exportnum } )
106 Adds this record to the database. If there is an error, returns the error,
107 otherwise returns false.
109 If a hash reference of options is supplied, part_export_option records are
110 created (see L<FS::part_export_option>).
114 Delete this record from the database.
118 #foreign keys would make this much less tedious... grr dumb mysql
121 local $SIG{HUP} = 'IGNORE';
122 local $SIG{INT} = 'IGNORE';
123 local $SIG{QUIT} = 'IGNORE';
124 local $SIG{TERM} = 'IGNORE';
125 local $SIG{TSTP} = 'IGNORE';
126 local $SIG{PIPE} = 'IGNORE';
128 my $oldAutoCommit = $FS::UID::AutoCommit;
129 local $FS::UID::AutoCommit = 0;
132 my $error = $self->SUPER::delete;
134 $dbh->rollback if $oldAutoCommit;
138 foreach my $export_svc ( $self->export_svc ) {
139 my $error = $export_svc->delete;
141 $dbh->rollback if $oldAutoCommit;
146 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
154 Checks all fields to make sure this is a valid export. If there is
155 an error, returns the error, otherwise returns false. Called by the insert
163 $self->ut_numbern('exportnum')
164 || $self->ut_textn('exportname')
165 || $self->ut_domain('machine')
166 || $self->ut_alpha('exporttype')
168 return $error if $error;
170 $self->nodomain =~ /^(Y?)$/ or return "Illegal nodomain: ". $self->nodomain;
173 $self->deprecated(1); #BLAH
182 Returns a label for this export, "exportname||exportype (machine)".
188 ($self->exportname || $self->exporttype ). ' ('. $self->machine. ')';
193 #Returns the service definition (see L<FS::part_svc>) for this export.
199 # qsearchs('part_svc', { svcpart => $self->svcpart } );
204 croak "FS::part_export::part_svc deprecated";
205 #confess "FS::part_export::part_svc deprecated";
210 Returns a list of associated FS::svc_* records.
216 map { $_->svc_x } $self->cust_svc;
221 Returns a list of associated FS::cust_svc records.
227 map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
228 grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
234 Returns a list of associated FS::export_svc records.
240 qsearch('export_svc', { 'exportnum' => $self->exportnum } );
245 Returns a list of associated FS::export_device records.
251 qsearch('export_device', { 'exportnum' => $self->exportnum } );
254 =item part_export_option
256 Returns all options as FS::part_export_option objects (see
257 L<FS::part_export_option>).
261 sub part_export_option {
263 $self->option_objects;
268 Returns a list of option names and values suitable for assigning to a hash.
270 =item option OPTIONNAME
272 Returns the option value for the given name, or the empty string.
276 Reblesses the object into the FS::part_export::EXPORTTYPE class, where
277 EXPORTTYPE is the object's I<exporttype> field. There should be better docs
278 on how to create new exports, but until then, see L</NEW EXPORT CLASSES>.
284 my $exporttype = $self->exporttype;
285 my $class = ref($self). "::$exporttype";
288 bless($self, $class) unless $@;
292 #these should probably all go away, just let the subclasses define em
294 =item export_insert SVC_OBJECT
301 $self->_export_insert(@_);
307 # my $method = $AUTOLOAD;
308 # #$method =~ s/::(\w+)$/::_$1/; #infinite loop prevention
309 # $method =~ s/::(\w+)$/_$1/; #infinite loop prevention
310 # $self->$method(@_);
313 =item export_replace NEW OLD
320 $self->_export_replace(@_);
330 $self->_export_delete(@_);
340 $self->_export_suspend(@_);
343 =item export_unsuspend
347 sub export_unsuspend {
350 $self->_export_unsuspend(@_);
353 #fallbacks providing useful error messages intead of infinite loops
356 return "_export_insert: unknown export type ". $self->exporttype;
359 sub _export_replace {
361 return "_export_replace: unknown export type ". $self->exporttype;
366 return "_export_delete: unknown export type ". $self->exporttype;
369 #call svcdb-specific fallbacks
371 sub _export_suspend {
373 #warn "warning: _export_suspened unimplemented for". ref($self);
375 my $new = $svc_x->clone_suspended;
376 $self->_export_replace( $new, $svc_x );
379 sub _export_unsuspend {
381 #warn "warning: _export_unsuspend unimplemented for ". ref($self);
383 my $old = $svc_x->clone_kludge_unsuspend;
384 $self->_export_replace( $svc_x, $old );
387 =item export_links SVC_OBJECT ARRAYREF
389 Adds a list of web elements to ARRAYREF specific to this export and SVC_OBJECT.
390 The elements are displayed in the UI to lead the the operator to external
391 configuration, monitoring, and similar tools.
393 =item export_getsettings SVC_OBJECT SETTINGS_HASHREF DEFAUTS_HASHREF
395 Adds a hashref of settings to SETTINGSREF specific to this export and
396 SVC_OBJECT. The elements can be displayed in the UI on the service view.
398 DEFAULTSREF is a hashref with the same keys where true values indicate the
399 setting is a default (and thus can be displayed in the UI with less emphasis,
400 or hidden by default).
410 =item export_info [ SVCDB ]
412 Returns a hash reference of the exports for the given I<svcdb>, or if no
413 I<svcdb> is specified, for all exports. The keys of the hash are
414 I<exporttype>s and the values are again hash references containing information
417 'desc' => 'Description',
419 'option' => { label=>'Option Label' },
420 'option2' => { label=>'Another label' },
422 'nodomain' => 'Y', #or ''
423 'notes' => 'Additional notes',
429 return $exports{$_[0]} || {} if @_;
430 #{ map { %{$exports{$_}} } keys %exports };
431 my $r = { map { %{$exports{$_}} } keys %exports };
434 #=item exporttype2svcdb EXPORTTYPE
436 #Returns the applicable I<svcdb> for an I<exporttype>.
440 #sub exporttype2svcdb {
441 # my $exporttype = $_[0];
442 # foreach my $svcdb ( keys %exports ) {
443 # return $svcdb if grep { $exporttype eq $_ } keys %{$exports{$svcdb}};
448 #false laziness w/part_pkg & cdr
449 foreach my $INC ( @INC ) {
450 foreach my $file ( glob("$INC/FS/part_export/*.pm") ) {
451 warn "attempting to load export info from $file\n" if $DEBUG;
452 $file =~ /\/(\w+)\.pm$/ or do {
453 warn "unrecognized file in $INC/FS/part_export/: $file\n";
457 my $info = eval "use FS::part_export::$mod; ".
458 "\\%FS::part_export::$mod\::info;";
460 die "error using FS::part_export::$mod (skipping): $@\n" if $@;
463 unless ( keys %$info ) {
464 warn "no %info hash found in FS::part_export::$mod, skipping\n"
465 unless $mod =~ /^(passwdfile|null)$/; #hack but what the heck
468 warn "got export info from FS::part_export::$mod: $info\n" if $DEBUG;
471 ref($info->{'svc'}) ? @{$info->{'svc'}} : $info->{'svc'}
474 warn "blank svc for FS::part_export::$mod (skipping)\n";
477 $exports{$svc}->{$mod} = $info;
484 =head1 NEW EXPORT CLASSES
486 A module should be added in FS/FS/part_export/ (an example may be found in
487 eg/export_template.pm)
491 Hmm... cust_export class (not necessarily a database table...) ... ?
497 L<FS::part_export_option>, L<FS::export_svc>, L<FS::svc_acct>,
499 L<FS::svc_forward>, L<FS::Record>, schema.html from the base documentation.