Koha/admin/koha2marclinks.pl
Marcel de Rooy 9dfff3ab19 Bug 10306: Support for multiple mappings in koha2marclinks
This actually refactors koha2marclinks.pl in order to support multiple
mappings per kohafield.

Instead of three separate mapping pages for biblio, biblioitems and items,
the script now lists them together. This gives a complete overview of all
mappings rightaway. Changes are applied immediately across all frameworks.

Note: This report handles the Default mappings just like it did before.
In this script Koha already considered them as authoritative, although
other parts of Koha did not. Follow-up report 19096 makes Default
mappings authoritative throughout all Koha.

On each line two buttons are provided, Add and Remove, in order to add or
remove an individual mapping. We do no longer provide a separate form with
the names of MARC tags. Since this form is targeted for administrators,
it should be enough to ask for a field tag and subfield code.

Note: The mappings for biblionumber, biblioitemnumber and itemnumber are
so vital that this form marks them as readonly. It is not recommended to
change them.

Test plan:
[1] Add a mapping. Verify via Frameworks or mysql command line that the
    kohafield is saved to the other frameworks too.
[2] Remove the mapping again. Check Frameworks or mysql cl again.
[3] Test adding a second mapping. Map copyrightdate to 260c and 264c.
    And map biblioitems.place to 260a and 264a.
[4] Edit biblio record 1: Put 1980 in 260c. Do not include 264c.
    Edit biblio record 2: Put 1990 in 264c. Do not include 260c.
    Edit biblio record 3: Put 2000 in both 260c and 264c. Put CityA in 260a
    and in 264a.
    Edit biblio record 4: Put 2010 in 260c, and 2015 in 264c (which you
    should refuse normally). Put CityA in 260a, and CityB in 264a.
[5] Create a report that shows biblioitems.place and biblio.copyrightdate
    for those biblio records.
    Record 4 should have 2010 in copyrightdate (since TransformMarcToKoha
    picks the first year for copyrightdate).
    Record 3 should have place CityA; record 4 should have CityA | CityB.
    Note: The CityA | CityB example illustrates that we should add some
    additional handling in TransformMarcToKoha for multiple 264s.
[6] Add these four biblio records to a new list. Sort by Year.
    With OPACXSLTListsDisplay==default, check if the order = 1,2,3,4.
    (The order is based on biblio.copyrightdate.)
    Note that (RDA) record 2 would be on top without this patch set, since
    copyrightdate would have been null.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-12-07 14:44:15 -03:00

112 lines
3.2 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
# Copyright 2017 Rijksmuseum
#
# 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 Koha::Database;
use C4::Auth;
use C4::Biblio;
use C4::Output;
use Koha::BiblioFrameworks;
use Koha::Caches;
use Koha::MarcSubfieldStructures;
my $input = new CGI;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
{
template_name => "admin/koha2marclinks.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { parameters => 'parameters_remaining_permissions' },
debug => 1,
}
);
my $schema = Koha::Database->new->schema;
my $cache = Koha::Caches->get_instance();
# Update data before showing the form
my $no_upd;
if( $input->param('add_field') ) {
# add a mapping to all frameworks
my ($kohafield, $tag, $sub) = split /,/, $input->param('add_field'), 3;
Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => $kohafield });
} elsif( $input->param('remove_field') ) {
# remove a mapping from all frameworks
my ($tag, $sub) = split /,/, $input->param('remove_field'), 2;
Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => undef });
} else {
$no_upd = 1;
}
# Clear the cache when needed
unless( $no_upd ) {
for( qw| default_value_for_mod_marc- MarcSubfieldStructure- | ) {
$cache->clear_from_cache($_);
}
}
# Build/Show the form
my $dbix_map = {
# Koha to MARC mappings are found in only three tables
biblio => 'Biblio',
biblioitems => 'Biblioitem',
items => 'Item',
};
my @cols;
foreach my $tbl ( sort keys %{$dbix_map} ) {
push @cols,
map { "$tbl.$_" } $schema->source( $dbix_map->{$tbl} )->columns;
}
my $kohafields = Koha::MarcSubfieldStructures->search({
frameworkcode => q{},
kohafield => { '>', '' },
});
my @loop_data;
foreach my $col ( @cols ) {
my $found;
my $readonly = $col =~ /\.(biblio|biblioitem|item)number$/;
foreach my $row ( $kohafields->search({ kohafield => $col }) ) {
$found = 1;
push @loop_data, {
kohafield => $col,
tagfield => $row->tagfield,
tagsubfield => $row->tagsubfield,
liblibrarian => $row->liblibrarian,
readonly => $readonly,
};
}
push @loop_data, {
kohafield => $col,
readonly => $readonly,
} if !$found;
}
$template->param(
loop => \@loop_data,
);
output_html_with_http_headers $input, $cookie, $template->output;