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;
95 $error ||= $self->export('device_insert');
97 $dbh->rollback if $oldAutoCommit;
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;
128 my $error = $self->export('device_delete') || $self->SUPER::delete;
130 $dbh->rollback if $oldAutoCommit;
134 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
138 =item replace OLD_RECORD
140 Replaces the OLD_RECORD with this one in the database. If there is an error,
141 returns the error, otherwise returns false.
148 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
152 local $SIG{HUP} = 'IGNORE';
153 local $SIG{INT} = 'IGNORE';
154 local $SIG{QUIT} = 'IGNORE';
155 local $SIG{TERM} = 'IGNORE';
156 local $SIG{TSTP} = 'IGNORE';
157 local $SIG{PIPE} = 'IGNORE';
159 my $oldAutoCommit = $FS::UID::AutoCommit;
160 local $FS::UID::AutoCommit = 0;
163 my $error = $new->SUPER::replace($old)
164 || $new->export('device_replace', $old);
166 $dbh->rollback if $oldAutoCommit;
171 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
177 Checks all fields to make sure this is a valid record. If there is
178 an error, returns the error, otherwise returns false. Called by the insert
183 # the check method should currently be supplied - FS::Record contains some
184 # data checking routines
189 my $mac = $self->mac_addr;
192 $self->mac_addr($mac);
195 $self->ut_numbern('devicenum')
196 || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
197 || $self->ut_foreign_key('svcnum', 'svc_phone', 'svcnum' ) #cust_svc?
198 || $self->ut_hexn('mac_addr')
200 return $error if $error;
207 Returns the device type record (see L<FS::part_device>) associated with this
214 qsearchs( 'part_device', { 'devicepart' => $self->devicepart } );
219 Returns the phone number (see L<FS::svc_phone>) associated with this customer
226 qsearchs( 'svc_phone', { 'svcnum' => $self->svcnum } );
229 =item export HOOK [ EXPORT_ARGS ]
231 Runs the provided export hook (i.e. "device_insert") for this service.
236 my( $self, $method ) = ( shift, shift );
238 local $SIG{HUP} = 'IGNORE';
239 local $SIG{INT} = 'IGNORE';
240 local $SIG{QUIT} = 'IGNORE';
241 local $SIG{TERM} = 'IGNORE';
242 local $SIG{TSTP} = 'IGNORE';
243 local $SIG{PIPE} = 'IGNORE';
245 my $oldAutoCommit = $FS::UID::AutoCommit;
246 local $FS::UID::AutoCommit = 0;
249 my $svc_phone = $self->svc_phone;
250 my $error = $svc_phone->export($method, $self, @_); #call device export
251 if ( $error ) { #netsapiens at least
252 $dbh->rollback if $oldAutoCommit;
253 return "error exporting $method event to svc_phone ". $svc_phone->svcnum.
254 " (transaction rolled back): $error";
257 $method = "export_$method" unless $method =~ /^export_/;
259 foreach my $part_export ( $self->part_device->part_export ) {
260 next unless $part_export->can($method);
261 my $error = $part_export->$method($svc_phone, $self, @_);
263 $dbh->rollback if $oldAutoCommit;
264 return "error exporting $method event to ". $part_export->exporttype.
265 " (transaction rolled back): $error";
269 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
276 Returns a list of html elements associated with this device's exports.
283 $self->export('export_device_links', $return);
293 L<FS::Record>, schema.html from the base documentation.