From fdcc8c4426d96d1389f9282ff78054a5b8aa930c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 4 Aug 2015 14:43:20 +0100 Subject: [PATCH] Bug 10363: FIX prevent duplicate --- Koha/AuthorisedValues.pm | 6 +----- admin/authorised_values.pl | 12 +++++++++++- .../intranet-tmpl/prog/en/modules/admin/authorised_values.tt | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm index f81eea7..e690d8c 100644 --- a/Koha/AuthorisedValues.pm +++ b/Koha/AuthorisedValues.pm @@ -59,11 +59,7 @@ sub search { } : {}; my $join = $branchcode ? { join => 'authorised_values_branches' } : {}; - my $rs = $self->_resultset() - ->search( { %$params, %$or, }, $join ); - - my $class = ref($self); - return wantarray ? $self->_wrap( $rs->all() ) : $class->_new_from_dbic($rs); + return $self->SUPER::search( { %$params, %$or, }, $join ); } sub categories { diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 620ddc7..9cfed64 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -103,7 +103,17 @@ if ($op eq 'add_form') { my $duplicate_entry = 0; my @branches = grep { $_ ne q{} } $input->param('branches'); - if ( $id ) { # Update + my $already_exists = Koha::AuthorisedValues->search( + { + category => $new_category, + authorised_value => $new_authorised_value, + } + )->count; + + if ( $already_exists ) { + push @messages, {type => 'error', code => 'already_exists' }; + } + elsif ( $id ) { # Update my $av = Koha::AuthorisedValues->new->find( $id ); $av->lib( $input->param('lib') || undef ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt index 19f36d0..3901ba3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt @@ -184,6 +184,8 @@ $(document).ready(function() { Authorized value inserted successfully. [% CASE 'success_on_delete' %] Authorized value deleted successfully. + [% CASE 'already_exists' %] + This authorized value already exists. [% CASE %] [% m.code %] [% END %] -- 2.1.0