From c83735f628e9f9af707d6dce55cd25f36e1050de Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Mon, 19 Aug 2019 15:44:17 -0400
Subject: [PATCH] Bug 20307: Use 'auhorised_values' instead of 'avs' to avoid
 confusion

And so we need to extend the size of localization.entity

Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 Koha/AuthorisedValue.pm                                     | 6 +++---
 Koha/Schema/Result/AuthorisedValueLocalization.pm           | 2 +-
 installer/data/mysql/atomicupdate/bug_20307.perl            | 1 +
 installer/data/mysql/kohastructure.sql                      | 2 +-
 .../prog/en/modules/admin/authorised_values.tt              | 4 ++--
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm
index 2c2e4cd051..08f77f24b2 100644
--- a/Koha/AuthorisedValue.pm
+++ b/Koha/AuthorisedValue.pm
@@ -69,7 +69,7 @@ sub opac_translated_description {
     $lang ||= C4::Languages::getlanguage;
     my $translated_description = Koha::Localizations->search({
         code => $self->authorised_value,
-        entity => 'avs',
+        entity => 'authorised_values',
         lang => $lang,
         interface => 'opac',
     })->next;
@@ -95,7 +95,7 @@ sub translated_description {
     $lang ||= C4::Languages::getlanguage;
     my $translated_description = Koha::Localizations->search({
         code => $self->authorised_value,
-        entity => 'avs',
+        entity => 'authorised_values',
         lang => $lang,
     })->next;
     return $translated_description
@@ -110,7 +110,7 @@ sub translated_description {
 sub translated_descriptions {
     my ( $self ) = @_;
     my @translated_descriptions = Koha::Localizations->search(
-        {   entity => 'avs',
+        {   entity => 'authorised_values',
             code   => $self->authorised_value,
         }
     );
diff --git a/Koha/Schema/Result/AuthorisedValueLocalization.pm b/Koha/Schema/Result/AuthorisedValueLocalization.pm
index fa2c69662b..b283172b1e 100644
--- a/Koha/Schema/Result/AuthorisedValueLocalization.pm
+++ b/Koha/Schema/Result/AuthorisedValueLocalization.pm
@@ -9,7 +9,7 @@ __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
 __PACKAGE__->table('authorised_value_localizations');
 __PACKAGE__->result_source_instance->is_virtual(1);
 __PACKAGE__->result_source_instance->view_definition(
-    "SELECT localization_id, code, lang, translation FROM localization WHERE entity='avs'"
+    "SELECT localization_id, code, lang, translation FROM localization WHERE entity='authorised_values'"
 );
 
 __PACKAGE__->add_columns(
diff --git a/installer/data/mysql/atomicupdate/bug_20307.perl b/installer/data/mysql/atomicupdate/bug_20307.perl
index 36896af3be..c82a7af872 100644
--- a/installer/data/mysql/atomicupdate/bug_20307.perl
+++ b/installer/data/mysql/atomicupdate/bug_20307.perl
@@ -4,6 +4,7 @@ if ( CheckVersion($DBversion) ) {
         $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` ADD UNIQUE KEY `entity_code_interface_lang` (entity, code, interface, lang)");
+        $dbh->do("ALTER TABLE `localization` MODIFY entity VARCHAR(30) NOT NULL");
     }
 
     SetVersion($DBversion);
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 8dba4d1739..dd2ca5aa62 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -3695,7 +3695,7 @@ CREATE TABLE `additional_field_values` (
 DROP TABLE IF EXISTS localization;
 CREATE TABLE `localization` (
       localization_id int(11) NOT NULL AUTO_INCREMENT,
-      entity varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
+      entity varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,
       interface varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
       code varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
       lang varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, -- could be a foreign key
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 97c0b84683..4021243fdb 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
@@ -77,7 +77,7 @@
             <input type="text" name="lib" id="lib" value="[% lib | html %]" maxlength="200" />
             [% IF can_be_translated %]
                 [% IF action_modify %]
-                    <a href="/cgi-bin/koha/admin/localization.pl?entity=avs&code=[% authorised_value | uri %]&interface=intranet"" title="Translate description" rel="gb_page_center[600,500]"><i class="fa fa-pencil"></i> Translate into other languages</a>
+                    <a href="/cgi-bin/koha/admin/localization.pl?entity=authorised_values&code=[% authorised_value | uri %]&interface=intranet"" title="Translate description" rel="gb_page_center[600,500]"><i class="fa fa-pencil"></i> Translate into other languages</a>
                 [% ELSE %]
                     <a href="#" class="disabled" title="The authorized value has to be saved to make it translatable"><i class="fa fa-pencil"></i> Translate into other languages</a>
                 [% END %]
@@ -88,7 +88,7 @@
             <input type="text" name="lib_opac" id="lib_opac" value="[% lib_opac | html %]" maxlength="200" />
             [% IF can_be_translated %]
                 [% IF action_modify %]
-                    <a href="/cgi-bin/koha/admin/localization.pl?entity=avs&code=[% authorised_value | uri %]&interface=opac" title="Translate OPAC description" rel="gb_page_center[600,500]"><i class="fa fa-pencil"></i> Translate into other languages</a>
+                    <a href="/cgi-bin/koha/admin/localization.pl?entity=authorised_values&code=[% authorised_value | uri %]&interface=opac" title="Translate OPAC description" rel="gb_page_center[600,500]"><i class="fa fa-pencil"></i> Translate into other languages</a>
                 [% ELSE %]
                     <a href="#" class="disabled" title="The authorized value has to be saved to make it translatable"><i class="fa fa-pencil"></i> Translate into other languages</a>
                 [% END %]
-- 
2.20.1