Bugzilla – Attachment 94068 Details for
Bug 20434
UNIMARC update from IFLA for existing Koha installations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20434: Update UNIMARC framework - script
Bug-20434-Update-UNIMARC-framework---script.patch (text/plain), 11.83 KB, created by
Alex Arnaud
on 2019-10-14 10:11:05 UTC
(
hide
)
Description:
Bug 20434: Update UNIMARC framework - script
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2019-10-14 10:11:05 UTC
Size:
11.83 KB
patch
obsolete
>From 077c32b7f1f228b223ab9902273e641be97c5e1c Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 2 Oct 2019 13:45:32 +0200 >Subject: [PATCH] Bug 20434: Update UNIMARC framework - script > >Test plan: >1. Take a look at files in misc/migration_tools/ifla/data. It > contains all data that will be inserted into Koha. Its content is > based on the previous patches. >2. Run the script misc/migration_tools/ifla/update.pl and verify > that it effectively added the new fields, subfields, authorised > values and authority types. >3. Run the script again and see that it doesn't update existing fields >4. Run with --force and verify that it update existing fields (you can > modify unimarc_ifla.yml to see changes) >5. Run with --force --po-file misc/migration_tools/ifla/language/fr.po > and verify that the labels are now in french > >There is a POT file in misc/migration_tools/ifla/language/template.pot, >use it to create PO files for other languages. > >Signed-off-by: Sonia BOUIS <sonia.bouis@univ-lyon3.fr> >Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> >--- > misc/migration_tools/ifla/update.pl | 309 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 309 insertions(+) > create mode 100755 misc/migration_tools/ifla/update.pl > >diff --git a/misc/migration_tools/ifla/update.pl b/misc/migration_tools/ifla/update.pl >new file mode 100755 >index 0000000..b736bf8 >--- /dev/null >+++ b/misc/migration_tools/ifla/update.pl >@@ -0,0 +1,309 @@ >+#!/usr/bin/env perl >+ >+# Copyright 2018 BibLibre >+# >+# 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 Date::Format; >+use File::Basename; >+use FindBin qw($Bin); >+use Getopt::Long; >+use Locale::PO; >+use YAML qw(LoadFile); >+use utf8; >+ >+use Koha::Database; >+ >+my $help; >+my $po_file; >+my $dump_pot; >+my $force; >+GetOptions( >+ 'help' => \$help, >+ 'po-file=s' => \$po_file, >+ 'dump-pot' => \$dump_pot, >+ 'force' => \$force, >+) or die 'Error in command line arguments'; >+ >+if ($help) { >+ my $basename = basename($0); >+ say <<"EOT"; >+Usage: >+ $basename [--po-file FILE] [--force] >+ $basename --dump-pot >+ $basename --help >+ >+This script adds new fields and subfields for biblio and authority, new >+authority types and new authorised values, for UNIMARC IFLA update >+ >+Options: >+ --help >+ Display this help >+ >+ --po-file FILE >+ PO file containing translations >+ >+ --dump-pot >+ Print a POT file containing all translatable strings and exit >+ >+ --force >+ Force updating existing data >+EOT >+ >+ exit 0; >+} >+ >+my $defaults = LoadFile("$Bin/data/defaults.yml"); >+my $authorised_values = LoadFile("$Bin/data/authorised_values.yml"); >+my $authtypes = LoadFile("$Bin/data/authtypes.yml"); >+my @authtags; >+my @authsubfields; >+for my $authfw (qw(default CLASS CO EXP FAM GENRE_FORM NP NTEXP NTWORK PA PERS PUB SAUTTIT SNC SNG TM TU WORK)) { >+ my $file = LoadFile("$Bin/data/auth/$authfw.yml"); >+ push @authtags, @{ $file->{authtags} }; >+ push @authsubfields, @{ $file->{authsubfields} }; >+} >+my $biblio = LoadFile("$Bin/data/biblio/default.yml"); >+my @tags = @{ $biblio->{tags} }; >+my @subfields = @{ $biblio->{subfields} }; >+ >+my $translations = {}; >+if ($dump_pot) { >+ $translations->{''} = new Locale::PO( >+ -msgid => '', >+ -msgstr => "Project-Id-Version: Koha\n" . >+ "POT-Creation-Date: " . time2str('%Y-%m-%d %R%z', time) . "\n" . >+ "MIME-Version: 1.0\n" . >+ "Content-Type: text/plain; charset=UTF-8\n" . >+ "Content-Transfer-Encoding: 8bit\n", >+ ); >+ while (my ($category, $values) = each %$authorised_values) { >+ foreach my $authorised_value (@$values) { >+ $translations->{$authorised_value->{lib}} = new Locale::PO( >+ -msgid => $authorised_value->{lib}, >+ -msgstr => '', >+ ); >+ } >+ } >+ for my $tag (@tags) { >+ $translations->{$tag->{liblibrarian}} = new Locale::PO( >+ -msgid => $tag->{liblibrarian}, >+ -msgstr => '', >+ ); >+ } >+ for my $subfield (@subfields) { >+ $translations->{$subfield->{liblibrarian}} = new Locale::PO( >+ -msgid => $subfield->{liblibrarian}, >+ -msgstr => '', >+ ); >+ } >+ for my $authtype (@$authtypes) { >+ $translations->{$authtype->{authtypetext}} = new Locale::PO( >+ -msgid => $authtype->{authtypetext}, >+ -msgstr => '', >+ ); >+ } >+ for my $authtag (@authtags) { >+ $translations->{$authtag->{liblibrarian}} = new Locale::PO( >+ -msgid => $authtag->{liblibrarian}, >+ -msgstr => '', >+ ); >+ } >+ for my $authsubfield (@authsubfields) { >+ $translations->{$authsubfield->{liblibrarian}} = new Locale::PO( >+ -msgid => $authsubfield->{liblibrarian}, >+ -msgstr => '', >+ );; >+ } >+ >+ Locale::PO->save_file_fromhash("$Bin/language/template.pot", $translations, 'utf8'); >+ >+ exit 0; >+} >+ >+if ($po_file) { >+ $translations = Locale::PO->load_file_ashash($po_file, 'utf8'); >+} >+ >+sub t { >+ my ($string) = @_; >+ >+ my $quoted_string = Locale::PO->quote($string); >+ unless (exists $translations->{$quoted_string} and $translations->{$quoted_string}) { >+ return $string; >+ } >+ >+ return Locale::PO->dequote($translations->{$quoted_string}->msgstr); >+} >+ >+ >+my $schema = Koha::Database->new()->schema(); >+my $authorised_value_rs = $schema->resultset('AuthorisedValue'); >+my $authorised_value_category_rs = $schema->resultset('AuthorisedValueCategory'); >+my $marc_tag_structure_rs = $schema->resultset('MarcTagStructure'); >+my $marc_subfield_structure_rs = $schema->resultset('MarcSubfieldStructure'); >+my $auth_type_rs = $schema->resultset('AuthType'); >+my $auth_tag_structure_rs = $schema->resultset('AuthTagStructure'); >+my $auth_subfield_structure_rs = $schema->resultset('AuthSubfieldStructure'); >+ >+my $av_defaults = $defaults->{av}; >+while (my ($category, $values) = each %$authorised_values) { >+ foreach my $authorised_value (@$values) { >+ foreach my $key (keys %$av_defaults) { >+ unless (exists $authorised_value->{$key}) { >+ $authorised_value->{$key} = $av_defaults->{$key}; >+ } >+ } >+ $authorised_value->{category} = $category; >+ $authorised_value->{lib} = t($authorised_value->{lib}); >+ >+ my $value = $authorised_value->{authorised_value}; >+ my $av = $authorised_value_rs->find({ >+ category => $category, >+ authorised_value => $value, >+ }); >+ if ($av) { >+ say "Authorised value already exists ($category, $value)"; >+ if ($force) { >+ say "Force mode is active, updating authorised value ($category, $value)"; >+ $av->update($authorised_value); >+ } >+ next; >+ } >+ >+ my $cat = $authorised_value_category_rs->find($category); >+ if (!$cat) { >+ say "Adding authorised value category $category"; >+ $authorised_value_category_rs->create({ >+ category_name => $category, >+ }); >+ } >+ >+ say "Adding authorised value ($category, $value)"; >+ $authorised_value_rs->create($authorised_value); >+ } >+} >+ >+my $tag_defaults = $defaults->{tag}; >+for my $tag (@tags) { >+ foreach my $key (keys %$tag_defaults) { >+ unless (exists $tag->{$key}) { >+ $tag->{$key} = $tag_defaults->{$key}; >+ } >+ } >+ $tag->{liblibrarian} = t($tag->{liblibrarian}); >+ >+ my $mts = $marc_tag_structure_rs->find('', $tag->{tagfield}); >+ if ($mts) { >+ say "Field already exists: " . $tag->{tagfield}; >+ if ($force) { >+ say "Force mode is active, updating field " . $tag->{tagfield}; >+ $mts->update($tag); >+ } >+ next; >+ } >+ >+ say "Adding field " . $tag->{tagfield}; >+ $marc_tag_structure_rs->create($tag); >+} >+ >+my $subfield_defaults = $defaults->{subfield}; >+for my $subfield (@subfields) { >+ foreach my $key (keys %$subfield_defaults) { >+ unless (exists $subfield->{$key}) { >+ $subfield->{$key} = $subfield_defaults->{$key}; >+ } >+ } >+ $subfield->{liblibrarian} = t($subfield->{liblibrarian}); >+ >+ my $mss = $marc_subfield_structure_rs->find('', $subfield->{tagfield}, $subfield->{tagsubfield}); >+ if ($mss) { >+ say sprintf('Subfield already exists: %s$%s', $subfield->{tagfield}, $subfield->{tagsubfield}); >+ if ($force) { >+ say sprintf('Force mode is active, updating subfield %s$%s', $subfield->{tagfield}, $subfield->{tagsubfield}); >+ $mss->update($subfield); >+ } >+ next; >+ } >+ >+ say sprintf('Adding subfield %s$%s', $subfield->{tagfield}, $subfield->{tagsubfield}); >+ $marc_subfield_structure_rs->create($subfield); >+} >+ >+for my $authtype (@$authtypes) { >+ $authtype->{authtypetext} = t($authtype->{authtypetext}); >+ >+ my $at = $auth_type_rs->find($authtype->{authtypecode}); >+ if ($at) { >+ say "Authority type already exists: " . $authtype->{authtypecode}; >+ if ($force) { >+ say "Force mode is active, updating authority type " . $authtype->{authtypecode}; >+ $at->update($authtype); >+ } >+ next; >+ } >+ >+ say "Adding authority type " . $authtype->{authtypecode}; >+ $auth_type_rs->create($authtype); >+} >+ >+my $authtag_defaults = $defaults->{authtag}; >+for my $authtag (@authtags) { >+ foreach my $key (keys %$authtag_defaults) { >+ unless (exists $authtag->{$key}) { >+ $authtag->{$key} = $authtag_defaults->{$key}; >+ } >+ } >+ $authtag->{liblibrarian} = t($authtag->{liblibrarian}); >+ >+ my $ats = $auth_tag_structure_rs->find($authtag->{authtypecode}, $authtag->{tagfield}); >+ if ($ats) { >+ say sprintf('Auth field already exists: %s (%s)', $authtag->{tagfield}, $authtag->{authtypecode}); >+ if ($force) { >+ say sprintf('Force mode is active, updating auth field %s (%s)', $authtag->{tagfield}, $authtag->{authtypecode}); >+ $ats->update($authtag); >+ } >+ next; >+ } >+ >+ say sprintf('Adding auth field %s (%s)', $authtag->{tagfield}, $authtag->{authtypecode}); >+ $auth_tag_structure_rs->create($authtag); >+} >+ >+my $authsubfield_defaults = $defaults->{authsubfield}; >+for my $authsubfield (@authsubfields) { >+ foreach my $key (keys %$authsubfield_defaults) { >+ unless (exists $authsubfield->{$key}) { >+ $authsubfield->{$key} = $authsubfield_defaults->{$key}; >+ } >+ } >+ $authsubfield->{liblibrarian} = t($authsubfield->{liblibrarian}); >+ >+ my $ass = $auth_subfield_structure_rs->find($authsubfield->{authtypecode}, $authsubfield->{tagfield}, $authsubfield->{tagsubfield}); >+ if ($ass) { >+ say sprintf('Auth subfield already exists: %s$%s (%s)', $authsubfield->{tagfield}, $authsubfield->{tagsubfield}, $authsubfield->{authtypecode}); >+ if ($force) { >+ say sprintf('Force mode is active, updating auth subfield %s$%s (%s)', $authsubfield->{tagfield}, $authsubfield->{tagsubfield}, $authsubfield->{authtypecode}); >+ $ass->update($authsubfield); >+ } >+ next; >+ } >+ >+ say sprintf('Adding auth subfield %s$%s (%s)', $authsubfield->{tagfield}, $authsubfield->{tagsubfield}, $authsubfield->{authtypecode}); >+ $auth_subfield_structure_rs->create($authsubfield); >+} >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20434
:
93415
|
93416
|
93417
|
93418
|
93419
|
93420
|
93421
|
93422
|
93423
|
93424
|
93425
|
93426
|
93427
|
93428
|
93429
|
93430
|
93431
|
93432
|
93433
|
93434
|
93435
|
93436
|
93437
|
93438
|
93449
|
93614
|
93658
|
93683
|
93684
|
93685
|
93686
|
93687
|
93688
|
93689
|
93690
|
93691
|
93692
|
93693
|
93694
|
93695
|
93696
|
93698
|
93701
|
93702
|
93703
|
93704
|
93705
|
93706
|
93707
|
93708
|
93709
|
93710
|
93711
|
93712
|
94040
|
94045
|
94046
|
94047
|
94048
|
94049
|
94050
|
94051
|
94052
|
94053
|
94054
|
94055
|
94056
|
94057
|
94058
|
94059
|
94060
|
94061
|
94062
|
94063
|
94064
|
94065
|
94066
|
94067
| 94068 |
94069
|
94070
|
94071
|
94072