diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-08-12 16:41:11 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-08-12 16:41:11 -0700 |
commit | 6f8edbafb0401dd2224d3698397bcb16ffad1580 (patch) | |
tree | 2e4dcefd3bec4c5ca746b5af7c7b47590dfb8413 | |
parent | e03f1de6578f009f306d92ec713b533e799330cd (diff) |
svc_cable unique serialnum and mac_addr, RT#
-rw-r--r-- | FS/FS/Schema.pm | 2 | ||||
-rw-r--r-- | 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 54c84f7..2aba2ea 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -6352,7 +6352,7 @@ sub tables_hashref { 'mac_addr', 'varchar', 'NULL', 12, '', '', ], 'primary_key' => 'svcnum', - 'unique' => [], + 'unique' => [ ['serialnum'] , ['mac_addr'] ], 'index' => [], 'foreign_keys' => [ { columns => [ 'svcnum' ], diff --git a/FS/FS/svc_cable.pm b/FS/FS/svc_cable.pm index 4dd4543..122d8c6 100644 --- a/FS/FS/svc_cable.pm +++ b/FS/FS/svc_cable.pm @@ -53,7 +53,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 ) = @_; @@ -168,6 +168,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. |