From 95a55d48f0d64dccfbedbaef360dd5e6a21ced30 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 15 Oct 2019 16:52:09 +0200
Subject: [PATCH] Bug 20307: Few more fixes due to bad rebase conflict
 resolutions

---
 Koha/AuthorisedValues.pm                                   | 14 +++++++++-----
 installer/data/mysql/atomicupdate/bug_20307.perl           |  2 +-
 .../prog/en/modules/admin/authorised_values.tt             |  8 ++++----
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm
index 475423f977..dbdfcf4c04 100644
--- a/Koha/AuthorisedValues.pm
+++ b/Koha/AuthorisedValues.pm
@@ -27,7 +27,7 @@ use Koha::AuthorisedValue;
 use Koha::MarcSubfieldStructures;
 use Koha::Cache::Memory::Lite;
 
-use base qw(Koha::Objects);
+use base qw(Koha::Objects Koha::Objects::Limit::Library);
 
 =head1 NAME
 
@@ -62,7 +62,7 @@ sub search {
       : {};
 
     my @join = $attributes->{join} || ();
-    push @join, 'authorised_values_branches';
+    push @join, $branchcode ? 'authorised_values_branches' : ();
     my $join = { join => \@join };
     $attributes //= {};
     $attributes = { %$attributes, %$join };
@@ -197,15 +197,19 @@ sub search_with_localization {
     $attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by};
     my @join = $attributes->{join} || ();
     push @join, 'localization';
-    my $join = { join => \@join };
+    $attributes->{join} = \@join;
     $attributes->{'+select'} = [
         {
             coalesce => [qw( localization.translation me.lib )],
             -as      => 'translated_description'
         }
     ];
-    $attributes = { %$attributes, %$join };
-    $self->search( $params, $attributes );
+    if(defined $params->{branchcode}) {
+        my $branchcode = delete $params->{branchcode};
+        $self->search_with_library_limits( $params, $attributes, $branchcode );
+    } else {
+        $self->SUPER::search( $params, $attributes );
+    }
 }
 
 
diff --git a/installer/data/mysql/atomicupdate/bug_20307.perl b/installer/data/mysql/atomicupdate/bug_20307.perl
index c82a7af872..ffaff3c386 100644
--- a/installer/data/mysql/atomicupdate/bug_20307.perl
+++ b/installer/data/mysql/atomicupdate/bug_20307.perl
@@ -2,7 +2,7 @@ $DBversion = 'XXX';    # will be replaced by the RM
 if ( CheckVersion($DBversion) ) {
     if ( !column_exists( 'localization', 'interface' ) ) {
         $dbh->do("ALTER TABLE `localization` ADD COLUMN `interface` VARCHAR(30) DEFAULT NULL AFTER `entity`");
-        $dbh->do("ALTER TABLE `localization` DROP FOREIGN KEY `entity_code_lang`");
+        $dbh->do("ALTER TABLE `localization` DROP KEY `entity_code_lang`");
         $dbh->do("ALTER TABLE `localization` ADD UNIQUE KEY `entity_code_interface_lang` (entity, code, interface, lang)");
         $dbh->do("ALTER TABLE `localization` MODIFY entity VARCHAR(30) NOT NULL");
     }
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 7f83819524..bf591aac50 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
@@ -255,7 +255,7 @@
         <td>[% av.lib_opac | html %]</td>
         <td>[% IF ( av.imageurl ) %]<img src="[% av.imageurl | url %]" alt=""/>[% ELSE %]&nbsp;[% END %]</td>
         <td>
-            [% IF av.branch_limitations.size > 0 %]
+            [% IF av.library_limits.count > 0 %]
                 [% branches_str = "" %]
                 [% FOREACH library IN av.library_limits %]
                     [%- IF loop.first -%]
@@ -265,10 +265,10 @@
                     [% END %]
                 [% END %]
                 <span class="library_limitation" title="[% branches_str | html %]">
-                    [% IF av.library_limits.size > 1 %]
-                        [% av.library_limits.size | html %] library limitations
+                    [% IF av.library_limits.count > 1 %]
+                        [% av.library_limits.count | html %] library limitations
                     [% ELSE %]
-                        [% av.library_limits.size | html %] library limitation
+                        [% av.library_limits.count | html %] library limitation
                     [% END %]
             [% ELSE %]
                 No limitation
-- 
2.11.0