[freeside-commits] branch master updated. 25386efd0e3f725d6cef005eba729840d3b4b3cb

Ivan Kohler ivan at freeside.biz
Sun Oct 28 15:04:32 PDT 2018


The branch, master has been updated
       via  25386efd0e3f725d6cef005eba729840d3b4b3cb (commit)
      from  e63d638c6b7b2c9adedb43e0bd9afe4260714837 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 25386efd0e3f725d6cef005eba729840d3b4b3cb
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Oct 28 15:04:28 2018 -0700

    svc_hardware uniqueness checks, RT#81534

diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 2a7a9d177..6ea060963 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -4168,7 +4168,7 @@ sub tables_hashref {
         'note',     'text',    'NULL',      '', '', '',
       ],
       'primary_key'  => 'svcnum',
-      'unique'       => [],
+      'unique'       => [ ['typenum', 'serial'], ['ip_addr'], ['hw_addr'] ],
       'index'        => [],
       'foreign_keys' => [
                           { columns    => [ 'svcnum' ],
@@ -6902,7 +6902,7 @@ sub tables_hashref {
         'mac_addr',  'varchar', 'NULL',      12, '', '', 
       ],
       'primary_key'  => 'svcnum',
-      'unique'       => [ ['serialnum'] , ['mac_addr'] ],
+      'unique'       => [ ['modelnum', 'serialnum'] , ['mac_addr'] ],
       'index'        => [],
       'foreign_keys' => [
                           { columns    => [ 'svcnum' ],
diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm
index 5e3f180b8..daaf680c5 100644
--- a/FS/FS/svc_cable.pm
+++ b/FS/FS/svc_cable.pm
@@ -209,7 +209,7 @@ sub _check_duplicate {
 
   if ( $self->serialnum ) {
     my @dup_serial;
-    @dup_serial = $self->find_duplicates('global', 'serialnum');
+    @dup_serial = $self->find_duplicates('global', 'modelnum', 'serialnum');
     if ( @dup_serial ) {
       return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
     }
diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm
index 019a5646c..69da0c7a4 100644
--- a/FS/FS/svc_hardware.pm
+++ b/FS/FS/svc_hardware.pm
@@ -214,6 +214,40 @@ sub check {
   $self->SUPER::check;
 }
 
+#false laziness w/svc_cable
+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.
+
+  if ( $self->hw_addr ) {
+    my @dup_mac;
+    @dup_mac = $self->find_duplicates('global', 'hw_addr');
+    if ( @dup_mac ) {
+      return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")";
+    }
+  }
+
+  if ( $self->ip_addr ) {
+    my @dup_ip;
+    @dup_ip = $self->find_duplicates('global', 'ip_addr');
+    if ( @dup_ip ) {
+      return "IP address in use (svcnum ".$dup_ip[0]->svcnum.")";
+    }
+  }
+
+  if ( $self->serialnum ) {
+    my @dup_serial;
+    @dup_serial = $self->find_duplicates('global', 'typenum', 'serialnum');
+    if ( @dup_serial ) {
+      return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")";
+    }
+  }
+
+  '';
+}
+
 =item hardware_type
 
 Returns the L<FS::hardware_type> object associated with this installation.

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Schema.pm       |  4 ++--
 FS/FS/svc_cable.pm    |  2 +-
 FS/FS/svc_hardware.pm | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)




More information about the freeside-commits mailing list