From 7b7649dc6fa7cf980ea591aa71ac4832d9d4f224 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Tue, 20 Nov 2018 13:23:29 +0200
Subject: [PATCH] Bug 11529: Remove field mapping table and admin page

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Michal Denar <black23@gmail.com>
---
 Koha/FieldMapping.pm                          | 44 ---------
 Koha/FieldMappings.pm                         | 50 ----------
 Koha/Manual.pm                                |  1 -
 admin/fieldmapping.pl                         | 70 --------------
 .../data/mysql/atomicupdate/bug_11529.perl    |  2 +
 installer/data/mysql/kohastructure.sql        | 13 ---
 .../marc21/optional/fieldmapping.sql          |  3 -
 .../marc21/optional/fieldmapping.txt          |  1 -
 .../marc21/optional/fieldmapping.sql          | 10 --
 .../marc21/optional/fieldmapping.txt          |  1 -
 .../prog/en/includes/admin-menu.inc           |  3 -
 .../prog/en/modules/admin/admin-home.tt       |  4 -
 .../prog/en/modules/admin/fieldmapping.tt     | 94 -------------------
 t/db_dependent/Koha/BiblioUtils.t             |  4 -
 14 files changed, 2 insertions(+), 298 deletions(-)
 delete mode 100644 Koha/FieldMapping.pm
 delete mode 100644 Koha/FieldMappings.pm
 delete mode 100755 admin/fieldmapping.pl
 delete mode 100644 installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.sql
 delete mode 100644 installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.txt
 delete mode 100644 installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.sql
 delete mode 100644 installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.txt
 delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt

diff --git a/Koha/FieldMapping.pm b/Koha/FieldMapping.pm
deleted file mode 100644
index bf0a1d62ab..0000000000
--- a/Koha/FieldMapping.pm
+++ /dev/null
@@ -1,44 +0,0 @@
-package Koha::FieldMapping;
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-
-use Carp;
-
-use Koha::Database;
-
-use base qw(Koha::Object);
-
-=head1 NAME
-
-Koha::FieldMapping - Koha Field Mapping Object class
-
-=head1 API
-
-=head2 Class Methods
-
-=cut
-
-=head3 type
-
-=cut
-
-sub _type {
-    return 'Fieldmapping';
-}
-
-1;
diff --git a/Koha/FieldMappings.pm b/Koha/FieldMappings.pm
deleted file mode 100644
index 8145dd7ecc..0000000000
--- a/Koha/FieldMappings.pm
+++ /dev/null
@@ -1,50 +0,0 @@
-package Koha::FieldMappings;
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-
-use Carp;
-
-use Koha::Database;
-
-use Koha::FieldMapping;
-
-use base qw(Koha::Objects);
-
-=head1 NAME
-
-Koha::FieldMappings - Koha Field Mapping Object set class
-
-=head1 API
-
-=head2 Class Methods
-
-=cut
-
-=head3 type
-
-=cut
-
-sub _type {
-    return 'Fieldmapping';
-}
-
-sub object_class {
-    return 'Koha::FieldMapping';
-}
-
-1;
diff --git a/Koha/Manual.pm b/Koha/Manual.pm
index 29028eff8b..1bc89e319e 100644
--- a/Koha/Manual.pm
+++ b/Koha/Manual.pm
@@ -79,7 +79,6 @@ our $mapping = {
     'admin/didyoumean'                         => '/administration.html#did-you-mean?',
     'admin/edi_accounts'                       => '/administration.html#edi-accounts',
     'admin/edi_ean_accounts'                   => '/administration.html#library-eans',
-    'admin/fieldmapping'                       => '/administration.html#keywords-to-marc-mapping',
     'admin/item_circulation_alerts'            => '/administration.html#item-circulation-alerts',
     'admin/items_search_fields'                => '/administration.html#item-search-fields',
     'admin/itemtypes'                          => '/administration.html#item-types',
diff --git a/admin/fieldmapping.pl b/admin/fieldmapping.pl
deleted file mode 100755
index ac13cc201c..0000000000
--- a/admin/fieldmapping.pl
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/perl
-# Copyright 2009 SARL BibLibre
-# Copyright 2017 Koha Development Team
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-use CGI qw ( -utf8 );
-use C4::Auth;
-use C4::Biblio;
-use C4::Output;
-
-use Koha::BiblioFrameworks;
-use Koha::FieldMappings;
-
-my $query = new CGI;
-
-my $frameworkcode = $query->param('framework') || "";
-my $field         = $query->param('fieldname');
-my $fieldcode     = $query->param('marcfield');
-my $subfieldcode  = $query->param('marcsubfield');
-my $op            = $query->param('op') || q{};
-my $id            = $query->param('id');
-
-my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
-    {
-        template_name   => "admin/fieldmapping.tt",
-        query           => $query,
-        type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { parameters => 'manage_keywords2marc_mappings' },
-        debug           => 1,
-    }
-);
-
-# FIXME Add exceptions
-if ( $op eq "delete" and $id ) {
-    Koha::FieldMappings->find($id)->delete;
-} elsif ( $field and $fieldcode ) {
-    my $params = { frameworkcode => $frameworkcode, field => $field, fieldcode => $fieldcode, subfieldcode => $subfieldcode };
-    my $exists = Koha::FieldMappings->search( $params )->count;;
-    unless ( $exists ) {
-        Koha::FieldMapping->new( $params )->store;
-    }
-}
-
-my $fields = Koha::FieldMappings->search({ frameworkcode => $frameworkcode });
-
-my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
-my $framework  = $frameworks->search( { frameworkcode => $frameworkcode } )->next;
-$template->param(
-    frameworks => $frameworks,
-    framework  => $framework,
-    fields     => $fields,
-);
-
-output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/installer/data/mysql/atomicupdate/bug_11529.perl b/installer/data/mysql/atomicupdate/bug_11529.perl
index 43ef42f0ec..c67d85f2b7 100644
--- a/installer/data/mysql/atomicupdate/bug_11529.perl
+++ b/installer/data/mysql/atomicupdate/bug_11529.perl
@@ -28,6 +28,8 @@ if( CheckVersion( $DBversion ) ) {
         $dbh->do( "UPDATE marc_subfield_structure SET kohafield='biblio.part_name' WHERE frameworkcode='' AND tagfield='245' AND tagsubfield='p'" );
     }
 
+    $dbh->do( "DROP TABLE IF EXISTS fieldmapping" );
+
     # Always end with this (adjust the bug info)
     SetVersion( $DBversion );
     print "Upgrade to $DBversion done (Bug 11529 - Add medium, subtitle and part information to biblio table)\n";
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index d18b0632de..b97970ac28 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -3267,19 +3267,6 @@ CREATE TABLE aqorders_transfers (
   CONSTRAINT aqorders_transfers_ordernumber_to FOREIGN KEY (ordernumber_to) REFERENCES aqorders (ordernumber) ON DELETE SET NULL ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
---
--- Table structure for table `fieldmapping`
---
-
-DROP TABLE IF EXISTS `fieldmapping`;
-CREATE TABLE `fieldmapping` ( -- koha to keyword mapping
-  `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
-  `field` varchar(255) NOT NULL, -- keyword to be mapped to (ex. subtitle)
-  `frameworkcode` char(4) NOT NULL default '', -- foreign key from the biblio_framework table to link this mapping to a specific framework
-  `fieldcode` char(3) NOT NULL, -- marc field number to map to this keyword
-  `subfieldcode` char(1) NOT NULL, -- marc subfield associated with the fieldcode to map to this keyword
-  PRIMARY KEY  (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 --
 -- Table structure for table `transport_cost`
diff --git a/installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.sql b/installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.sql
deleted file mode 100644
index 19c4058f94..0000000000
--- a/installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-INSERT INTO `fieldmapping` (`field`, `frameworkcode`, `fieldcode`, `subfieldcode`) VALUES
-('subtitle', 'CF',  '245', 'p'),
-('subtitle', 'SER', '490', 'v');
diff --git a/installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.txt b/installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.txt
deleted file mode 100644
index 94d57bd7fd..0000000000
--- a/installer/data/mysql/ru-RU/marcflavour/marc21/optional/fieldmapping.txt
+++ /dev/null
@@ -1 +0,0 @@
-Отображение ключевого слова в МАРК-поле (пока 490^v (SER) и 245^p (CF) в кл.сл. «subtitle»).
diff --git a/installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.sql b/installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.sql
deleted file mode 100644
index 71f2f1a6a9..0000000000
--- a/installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.sql
+++ /dev/null
@@ -1,10 +0,0 @@
--- koha to keyword mapping
---  id            -- unique identifier assigned by Koha (auto_increment)
---  field         -- keyword to be mapped to (ex. subtitle)
---  frameworkcode -- foreign key from the biblio_framework table to link this mapping to a specific framework (default '')
---  fieldcode     -- marc field number to map to this keyword
---  subfieldcode  -- marc subfield associated with the fieldcode to map to this keyword
-INSERT INTO fieldmapping
- ( field,     frameworkcode,  fieldcode, subfieldcode) VALUES
- ('subtitle', 'CF',           '245',     'p'),
- ('subtitle', 'SER',          '490',     'v');
diff --git a/installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.txt b/installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.txt
deleted file mode 100644
index 6382493eea..0000000000
--- a/installer/data/mysql/uk-UA/marcflavour/marc21/optional/fieldmapping.txt
+++ /dev/null
@@ -1 +0,0 @@
-Відображення ключового слова у МАРК-поле (наразі 490^v (SER) та 245^p (CF) у кл.сл. „subtitle“).
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
index 1677280097..9953d98baf 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
@@ -58,9 +58,6 @@
                 <li><a href="/cgi-bin/koha/admin/biblio_framework.pl">MARC bibliographic framework</a></li>
                 <li><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></li>
             [% END %]
-            [% IF ( CAN_user_parameters_manage_keywords2koha_mappings ) %]
-                <li><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></li>
-            [% END %]
             [% IF ( CAN_user_parameters_manage_marc_frameworks ) %]
                 <li><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC bibliographic framework test</a></li>
                 <li><a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a></li>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
index 60c0f572f0..8d7930af7b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
@@ -117,10 +117,6 @@
                         <dt><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></dt>
                         <dd>Define the mapping between the Koha transactional database (SQL) and the MARC Bibliographic records.</dd>
                     [% END %]
-                    [% IF ( CAN_user_parameters_manage_keywords2koha_mappings ) %]
-                        <dt><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></dt>
-                        <dd>Define the mapping between keywords and MARC fields. The keywords are used to find some data independently of the framework.</dd>
-                    [% END %]
                     [% IF ( CAN_user_parameters_manage_marc_frameworks ) %]
                         <dt><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC Bibliographic framework test</a></dt>
                         <dd>Checks the MARC structure. If you change your MARC Bibliographic framework it's recommended that you run this tool to test for errors in your definition.</dd>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt
deleted file mode 100644
index b4a75a91d9..0000000000
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt
+++ /dev/null
@@ -1,94 +0,0 @@
-[% USE raw %]
-[% USE Asset %]
-[% SET footerjs = 1 %]
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Administration &rsaquo; Keyword to MARC mapping</title>
-[% INCLUDE 'doc-head-close.inc' %]
-</head>
-
-<body id="admin_fieldmapping" class="admin">
-[% INCLUDE 'header.inc' %]
-[% INCLUDE 'prefs-admin-search.inc' %]
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Keyword to MARC mapping</div>
-
-<div class="main container-fluid">
-    <div class="row">
-        <div class="col-sm-10 col-sm-push-2">
-            <main>
-
-            <h2>Keyword to MARC mapping</h2>
-            [% UNLESS ( fields.count ) %]
-                <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext | html %]</em>[% ELSE %]default[% END %] framework. </p></div>
-            [% END %]
-			<form method="get" action="/cgi-bin/koha/admin/fieldmapping.pl" id="selectframework">
-				<label for="framework">Framework:</label>
-                <select name="framework" id="framework" style="width:20em;">
-                    <option value="">Default</option>
-                [% FOREACH f IN frameworks %]
-                    [% IF f.frameworkcode == framework.frameworkcode %]
-                    <option selected="selected" value="[% f.frameworkcode | html %]">[% f.frameworktext | html %]</option>
-                    [% ELSE %]
-                    <option value="[% f.frameworkcode | html %]">[% f.frameworktext | html %]</option>
-                    [% END %]
-                [% END %]
-                </select>
-			<input type="submit" value="Go" />
-			</form>
-
-
-			<form method="post" action="" id="addfield">
-                <input type="hidden" name="framework" value="[% framework.frameworkcode | html %]" />
-				<fieldset class="rows">
-				<legend>Add a mapping</legend>
-				<ol>
-					<li><label for="fieldname">Field name: </label><input type="text" id="fieldname" name="fieldname" /></li>
-					<li><label for="marcfield">MARC field: </label><input type="text" id="marcfield" name="marcfield" size="3" /></li>
-					<li><label for="marcsubfield">MARC subfield: </label><input type="text" id="marcsubfield" name="marcsubfield" size="1" /></li>
-				</ol>
-				<fieldset class="action">
-					<input type="submit" value="Submit" />
-				</fieldset>
-				</fieldset>
-			</form>
-
-                [% IF ( fields.count ) %]
-                    <table>
-                    <caption>Mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext | html %]</em>[% ELSE %]default[% END %] framework</caption>
-									<tr>
-										<th>Field</th>
-                                        <th>MARC field</th>
-                                        <th>MARC subfield</th>
-										<th>&nbsp;</th>
-									</tr>
-									[% FOREACH field IN fields %]
-									<tr>
-                                        <td>[% field.field | html %]</td>
-										<td>[% field.fieldcode | html %]</td>
-										<td>[% field.subfieldcode | html %]</td>
-                                        <td><a class="btn btn-default btn-xs" href="?op=delete&amp;id=[% field.id | html %]&amp;framework=[% field.frameworkcode | html %]"><i class="fa fa-trash"></i> Delete</a></td>
-									</tr>
-									[% END %]
-								</table>[% END %]
-
-            </main>
-        </div> <!-- /.col-sm-10.col-sm-push-2 -->
-
-        <div class="col-sm-2 col-sm-pull-10">
-            <aside>
-                [% INCLUDE 'admin-menu.inc' %]
-            </aside>
-        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
-     </div> <!-- /.row -->
-[% MACRO jsinclude BLOCK %]
-    [% Asset.js("js/admin-menu.js") | $raw %]
-    <script type="text/javascript">
-    <script>
-        $(document).ready(function() {
-            $('#selectframework').find("input:submit").hide();
-            $('#framework').change(function() {
-                    $('#selectframework').submit();
-            });
-        });
-    </script>
-[% END %]
-[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/t/db_dependent/Koha/BiblioUtils.t b/t/db_dependent/Koha/BiblioUtils.t
index 85bf9217b9..fb5776d800 100755
--- a/t/db_dependent/Koha/BiblioUtils.t
+++ b/t/db_dependent/Koha/BiblioUtils.t
@@ -46,10 +46,6 @@ $biblio->append_fields(
 );
 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
 
-my $field_mappings = Koha::Database->new()->schema()->resultset('Fieldmapping');
-$field_mappings->delete();
-$field_mappings->create( { field => 'subtitle', fieldcode => '245', subfieldcode => 'b' } );
-
 $biblio = Koha::Biblios->find( $biblionumber );
 my @subtitles = $biblio->subtitles();
 is( $subtitles[0], 'Test Record Subtitle', 'Got first subtitle correctly' );
-- 
2.17.1