1 package FS::phone_device;
4 use base qw( FS::Record );
5 use Scalar::Util qw( blessed );
6 use FS::Record qw( dbh qsearchs ); # qsearch );
12 FS::phone_device - Object methods for phone_device records
18 $record = new FS::phone_device \%hash;
19 $record = new FS::phone_device { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::phone_device object represents a specific customer phone device, such as
32 a SIP phone or ATA. FS::phone_device inherits from FS::Record. The following
33 fields are currently supported:
62 Creates a new record. To add the record to the database, see L<"insert">.
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to. You can ask the object for a copy with the I<hash> method.
69 # the new method can be inherited from FS::Record, if a table method is defined
71 sub table { 'phone_device'; }
75 Adds this record to the database. If there is an error, returns the error,
76 otherwise returns false.
83 local $SIG{HUP} = 'IGNORE';
84 local $SIG{INT} = 'IGNORE';
85 local $SIG{QUIT} = 'IGNORE';
86 local $SIG{TERM} = 'IGNORE';
87 local $SIG{TSTP} = 'IGNORE';
88 local $SIG{PIPE} = 'IGNORE';
90 my $oldAutoCommit = $FS::UID::AutoCommit;
91 local $FS::UID::AutoCommit = 0;
94 my $error = $self->SUPER::insert;
96 $dbh->rollback if $oldAutoCommit;
100 $self->export('device_insert');
102 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
109 Delete this record from the database.
116 local $SIG{HUP} = 'IGNORE';
117 local $SIG{INT} = 'IGNORE';
118 local $SIG{QUIT} = 'IGNORE';
119 local $SIG{TERM} = 'IGNORE';
120 local $SIG{TSTP} = 'IGNORE';
121 local $SIG{PIPE} = 'IGNORE';
123 my $oldAutoCommit = $FS::UID::AutoCommit;
124 local $FS::UID::AutoCommit = 0;
127 $self->export('device_delete');
129 my $error = $self->SUPER::delete;
131 $dbh->rollback if $oldAutoCommit;
135 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
139 =item replace OLD_RECORD
141 Replaces the OLD_RECORD with this one in the database. If there is an error,
142 returns the error, otherwise returns false.
149 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
153 local $SIG{HUP} = 'IGNORE';
154 local $SIG{INT} = 'IGNORE';
155 local $SIG{QUIT} = 'IGNORE';
156 local $SIG{TERM} = 'IGNORE';
157 local $SIG{TSTP} = 'IGNORE';
158 local $SIG{PIPE} = 'IGNORE';
160 my $oldAutoCommit = $FS::UID::AutoCommit;
161 local $FS::UID::AutoCommit = 0;
164 my $error = $new->SUPER::replace($old);
166 $dbh->rollback if $oldAutoCommit;
170 $new->export('device_replace', $old);
172 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
178 Checks all fields to make sure this is a valid record. If there is
179 an error, returns the error, otherwise returns false. Called by the insert
184 # the check method should currently be supplied - FS::Record contains some
185 # data checking routines
190 my $mac = $self->mac_addr;
193 $self->mac_addr($mac);
196 $self->ut_numbern('devicenum')
197 || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
198 || $self->ut_foreign_key('svcnum', 'svc_phone', 'svcnum' ) #cust_svc?
199 || $self->ut_hexn('mac_addr')
201 return $error if $error;
208 Returns the device type record (see L<FS::part_device>) associated with this
215 qsearchs( 'part_device', { 'devicepart' => $self->devicepart } );
220 Returns the phone number (see L<FS::svc_phone>) associated with this customer
227 qsearchs( 'svc_phone', { 'svcnum' => $self->svcnum } );
230 =item export HOOK [ EXPORT_ARGS ]
232 Runs the provided export hook (i.e. "device_insert") for this service.
237 my( $self, $method ) = ( shift, shift );
239 local $SIG{HUP} = 'IGNORE';
240 local $SIG{INT} = 'IGNORE';
241 local $SIG{QUIT} = 'IGNORE';
242 local $SIG{TERM} = 'IGNORE';
243 local $SIG{TSTP} = 'IGNORE';
244 local $SIG{PIPE} = 'IGNORE';
246 my $oldAutoCommit = $FS::UID::AutoCommit;
247 local $FS::UID::AutoCommit = 0;
250 my $svc_phone = $self->svc_phone;
251 my $error = $svc_phone->export($method, $self, @_); #call device export
252 if ( $error ) { #netsapiens at least
253 $dbh->rollback if $oldAutoCommit;
254 return "error exporting $method event to svc_phone ". $svc_phone->svcnum.
255 " (transaction rolled back): $error";
258 $method = "export_$method" unless $method =~ /^export_/;
260 foreach my $part_export ( $self->part_device->part_export ) {
261 next unless $part_export->can($method);
262 my $error = $part_export->$method($svc_phone, $self, @_);
264 $dbh->rollback if $oldAutoCommit;
265 return "error exporting $method event to ". $part_export->exporttype.
266 " (transaction rolled back): $error";
270 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
277 Returns a list of html elements associated with this device's exports.
284 $self->export('export_device_links', $return);
294 L<FS::Record>, schema.html from the base documentation.