1 package FS::phone_device;
2 use base qw( FS::MAC_Mixin FS::Record );
5 use Scalar::Util qw( blessed );
6 use FS::Record qw( dbh ); # qsearch qsearchs dbh );
10 FS::phone_device - Object methods for phone_device records
16 $record = new FS::phone_device \%hash;
17 $record = new FS::phone_device { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::phone_device object represents a specific customer phone device, such as
30 a SIP phone or ATA. FS::phone_device inherits from FS::Record. The following
31 fields are currently supported:
60 Creates a new record. To add the record to the database, see L<"insert">.
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to. You can ask the object for a copy with the I<hash> method.
67 # the new method can be inherited from FS::Record, if a table method is defined
69 sub table { 'phone_device'; }
73 Adds this record to the database. If there is an error, returns the error,
74 otherwise returns false.
81 local $SIG{HUP} = 'IGNORE';
82 local $SIG{INT} = 'IGNORE';
83 local $SIG{QUIT} = 'IGNORE';
84 local $SIG{TERM} = 'IGNORE';
85 local $SIG{TSTP} = 'IGNORE';
86 local $SIG{PIPE} = 'IGNORE';
88 my $oldAutoCommit = $FS::UID::AutoCommit;
89 local $FS::UID::AutoCommit = 0;
92 my $error = $self->SUPER::insert;
93 $error ||= $self->export('device_insert');
95 $dbh->rollback if $oldAutoCommit;
100 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
107 Delete this record from the database.
114 local $SIG{HUP} = 'IGNORE';
115 local $SIG{INT} = 'IGNORE';
116 local $SIG{QUIT} = 'IGNORE';
117 local $SIG{TERM} = 'IGNORE';
118 local $SIG{TSTP} = 'IGNORE';
119 local $SIG{PIPE} = 'IGNORE';
121 my $oldAutoCommit = $FS::UID::AutoCommit;
122 local $FS::UID::AutoCommit = 0;
126 my $error = $self->export('device_delete') || $self->SUPER::delete;
128 $dbh->rollback if $oldAutoCommit;
132 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
136 =item replace OLD_RECORD
138 Replaces the OLD_RECORD with this one in the database. If there is an error,
139 returns the error, otherwise returns false.
146 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
150 local $SIG{HUP} = 'IGNORE';
151 local $SIG{INT} = 'IGNORE';
152 local $SIG{QUIT} = 'IGNORE';
153 local $SIG{TERM} = 'IGNORE';
154 local $SIG{TSTP} = 'IGNORE';
155 local $SIG{PIPE} = 'IGNORE';
157 my $oldAutoCommit = $FS::UID::AutoCommit;
158 local $FS::UID::AutoCommit = 0;
161 my $error = $new->SUPER::replace($old)
162 || $new->export('device_replace', $old);
164 $dbh->rollback if $oldAutoCommit;
169 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
175 Checks all fields to make sure this is a valid record. If there is
176 an error, returns the error, otherwise returns false. Called by the insert
181 # the check method should currently be supplied - FS::Record contains some
182 # data checking routines
187 my $mac = $self->mac_addr;
190 $self->mac_addr($mac);
193 $self->ut_numbern('devicenum')
194 || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
195 || $self->ut_foreign_key('svcnum', 'svc_phone', 'svcnum' ) #cust_svc?
196 || $self->ut_hexn('mac_addr')
198 return $error if $error;
205 Returns the device type record (see L<FS::part_device>) associated with this
210 Returns the phone number (see L<FS::svc_phone>) associated with this customer
213 =item export HOOK [ EXPORT_ARGS ]
215 Runs the provided export hook (i.e. "device_insert") for this service.
220 my( $self, $method ) = ( shift, shift );
222 local $SIG{HUP} = 'IGNORE';
223 local $SIG{INT} = 'IGNORE';
224 local $SIG{QUIT} = 'IGNORE';
225 local $SIG{TERM} = 'IGNORE';
226 local $SIG{TSTP} = 'IGNORE';
227 local $SIG{PIPE} = 'IGNORE';
229 my $oldAutoCommit = $FS::UID::AutoCommit;
230 local $FS::UID::AutoCommit = 0;
233 my $svc_phone = $self->svc_phone;
234 my $error = $svc_phone->export($method, $self, @_); #call device export
235 if ( $error ) { #netsapiens at least
236 $dbh->rollback if $oldAutoCommit;
237 return "error exporting $method event to svc_phone ". $svc_phone->svcnum.
238 " (transaction rolled back): $error";
241 $method = "export_$method" unless $method =~ /^export_/;
243 foreach my $part_export ( $self->part_device->part_export ) {
244 next unless $part_export->can($method);
245 my $error = $part_export->$method($svc_phone, $self, @_);
247 $dbh->rollback if $oldAutoCommit;
248 return "error exporting $method event to ". $part_export->exporttype.
249 " (transaction rolled back): $error";
253 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
260 Returns a list of html elements associated with this device's exports.
267 $self->export('export_device_links', $return);
277 L<FS::Record>, schema.html from the base documentation.