maestro cust status as reqeusted, RT#8712
[freeside.git] / FS / FS / svc_pbx.pm
index 4ba8e66..21aaa4e 100644 (file)
@@ -2,8 +2,10 @@ package FS::svc_pbx;
 
 use strict;
 use base qw( FS::svc_External_Common );
-#use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::cust_svc;
+use FS::svc_phone;
+use FS::svc_acct;
 
 =head1 NAME
 
@@ -53,6 +55,10 @@ PBX name
 
 Maximum number of extensions
 
+=item max_simultaneous
+
+Maximum number of simultaneous users
+
 =back
 
 =head1 METHODS
@@ -80,9 +86,10 @@ sub table_info {
     'display_weight' => 70,
     'cancel_weight'  => 90,
     'fields' => {
-      'id'    => 'Thirdlane ID',
+      'id'    => 'ID',
       'title' => 'Name',
       'max_extensions' => 'Maximum number of User Extensions',
+      'max_simultaneous' => 'Maximum number of simultaneous users',
 #      'field'         => 'Description',
 #      'another_field' => { 
 #                           'label'     => 'Description',
@@ -157,11 +164,42 @@ Delete this record from the database.
 
 sub delete {
   my $self = shift;
-  my $error;
-
-  $error = $self->SUPER::delete;
-  return $error if $error;
 
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  foreach my $svc_phone (qsearch('svc_phone', { 'pbxsvc' => $self->svcnum } )) {
+    $svc_phone->pbxsvc('');
+    my $error = $svc_phone->replace;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  foreach my $svc_acct  (qsearch('svc_acct',  { 'pbxsvc' => $self->svcnum } )) {
+    my $error = $svc_acct->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  my $error = $self->SUPER::delete;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
 }
 
@@ -173,15 +211,15 @@ returns the error, otherwise returns false.
 
 =cut
 
-sub replace {
-  my ( $new, $old ) = ( shift, shift );
-  my $error;
-
-  $error = $new->SUPER::replace($old);
-  return $error if $error;
-
-  '';
-}
+#sub replace {
+#  my ( $new, $old ) = ( shift, shift );
+#  my $error;
+#
+#  $error = $new->SUPER::replace($old);
+#  return $error if $error;
+#
+#  '';
+#}
 
 =item suspend
 
@@ -214,6 +252,21 @@ sub check {
   $self->SUPER::check;
 }
 
+#XXX this is a way-too simplistic implementation
+# at the very least, title should be unique across exports that need that or
+# controlled by a conf setting or something
+sub _check_duplicate {
+  my $self = shift;
+
+  $self->lock_table;
+
+  if ( qsearchs( 'svc_pbx', { 'title' => $self->title } ) ) {
+    return "Name in use";
+  } else {
+    return '';
+  }
+}
+
 =back
 
 =head1 BUGS