svc_cable unique serialnum and mac_addr, RT#
authorIvan Kohler <ivan@freeside.biz>
Tue, 12 Aug 2014 23:41:15 +0000 (16:41 -0700)
committerIvan Kohler <ivan@freeside.biz>
Tue, 12 Aug 2014 23:41:15 +0000 (16:41 -0700)
FS/FS/Schema.pm
FS/FS/svc_cable.pm

index 9e71af1..1828cba 100644 (file)
@@ -4488,7 +4488,7 @@ sub tables_hashref {
         'mac_addr',  'varchar', 'NULL',      12, '', '', 
       ],
       'primary_key' => 'svcnum',
-      'unique' => [],
+      'unique'       => [ ['serialnum'] , ['mac_addr'] ],
       'index'  => [],
     },
 
index 0c0d684..944f781 100644 (file)
@@ -56,7 +56,7 @@ points to.  You can ask the object for a copy with the I<hash> method.
 
 sub table { 'svc_cable'; }
 
-sub table_dupcheck_fields { ( 'mac_addr' ); }
+sub table_dupcheck_fields { ( 'serialnum', 'mac_addr' ); }
 
 sub search_sql {
   my( $class, $string ) = @_;
@@ -171,6 +171,27 @@ sub check {
   $self->SUPER::check;
 }
 
+sub _check_duplicate {
+  my $self = shift;
+
+  # Not reliable checks because the table isn't locked, but that's why we have
+  # unique indices.  These are just to give friendlier error messages.
+
+  my @dup_mac;
+  @dup_mac = $self->find_duplicates('global', 'mac_addr');
+  if ( @dup_mac ) {
+    return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
+  }
+
+  my @dup_serial;
+  @dup_serial = $self->find_duplicates('global', 'serialnum');
+  if ( @dup_serial ) {
+    return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
+  }
+
+  '';
+}
+
 =item cable_provider
 
 Returns the cable_provider object for this record.