[freeside-commits] freeside/FS/FS Conf.pm, 1.393, 1.394 svc_Common.pm, 1.58, 1.59 svc_pbx.pm, 1.10, 1.11

Mark Wells mark at wavetail.420.am
Thu Oct 28 00:47:15 PDT 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv9212

Modified Files:
	Conf.pm svc_Common.pm svc_pbx.pm 
Log Message:
global duplicate checking on svc_pbx.id, RT#9967

Index: svc_Common.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_Common.pm,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -w -d -r1.58 -r1.59
--- svc_Common.pm	21 May 2010 00:09:40 -0000	1.58
+++ svc_Common.pm	28 Oct 2010 07:47:13 -0000	1.59
@@ -1013,6 +1013,42 @@
   shift;
 }
 
+=item find_duplicates MODE FIELDS...
+
+Method used by _check_duplicate routines to find services with duplicate 
+values in specified fields.  Set MODE to 'global' to search across all 
+services, or 'export' to limit to those that share one or more exports 
+with this service.  FIELDS is a list of field names; only services 
+matching in all fields will be returned.  Empty fields will be skipped.
+
+=cut
+
+sub find_duplicates {
+  my $self = shift;
+  my $mode = shift;
+  my @fields = @_;
+
+  my %search = map { $_ => $self->getfield($_) } 
+               grep { length($self->getfield($_)) } @fields;
+  return () if !%search;
+  my @dup = grep { ! $self->svcnum or $_->svcnum != $self->svcnum }
+            qsearch( $self->table, \%search );
+  return () if !@dup;
+  return @dup if $mode eq 'global';
+  die "incorrect find_duplicates mode '$mode'" if $mode ne 'export';
+
+  my $exports = FS::part_export::export_info($self->table);
+  my %conflict_svcparts;
+  my $part_svc = $self->part_svc;
+  foreach my $part_export ( $part_svc->part_export ) {
+    %conflict_svcparts = map { $_->svcpart => 1 } $part_export->export_svc;
+  }
+  return grep { $conflict_svcparts{$_->cust_svc->svcpart} } @dup;
+}
+
+
+
+
 =back
 
 =head1 BUGS

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.393
retrieving revision 1.394
diff -u -w -d -r1.393 -r1.394
--- Conf.pm	25 Oct 2010 22:22:41 -0000	1.393
+++ Conf.pm	28 Oct 2010 07:47:13 -0000	1.394
@@ -2305,7 +2305,15 @@
   {
     'key'         => 'global_unique-pbx_title',
     'section'     => '',
-    'description' => 'Global phone number uniqueness control: enabled (usual setting - svc_pbx.title must be unique), or disabled turns off duplicate checking for this field.',
+    'description' => 'Global phone number uniqueness control: none (check uniqueness per exports), enabled (check across all services), or disabled (no duplicate checking).',
+    'type'        => 'select',
+    'select_enum' => [ 'enabled', 'disabled' ],
+  },
+
+  {
+    'key'         => 'global_unique-pbx_id',
+    'section'     => '',
+    'description' => 'Global PBX id uniqueness control: none (check uniqueness per exports), enabled (check across all services), or disabled (no duplicate checking).',
     'type'        => 'select',
     'select_enum' => [ 'enabled', 'disabled' ],
   },

Index: svc_pbx.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_pbx.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -d -r1.10 -r1.11
--- svc_pbx.pm	4 Oct 2010 18:46:39 -0000	1.10
+++ svc_pbx.pm	28 Oct 2010 07:47:13 -0000	1.11
@@ -253,22 +253,27 @@
   $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;
 
   my $conf = new FS::Conf;
-  return '' if $conf->config('global_unique-pbx_title') eq 'disabled';
 
   $self->lock_table;
 
-  if ( qsearchs( 'svc_pbx', { 'title' => $self->title } ) ) {
-    return "Name in use";
-  } else {
-    return '';
+  foreach my $field ('title', 'id') {
+    my $global_unique = $conf->config("global_unique-pbx_$field");
+    # can be 'disabled', 'enabled', or empty.
+    # if empty, check per exports; if not empty or disabled, check 
+    # globally.
+    next if $global_unique eq 'disabled';
+    my @dup = $self->find_duplicates(
+      ($global_unique ? 'global' : 'export') , $field
+    );
+    next if !@dup;
+    return "duplicate $field '".$self->getfield($field).
+           "': conflicts with svcnum ".$dup[0]->svcnum;
   }
+  return '';
 }
 
 =item get_cdrs



More information about the freeside-commits mailing list