1 package FS::part_export;
5 use FS::Record qw( qsearch qsearchs dbh );
7 use FS::part_export_option;
13 FS::part_export - Object methods for part_export records
19 $record = new FS::part_export \%hash;
20 $record = new FS::part_export { 'column' => 'value' };
22 ($new_record, $options) = $template_recored->clone( $svcpart );
24 $error = $record->insert( { 'option' => 'value' } );
25 $error = $record->insert( \$options );
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::part_export object represents an export of Freeside data to an external
36 provisioning system. FS::part_export inherits from FS::Record. The following
37 fields are currently supported:
41 =item exportnum - primary key
43 =item svcpart - Service definition (see L<FS::part_svc>) to which this export applies
45 =item machine - Machine name
47 =item exporttype - Export type
49 =item nodomain - blank or "Y" : usernames are exported to this service with no domain
59 Creates a new export. To add the export to the database, see L<"insert">.
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to. You can ask the object for a copy with the I<hash> method.
66 # the new method can be inherited from FS::Record, if a table method is defined
68 sub table { 'part_export'; }
72 An alternate constructor. Creates a new export by duplicating an existing
73 export. The given svcpart is assigned to the new export.
75 Returns a list consisting of the new export object and a hashref of options.
81 my $class = ref($self);
82 my %hash = $self->hash;
83 $hash{'exportnum'} = '';
84 $hash{'svcpart'} = shift;
85 ( $class->new( \%hash ),
86 { map { $_->optionname => $_->optionvalue }
87 qsearch('part_export_option', { 'exportnum' => $self->exportnum } )
94 Adds this record to the database. If there is an error, returns the error,
95 otherwise returns false.
97 If a hash reference of options is supplied, part_export_option records are
98 created (see L<FS::part_export_option>).
102 #false laziness w/queue.pm
105 local $SIG{HUP} = 'IGNORE';
106 local $SIG{INT} = 'IGNORE';
107 local $SIG{QUIT} = 'IGNORE';
108 local $SIG{TERM} = 'IGNORE';
109 local $SIG{TSTP} = 'IGNORE';
110 local $SIG{PIPE} = 'IGNORE';
112 my $oldAutoCommit = $FS::UID::AutoCommit;
113 local $FS::UID::AutoCommit = 0;
116 my $error = $self->SUPER::insert;
118 $dbh->rollback if $oldAutoCommit;
123 foreach my $optionname ( keys %{$options} ) {
124 my $part_export_option = new FS::part_export_option ( {
125 'optionname' => $optionname,
126 'optionvalue' => $options->{$optionname},
128 $error = $part_export_option->insert;
130 $dbh->rollback if $oldAutoCommit;
135 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
143 Delete this record from the database.
147 # the delete method can be inherited from FS::Record
149 =item replace OLD_RECORD
151 Replaces the OLD_RECORD with this one in the database. If there is an error,
152 returns the error, otherwise returns false.
156 # the replace method can be inherited from FS::Record
160 Checks all fields to make sure this is a valid export. If there is
161 an error, returns the error, otherwise returns false. Called by the insert
169 $self->ut_numbern('exportnum')
170 || $self->ut_number('svcpart')
171 || $self->ut_alpha('exporttype')
173 return $error if $error;
175 return "Unknown svcpart: ". $self->svcpart
176 unless qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
178 $self->machine =~ /^([\w\-\.]*)$/
179 or return "Illegal machine: ". $self->machine;
182 $self->nodomain =~ /^(Y?)$/ or return "Illegal nodomain: ". $self->nodomain;
192 Returns the service definition (see L<FS::part_svc>) for this export.
198 qsearchs('part_svc', { svcpart => $self->svcpart } );
209 L<FS::part_export_option>, L<FS::part_svc>, L<FS::svc_acct>, L<FS::svc_domain>,
210 L<FS::svc_forward>, L<FS::Record>, schema.html from the base documentation.