4 use base qw( FS::svc_External_Common );
5 use FS::Record qw( qsearch qsearchs dbh );
13 FS::svc_pbx - Object methods for svc_pbx records
19 $record = new FS::svc_pbx \%hash;
20 $record = new FS::svc_pbx { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
30 $error = $record->suspend;
32 $error = $record->unsuspend;
34 $error = $record->cancel;
38 An FS::svc_pbx object represents a PBX tenant. FS::svc_pbx inherits from
39 FS::svc_Common. The following fields are currently supported:
45 Primary key (assigned automatcially for new accounts)
49 (Unique?) number of external record
57 Maximum number of extensions
67 Creates a new PBX tenant. To add the PBX tenant to the database, see
70 Note that this stores the hash reference, not a distinct copy of the hash it
71 points to. You can ask the object for a copy with the I<hash> method.
75 sub table { 'svc_pbx'; }
80 'name_plural' => 'PBXs', #optional,
81 'longname_plural' => 'PBXs', #optional
82 'sorts' => 'svcnum', # optional sort field (or arrayref of sort fields, main first)
83 'display_weight' => 70,
84 'cancel_weight' => 90,
88 'max_extensions' => 'Maximum number of User Extensions',
89 # 'field' => 'Description',
90 # 'another_field' => {
91 # 'label' => 'Description',
92 # 'def_label' => 'Description for service definitions',
94 # 'disable_default' => 1, #disable switches
95 # 'disable_fixed' => 1, #
96 # 'disable_inventory' => 1, #
99 # 'label' => 'Description',
100 # 'def_label' => 'Description for service defs',
101 # 'type' => 'select',
102 # 'select_table' => 'foreign_table',
103 # 'select_key' => 'key_field_in_table',
104 # 'select_label' => 'label_field_in_table',
111 =item search_sql STRING
113 Class method which returns an SQL fragment to search for the given string.
118 #or something more complicated if necessary
120 # my($class, $string) = @_;
121 # $class->search_sql_field('title', $string);
126 Returns the title field for this PBX tenant.
137 Adds this record to the database. If there is an error, returns the error,
138 otherwise returns false.
140 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
141 defined. An FS::cust_svc record will be created and inserted.
149 $error = $self->SUPER::insert;
150 return $error if $error;
157 Delete this record from the database.
164 local $SIG{HUP} = 'IGNORE';
165 local $SIG{INT} = 'IGNORE';
166 local $SIG{QUIT} = 'IGNORE';
167 local $SIG{TERM} = 'IGNORE';
168 local $SIG{TSTP} = 'IGNORE';
169 local $SIG{PIPE} = 'IGNORE';
171 my $oldAutoCommit = $FS::UID::AutoCommit;
172 local $FS::UID::AutoCommit = 0;
175 foreach my $svc_phone (qsearch('svc_phone', { 'pbxsvc' => $self->svcnum } )) {
176 $svc_phone->pbxsvc('');
177 my $error = $svc_phone->replace;
179 $dbh->rollback if $oldAutoCommit;
184 foreach my $svc_acct (qsearch('svc_acct', { 'pbxsvc' => $self->svcnum } )) {
185 my $error = $svc_acct->delete;
187 $dbh->rollback if $oldAutoCommit;
192 my $error = $self->SUPER::delete;
194 $dbh->rollback if $oldAutoCommit;
198 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
203 =item replace OLD_RECORD
205 Replaces the OLD_RECORD with this one in the database. If there is an error,
206 returns the error, otherwise returns false.
211 my ( $new, $old ) = ( shift, shift );
214 $error = $new->SUPER::replace($old);
215 return $error if $error;
222 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
226 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
230 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
234 Checks all fields to make sure this is a valid PBX tenant. If there is
235 an error, returns the error, otherwise returns false. Called by the insert
243 my $x = $self->setfixed;
244 return $x unless ref($x);
251 #XXX this is a way-too simplistic implementation
252 # at the very least, title should be unique across exports that need that or
253 # controlled by a conf setting or something
254 sub _check_duplicate {
257 my $conf = new FS::Conf;
258 return '' if $conf->config('global_unique-pbx_title') eq 'disabled';
262 if ( qsearchs( 'svc_pbx', { 'title' => $self->title } ) ) {
263 return "Name in use";
275 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
276 L<FS::cust_pkg>, schema.html from the base documentation.