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