1 package FS::export_svc;
5 use FS::Record qw( qsearch qsearchs dbh );
13 FS::export_svc - Object methods for export_svc records
19 $record = new FS::export_svc \%hash;
20 $record = new FS::export_svc { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::export_svc object links a service definition (see L<FS::part_svc>) to
33 an export (see L<FS::part_export>). FS::export_svc inherits from FS::Record.
34 The following fields are currently supported:
38 =item exportsvcnum - primary key
40 =item exportnum - export (see L<FS::part_export>)
42 =item svcpart - service definition (see L<FS::part_svc>)
52 Creates a new record. To add the record to the database, see L<"insert">.
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to. You can ask the object for a copy with the I<hash> method.
59 # the new method can be inherited from FS::Record, if a table method is defined
61 sub table { 'export_svc'; }
65 Adds this record to the database. If there is an error, returns the error,
66 otherwise returns false.
74 local $SIG{HUP} = 'IGNORE';
75 local $SIG{INT} = 'IGNORE';
76 local $SIG{QUIT} = 'IGNORE';
77 local $SIG{TERM} = 'IGNORE';
78 local $SIG{TSTP} = 'IGNORE';
79 local $SIG{PIPE} = 'IGNORE';
81 my $oldAutoCommit = $FS::UID::AutoCommit;
82 local $FS::UID::AutoCommit = 0;
85 $error = $self->check;
86 return $error if $error;
88 #check for duplicates!
92 my $svcdb = $self->part_svc->svcdb;
93 if ( $svcdb eq 'svc_acct' ) { #XXX AND UID! sheesh @method or %method not $method
94 if ( $self->part_export->nodomain =~ /^Y/i ) {
98 $label = 'username@domain';
101 } elsif ( $svcdb eq 'domain' ) {
105 warn "WARNING: XXX fill in this warning";
109 my @current_svc = $self->part_export->svc_x;
110 my @new_svc = $self->part_svc->svc_x;
111 my %cur_svc = map { $_->$method() => 1 } @current_svc;
112 my @dup_svc = grep { $cur_svc{$_->method()} } @new_svc;
114 if ( @dup_svc ) { #aye, that's the rub
115 #error out for now, eventually accept different options of adjustments
116 # to make to allow us to continue forward
117 $dbh->rollback if $oldAutoCommit;
118 return "Can't export ".
119 $self->part_svc->svcpart.':'.$self->part_svc->svc. " service to ".
120 $self->part_export->exportnum.':'.$self->exporttype.
121 ' on '. $self->machine.
122 " : Duplicate $label: ".
123 join(', ', sort map { $_->method() } @dup_svc );
124 #XXX eventually a sort sub so usernames and domains are default alpha, username@domain is domain first then username, and uid is numeric
128 #end of duplicate check, whew
130 $error = $self->SUPER::insert;
132 $dbh->rollback if $oldAutoCommit;
136 # if ( $self->part_svc->svcdb eq 'svc_acct' ) {
138 # if ( $self->part_export->nodomain =~ /^Y/i ) {
140 # select username from svc_acct where svcpart = $svcpart
141 # group by username having count(*) > 1;
145 # select username, domain
147 # join svc_domain on ( svc_acct.domsvc = svc_domain.svcnum )
148 # group by username, domain having count(*) > 1;
152 # } elsif ( $self->part_svc->svcdb eq 'svc_domain' ) {
154 # #similar but easier domain checking one
159 # map { $_->part_svc }
160 # grep { $_->svcpart != $self->svcpart }
161 # $self->part_export->export_svc;
163 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
169 Delete this record from the database.
173 # the delete method can be inherited from FS::Record
175 =item replace OLD_RECORD
177 Replaces the OLD_RECORD with this one in the database. If there is an error,
178 returns the error, otherwise returns false.
182 # the replace method can be inherited from FS::Record
186 Checks all fields to make sure this is a valid record. If there is
187 an error, returns the error, otherwise returns false. Called by the insert
192 # the check method should currently be supplied - FS::Record contains some
193 # data checking routines
198 $self->ut_numbern('exportsvcnum')
199 || $self->ut_number('exportnum')
200 || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
201 || $self->ut_number('svcpart')
202 || $self->ut_foreign_key('svcpart', 'part_svc', 'svcpart')
208 Returns the FS::part_export object (see L<FS::part_export>).
214 qsearchs( 'part_export', { 'exportnum' => $self->exportnum } );
219 Returns the FS::part_svc object (see L<FS::part_svc>).
225 qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
234 L<FS::part_export>, L<FS::part_svc>, L<FS::Record>, schema.html from the base