From 7e0eb79c2efc03e27a4e8207b92526a2ac436602 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 12 Aug 2014 16:41:15 -0700 Subject: [PATCH] svc_cable unique serialnum and mac_addr, RT# --- FS/FS/Schema.pm | 2 +- FS/FS/svc_cable.pm | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 9e71af15c..1828cba8b 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -4488,7 +4488,7 @@ sub tables_hashref { 'mac_addr', 'varchar', 'NULL', 12, '', '', ], 'primary_key' => 'svcnum', - 'unique' => [], + 'unique' => [ ['serialnum'] , ['mac_addr'] ], 'index' => [], }, diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm index 0c0d684e0..944f781fd 100644 --- a/FS/FS/svc_cable.pm +++ b/FS/FS/svc_cable.pm @@ -56,7 +56,7 @@ points to. You can ask the object for a copy with the I 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. -- 2.11.0