4 use base qw( FS::svc_External_Common );
5 use FS::Record qw( qsearch qsearchs dbh );
12 FS::svc_pbx - Object methods for svc_pbx records
18 $record = new FS::svc_pbx \%hash;
19 $record = new FS::svc_pbx { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
29 $error = $record->suspend;
31 $error = $record->unsuspend;
33 $error = $record->cancel;
37 An FS::svc_pbx object represents a PBX tenant. FS::svc_pbx inherits from
38 FS::svc_Common. The following fields are currently supported:
44 Primary key (assigned automatcially for new accounts)
48 (Unique?) number of external record
56 Maximum number of extensions
58 =item max_simultaneous
60 Maximum number of simultaneous users
70 Creates a new PBX tenant. To add the PBX tenant to the database, see
73 Note that this stores the hash reference, not a distinct copy of the hash it
74 points to. You can ask the object for a copy with the I<hash> method.
78 sub table { 'svc_pbx'; }
83 'name_plural' => 'PBXs', #optional,
84 'longname_plural' => 'PBXs', #optional
85 'sorts' => 'svcnum', # optional sort field (or arrayref of sort fields, main first)
86 'display_weight' => 70,
87 'cancel_weight' => 90,
91 'max_extensions' => 'Maximum number of User Extensions',
92 'max_simultaneous' => 'Maximum number of simultaneous users',
93 # 'field' => 'Description',
94 # 'another_field' => {
95 # 'label' => 'Description',
96 # 'def_label' => 'Description for service definitions',
98 # 'disable_default' => 1, #disable switches
99 # 'disable_fixed' => 1, #
100 # 'disable_inventory' => 1, #
103 # 'label' => 'Description',
104 # 'def_label' => 'Description for service defs',
105 # 'type' => 'select',
106 # 'select_table' => 'foreign_table',
107 # 'select_key' => 'key_field_in_table',
108 # 'select_label' => 'label_field_in_table',
115 =item search_sql STRING
117 Class method which returns an SQL fragment to search for the given string.
122 #or something more complicated if necessary
124 # my($class, $string) = @_;
125 # $class->search_sql_field('title', $string);
130 Returns the title field for this PBX tenant.
141 Adds this record to the database. If there is an error, returns the error,
142 otherwise returns false.
144 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
145 defined. An FS::cust_svc record will be created and inserted.
153 $error = $self->SUPER::insert;
154 return $error if $error;
161 Delete this record from the database.
168 local $SIG{HUP} = 'IGNORE';
169 local $SIG{INT} = 'IGNORE';
170 local $SIG{QUIT} = 'IGNORE';
171 local $SIG{TERM} = 'IGNORE';
172 local $SIG{TSTP} = 'IGNORE';
173 local $SIG{PIPE} = 'IGNORE';
175 my $oldAutoCommit = $FS::UID::AutoCommit;
176 local $FS::UID::AutoCommit = 0;
179 foreach my $svc_phone (qsearch('svc_phone', { 'pbxsvc' => $self->svcnum } )) {
180 $svc_phone->pbxsvc('');
181 my $error = $svc_phone->replace;
183 $dbh->rollback if $oldAutoCommit;
188 foreach my $svc_acct (qsearch('svc_acct', { 'pbxsvc' => $self->svcnum } )) {
189 my $error = $svc_acct->delete;
191 $dbh->rollback if $oldAutoCommit;
196 my $error = $self->SUPER::delete;
198 $dbh->rollback if $oldAutoCommit;
202 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
207 =item replace OLD_RECORD
209 Replaces the OLD_RECORD with this one in the database. If there is an error,
210 returns the error, otherwise returns false.
215 # my ( $new, $old ) = ( shift, shift );
218 # $error = $new->SUPER::replace($old);
219 # return $error if $error;
226 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
230 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
234 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
238 Checks all fields to make sure this is a valid PBX tenant. If there is
239 an error, returns the error, otherwise returns false. Called by the insert
247 my $x = $self->setfixed;
248 return $x unless ref($x);
255 #XXX this is a way-too simplistic implementation
256 # at the very least, title should be unique across exports that need that or
257 # controlled by a conf setting or something
258 sub _check_duplicate {
263 if ( qsearchs( 'svc_pbx', { 'title' => $self->title } ) ) {
264 return "Name in use";
276 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
277 L<FS::cust_pkg>, schema.html from the base documentation.