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;
94 $dbh->rollback if $oldAutoCommit;
98 $self->export('device_insert');
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;
125 $self->export('device_delete');
127 my $error = $self->SUPER::delete;
129 $dbh->rollback if $oldAutoCommit;
133 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
137 =item replace OLD_RECORD
139 Replaces the OLD_RECORD with this one in the database. If there is an error,
140 returns the error, otherwise returns false.
147 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
151 local $SIG{HUP} = 'IGNORE';
152 local $SIG{INT} = 'IGNORE';
153 local $SIG{QUIT} = 'IGNORE';
154 local $SIG{TERM} = 'IGNORE';
155 local $SIG{TSTP} = 'IGNORE';
156 local $SIG{PIPE} = 'IGNORE';
158 my $oldAutoCommit = $FS::UID::AutoCommit;
159 local $FS::UID::AutoCommit = 0;
162 my $error = $new->SUPER::replace($old);
164 $dbh->rollback if $oldAutoCommit;
168 $new->export('device_replace', $old);
170 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
176 Checks all fields to make sure this is a valid record. If there is
177 an error, returns the error, otherwise returns false. Called by the insert
182 # the check method should currently be supplied - FS::Record contains some
183 # data checking routines
188 my $mac = $self->mac_addr;
191 $self->mac_addr($mac);
194 $self->ut_numbern('devicenum')
195 || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
196 || $self->ut_foreign_key('svcnum', 'svc_phone', 'svcnum' ) #cust_svc?
197 || $self->ut_hexn('mac_addr')
199 return $error if $error;
206 Returns the device type record (see L<FS::part_device>) associated with this
211 Returns the phone number (see L<FS::svc_phone>) associated with this customer
214 =item export HOOK [ EXPORT_ARGS ]
216 Runs the provided export hook (i.e. "device_insert") for this service.
221 my( $self, $method ) = ( shift, shift );
223 local $SIG{HUP} = 'IGNORE';
224 local $SIG{INT} = 'IGNORE';
225 local $SIG{QUIT} = 'IGNORE';
226 local $SIG{TERM} = 'IGNORE';
227 local $SIG{TSTP} = 'IGNORE';
228 local $SIG{PIPE} = 'IGNORE';
230 my $oldAutoCommit = $FS::UID::AutoCommit;
231 local $FS::UID::AutoCommit = 0;
234 my $svc_phone = $self->svc_phone;
235 my $error = $svc_phone->export($method, $self, @_); #call device export
236 if ( $error ) { #netsapiens at least
237 $dbh->rollback if $oldAutoCommit;
238 return "error exporting $method event to svc_phone ". $svc_phone->svcnum.
239 " (transaction rolled back): $error";
242 $method = "export_$method" unless $method =~ /^export_/;
244 foreach my $part_export ( $self->part_device->part_export ) {
245 next unless $part_export->can($method);
246 my $error = $part_export->$method($svc_phone, $self, @_);
248 $dbh->rollback if $oldAutoCommit;
249 return "error exporting $method event to ". $part_export->exporttype.
250 " (transaction rolled back): $error";
254 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
261 Returns a list of html elements associated with this device's exports.
268 $self->export('export_device_links', $return);
278 L<FS::Record>, schema.html from the base documentation.