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->svc_phone->export('device_insert', $self); #call device export
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->svc_phone->export('device_delete', $self); #call device export
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->svc_phone->export('device_replace', $new, $old); #call device export
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 } );
236 L<FS::Record>, schema.html from the base documentation.