export host selection per service, RT#17914
[freeside.git] / FS / FS / part_export_machine.pm
1 package FS::part_export_machine;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( dbh qsearch ); #qsearchs );
6 use FS::part_export;
7 use FS::svc_export_machine;
8
9 =head1 NAME
10
11 FS::part_export_machine - Object methods for part_export_machine records
12
13 =head1 SYNOPSIS
14
15   use FS::part_export_machine;
16
17   $record = new FS::part_export_machine \%hash;
18   $record = new FS::part_export_machine { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::part_export_machine object represents an export hostname choice.
31 FS::part_export_machine inherits from FS::Record.  The following fields are
32 currently supported:
33
34 =over 4
35
36 =item machinenum
37
38 primary key
39
40 =item exportnum
41
42 Export, see L<FS::part_export>
43
44 =item machine
45
46 Hostname or IP address
47
48 =back
49
50 =head1 METHODS
51
52 =over 4
53
54 =item new HASHREF
55
56 Creates a new record.  To add the record to the database, see L<"insert">.
57
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to.  You can ask the object for a copy with the I<hash> method.
60
61 =cut
62
63 sub table { 'part_export_machine'; }
64
65 =item insert
66
67 Adds this record to the database.  If there is an error, returns the error,
68 otherwise returns false.
69
70 =item delete
71
72 Delete this record from the database.
73
74 =cut
75
76 sub delete {
77   my $self = shift;
78
79   local $SIG{HUP} = 'IGNORE';
80   local $SIG{INT} = 'IGNORE';
81   local $SIG{QUIT} = 'IGNORE';
82   local $SIG{TERM} = 'IGNORE';
83   local $SIG{TSTP} = 'IGNORE';
84   local $SIG{PIPE} = 'IGNORE';
85   my $oldAutoCommit = $FS::UID::AutoCommit;
86   local $FS::UID::AutoCommit = 0;
87   my $dbh = dbh;
88
89   my $error = $self->SUPER::delete;
90   if ( $error ) {
91     $dbh->rollback if $oldAutoCommit;
92     return $error;
93   }
94
95   foreach my $svc_export_machine ( $self->svc_export_machine ) {
96     my $error = $svc_export_machine->delete;
97     if ( $error ) {
98       $dbh->rollback if $oldAutoCommit;
99       return $error;
100     }
101   }
102
103   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
104   '';
105
106 }
107
108 =item replace OLD_RECORD
109
110 Replaces the OLD_RECORD with this one in the database.  If there is an error,
111 returns the error, otherwise returns false.
112
113 =item check
114
115 Checks all fields to make sure this is a valid record.  If there is
116 an error, returns the error, otherwise returns false.  Called by the insert
117 and replace methods.
118
119 =cut
120
121 sub check {
122   my $self = shift;
123
124   my $error = 
125     $self->ut_numbern('machinenum')
126     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
127     || $self->ut_domain('machine')
128     || $self->ut_enum('disabled', [ '', 'Y' ])
129   ;
130   return $error if $error;
131
132   $self->SUPER::check;
133 }
134
135 =item svc_export_machine
136
137 =cut
138
139 sub svc_export_machine {
140   my $self = shift;
141   qsearch( 'svc_export_machine', { 'machinenum' => $self->machinenum } );
142 }
143
144 =back
145
146 =head1 BUGS
147
148 =head1 SEE ALSO
149
150 L<FS::part_export>, L<FS::Record>
151
152 =cut
153
154 1;
155