Bug 10363: FIX regression - prevent duplicate
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 4 Aug 2015 13:43:20 +0000 (14:43 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 19 Oct 2015 15:46:28 +0000 (12:46 -0300)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/AuthorisedValues.pm
admin/authorised_values.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt

index f81eea7..e690d8c 100644 (file)
@@ -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 {
index 620ddc7..7534353 100755 (executable)
@@ -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,
+        }
+    )->next;
+
+    if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
+        push @messages, {type => 'error', code => 'already_exists' };
+    }
+    elsif ( $id ) { # Update
         my $av = Koha::AuthorisedValues->new->find( $id );
 
         $av->lib( $input->param('lib') || undef );
index 19f36d0..3901ba3 100644 (file)
@@ -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 %]