67371bc3b534b6b0fe27c511fd504cddff259a50
[freeside.git] / FS / FS / part_export.pm
1 package FS::part_export;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::part_svc;
7
8 @ISA = qw(FS::Record);
9
10 =head1 NAME
11
12 FS::part_export - Object methods for part_export records
13
14 =head1 SYNOPSIS
15
16   use FS::part_export;
17
18   $record = new FS::part_export \%hash;
19   $record = new FS::part_export { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::part_export object represents an export of Freeside data to an external
32 provisioning system.  FS::part_export inherits from FS::Record.  The following
33 fields are currently supported:
34
35 =over 4
36
37 =item eventpart - primary key
38
39 =item svcpart - Service definition (see L<FS::part_svc>) to which this export applies
40
41 =item machine - Machine name 
42
43 =item exporttype - Export type
44
45 =item nodomain - blank or "Y" : usernames are exported to this service with no domain
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new export.  To add the export to the database, see L<"insert">.
56
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to.  You can ask the object for a copy with the I<hash> method.
59
60 =cut
61
62 # the new method can be inherited from FS::Record, if a table method is defined
63
64 sub table { 'part_export'; }
65
66 =item insert
67
68 Adds this record to the database.  If there is an error, returns the error,
69 otherwise returns false.
70
71 =cut
72
73 # the insert method can be inherited from FS::Record
74
75 =item delete
76
77 Delete this record from the database.
78
79 =cut
80
81 # the delete method can be inherited from FS::Record
82
83 =item replace OLD_RECORD
84
85 Replaces the OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =cut
89
90 # the replace method can be inherited from FS::Record
91
92 =item check
93
94 Checks all fields to make sure this is a valid export.  If there is
95 an error, returns the error, otherwise returns false.  Called by the insert
96 and replace methods.
97
98 =cut
99
100 sub check {
101   my $self = shift;
102   my $error = 
103     $self->ut_numbern('exportnum')
104     || $self->ut_number('svcpart')
105     || $self->ut_alpha('exporttype')
106   ;
107   return $error if $error;
108
109   return "Unknown svcpart: ". $self->svcpart
110     unless qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
111
112   $self->machine =~ /^([\w\-\.]*)$/
113     or return "Illegal machine: ". $self->machine;
114   $self->machine($1);
115
116   $self->nodomain =~ /^(Y?)$/ or return "Illegal nodomain: ". $self->nodomain;
117   $self->nodomain($1);
118
119   #check exporttype?
120
121   ''; #no error
122 }
123
124 =back
125
126 =head1 BUGS
127
128 Probably.
129
130 =head1 SEE ALSO
131
132 L<FS::part_export_option>, L<FS::part_svc>, L<FS::svc_acct>, L<FS::svc_domain>,
133 L<FS::svc_forward>, L<FS::Record>, schema.html from the base documentation.
134
135 =cut
136
137 1;
138