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
66 Creates a new PBX tenant. To add the PBX tenant to the database, see
69 Note that this stores the hash reference, not a distinct copy of the hash it
70 points to. You can ask the object for a copy with the I<hash> method.
74 sub table { 'svc_pbx'; }
79 'name_plural' => 'PBXs', #optional,
80 'longname_plural' => 'PBXs', #optional
81 'sorts' => 'svcnum', # optional sort field (or arrayref of sort fields, main first)
82 'display_weight' => 70,
83 'cancel_weight' => 90,
87 'max_extensions' => 'Maximum number of User Extensions',
88 # 'field' => 'Description',
89 # 'another_field' => {
90 # 'label' => 'Description',
91 # 'def_label' => 'Description for service definitions',
93 # 'disable_default' => 1, #disable switches
94 # 'disable_fixed' => 1, #
95 # 'disable_inventory' => 1, #
98 # 'label' => 'Description',
99 # 'def_label' => 'Description for service defs',
100 # 'type' => 'select',
101 # 'select_table' => 'foreign_table',
102 # 'select_key' => 'key_field_in_table',
103 # 'select_label' => 'label_field_in_table',
110 =item search_sql STRING
112 Class method which returns an SQL fragment to search for the given string.
117 #or something more complicated if necessary
119 # my($class, $string) = @_;
120 # $class->search_sql_field('title', $string);
125 Returns the title field for this PBX tenant.
136 Adds this record to the database. If there is an error, returns the error,
137 otherwise returns false.
139 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
140 defined. An FS::cust_svc record will be created and inserted.
148 $error = $self->SUPER::insert;
149 return $error if $error;
156 Delete this record from the database.
163 local $SIG{HUP} = 'IGNORE';
164 local $SIG{INT} = 'IGNORE';
165 local $SIG{QUIT} = 'IGNORE';
166 local $SIG{TERM} = 'IGNORE';
167 local $SIG{TSTP} = 'IGNORE';
168 local $SIG{PIPE} = 'IGNORE';
170 my $oldAutoCommit = $FS::UID::AutoCommit;
171 local $FS::UID::AutoCommit = 0;
174 foreach my $svc_phone (qsearch('svc_phone', { 'pbxsvc' => $self->svcnum } )) {
175 $svc_phone->pbxsvc('');
176 my $error = $svc_phone->replace;
178 $dbh->rollback if $oldAutoCommit;
183 foreach my $svc_acct (qsearch('svc_acct', { 'pbxsvc' => $self->svcnum } )) {
184 my $error = $svc_acct->delete;
186 $dbh->rollback if $oldAutoCommit;
191 my $error = $self->SUPER::delete;
193 $dbh->rollback if $oldAutoCommit;
197 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
202 =item replace OLD_RECORD
204 Replaces the OLD_RECORD with this one in the database. If there is an error,
205 returns the error, otherwise returns false.
210 my ( $new, $old ) = ( shift, shift );
213 $error = $new->SUPER::replace($old);
214 return $error if $error;
221 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
225 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
229 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
233 Checks all fields to make sure this is a valid PBX tenant. If there is
234 an error, returns the error, otherwise returns false. Called by the insert
242 my $x = $self->setfixed;
243 return $x unless ref($x);
250 #XXX this is a way-too simplistic implementation
251 # at the very least, title should be unique across exports that need that or
252 # controlled by a conf setting or something
253 sub _check_duplicate {
258 if ( qsearchs( 'svc_pbx', { 'title' => $self->title } ) ) {
259 return "Name in use";
271 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
272 L<FS::cust_pkg>, schema.html from the base documentation.