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 #- have edit/process/part_svc.cgi redirect with error back to
93 #edit/part_svc.cgi rather than eidiot out
95 #- rewrite in SQL for efficiency
99 my $svcdb = $self->part_svc->svcdb;
100 if ( $svcdb eq 'svc_acct' ) { #XXX AND UID! sheesh @method or %method not $method
101 if ( $self->part_export->nodomain =~ /^Y/i ) {
102 $label = 'usernames';
103 $method = 'username';
105 $label = 'username@domain';
108 } elsif ( $svcdb eq 'domain' ) {
112 warn "WARNING: XXX fill in this warning";
117 my @current_svc = $self->part_export->svc_x;
118 #warn "current: ". scalar(@current_svc). " $current_svc[0]\n";
119 my @new_svc = $self->part_svc->svc_x;
120 #warn "new: ". scalar(@new_svc). " $new_svc[0]\n";
121 my %cur_svc = map { $_->$method() => 1 } @current_svc;
122 my @dup_svc = grep { $cur_svc{$_->$method()} } @new_svc;
124 if ( @dup_svc ) { #aye, that's the rub
125 #error out for now, eventually accept different options of adjustments
126 # to make to allow us to continue forward
127 $dbh->rollback if $oldAutoCommit;
128 return "Can't export ".
129 $self->part_svc->svcpart.':'.$self->part_svc->svc. " service to ".
130 $self->part_export->exportnum.':'.$self->part_export->exporttype.
131 ' on '. $self->part_export->machine.
132 ' : '. scalar(@dup_svc). " duplicate $label: ".
133 join(', ', sort map { $_->$method() } @dup_svc );
134 #XXX eventually a sort sub so usernames and domains are default alpha, username@domain is domain first then username, and uid is numeric
138 #end of duplicate check, whew
140 $error = $self->SUPER::insert;
142 $dbh->rollback if $oldAutoCommit;
146 # if ( $self->part_svc->svcdb eq 'svc_acct' ) {
148 # if ( $self->part_export->nodomain =~ /^Y/i ) {
150 # select username from svc_acct where svcpart = $svcpart
151 # group by username having count(*) > 1;
155 # select username, domain
157 # join svc_domain on ( svc_acct.domsvc = svc_domain.svcnum )
158 # group by username, domain having count(*) > 1;
162 # } elsif ( $self->part_svc->svcdb eq 'svc_domain' ) {
164 # #similar but easier domain checking one
169 # map { $_->part_svc }
170 # grep { $_->svcpart != $self->svcpart }
171 # $self->part_export->export_svc;
173 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
179 Delete this record from the database.
183 # the delete method can be inherited from FS::Record
185 =item replace OLD_RECORD
187 Replaces the OLD_RECORD with this one in the database. If there is an error,
188 returns the error, otherwise returns false.
192 # the replace method can be inherited from FS::Record
196 Checks all fields to make sure this is a valid record. If there is
197 an error, returns the error, otherwise returns false. Called by the insert
202 # the check method should currently be supplied - FS::Record contains some
203 # data checking routines
208 $self->ut_numbern('exportsvcnum')
209 || $self->ut_number('exportnum')
210 || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
211 || $self->ut_number('svcpart')
212 || $self->ut_foreign_key('svcpart', 'part_svc', 'svcpart')
213 || $self->SUPER::check
219 Returns the FS::part_export object (see L<FS::part_export>).
225 qsearchs( 'part_export', { 'exportnum' => $self->exportnum } );
230 Returns the FS::part_svc object (see L<FS::part_svc>).
236 qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
245 L<FS::part_export>, L<FS::part_svc>, L<FS::Record>, schema.html from the base