Bugzilla – Attachment 69681 Details for
Bug 19096
Koha to MARC mappings (Part 2): Make Default authoritative
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19096: Add dbrev to sync kohafield in all frameworks
Bug-19096-Add-dbrev-to-sync-kohafield-in-all-frame.patch (text/plain), 9.13 KB, created by
Marcel de Rooy
on 2017-12-11 10:35:31 UTC
(
hide
)
Description:
Bug 19096: Add dbrev to sync kohafield in all frameworks
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-12-11 10:35:31 UTC
Size:
9.13 KB
patch
obsolete
>From ea106396041c830c49bafad75b20e81795b72cdf Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 17 Aug 2017 10:57:28 +0200 >Subject: [PATCH] Bug 19096: Add dbrev to sync kohafield in all frameworks >Content-Type: text/plain; charset=utf-8 > >Squashed the last four follow-ups into one patch. Instead of adding >two routines to Koha::MarcSubfieldStructures, and instead of moving >them to Koha::Util::Dbrev, we finally ended up with converting the >code to raw SQL queries (thx Jonathan). No need to 'pollute' the git >history with all this moving around. > >As Jonathan pointed out, there is a risk in using DBIx calls (with Koha >objects) while running database revisions. See also bug 17292 and >bug 19789. > >I tested the resulting db revision by adding a few fields to the Default >framework and adding deviating kohafields in other frameworks. And confirm >that it works as expected. > >Please read the remainder of this commit message in the light of the above: > >=== > >The dbrev will use two new routines in MarcSubfieldStructures: >[1] get_kohafield_exceptions is used to report deviating kohafields in > the additional frameworks, >[2] sync_kohafield is used to reset kohafield in the other frameworks to > the mapping in Default. > >Test plan: > >Unit test and database revision: >[1] Run t/db_dependent/Koha/MarcSubfieldStructures.t >[2] Verify that your Default 100a is mapped to biblio.author. Go to another > framework and clear the mapping via mysql command line: > UPDATE marc_subfield_structure SET kohafield=NULL WHERE frameworkcode=[your_framework] AND tagfield='100' AND tagsubfield='a'; >[3] Run the db revision. It should report that 100a was adjusted. >[4] Check in admin/marc_subfield_structure that your 100a is mapped to > biblio.author again in that framework. > >Additional interface testing (ensuring that the changes on this report do >not interfere with multiple mappings): >[5] Make two mappings for copyrightdate: 260c and 264a. And make two > mappings for biblioitems.pages: 300a and say 300g. Toggle with some > field values in those fields in the cataloging editor and verify the > contents of biblio.copyrightdate and biblioitems.pages. The former > should contain one year (due to additional logic) and the latter should > contain A | B if both fields are filled. > Remove the mapping for 300g. >[6] Set AcqCreateItem to ordering or placing. Verify that you can still > add or receive an order as usual. >[7] Add a mapping for itemcallnumber to 952f (this should remove the one > for coded_location_qualifier). This is very unusual but serves well in > testing multiple mappings for items. > Add or receive an order (fill 952f and 952o) with same and/or different > values. Verify the contents of items.callnumber. (Check with regular > item editor; see note.) > Do a similar edit in the regular item editor. > Note: You should expect to see A | B in both 952f and 925o if both > fields are filled with a different value. > Set items.coded_location_qualifier back to 952f in koha2marclinks. > > Note: When AcqCreateItem==ordering, you will not see A|B in the callno > field when adding an item on neworderempty.pl. But when you submit > the main form, addorder.pl is called. At that time an item is created > and you will see that A|B is in both fields (952f and 952o). > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Bug 19096: (QA follow-up) Move two routines out of Koha::MSS > >As requested by RM, this patch moves sync_kohafield and >get_kohafield_exceptions from Koha/MarcSubfieldStructures.pm. > >At this moment they are only used in a database revision; it is not clear >if they may be of use later on. > >In order to keep them in a module and not remove the unit tests, this >patch adds a Koha::Util module Dbrev.pm. It is now required in the atomic >update, but could be added in a use statement in updatedatabase.pl. > >Test plan: >[1] Run updatedatabase.pl >[2] Run t/db_dependent/Koha/MarcSubfieldStructures.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Bug 19096: Use raw SQL queries instead for the update DB entry > >I strongly thing we must not use C4 or Koha subroutine in the update DB >process, only sql queries. >Especially not DBIC Schema files as they will change. >For instance the update DB 17.12.00.00X is using a specific Koha::Schema::RS::MSS >representing the current schema, but in X months/years, this schema will change >and the ->search we used may failed. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Bug 19096: Move the sql queries to the update DB entry > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Amended: Print "Field 700$a" instead of "Field 700.a" in the dbrev. >--- > installer/data/mysql/atomicupdate/bug19096.perl | 94 +++++++++++++++++++++++++ > t/db_dependent/Koha/MarcSubfieldStructures.t | 1 - > 2 files changed, 94 insertions(+), 1 deletion(-) > create mode 100644 installer/data/mysql/atomicupdate/bug19096.perl > >diff --git a/installer/data/mysql/atomicupdate/bug19096.perl b/installer/data/mysql/atomicupdate/bug19096.perl >new file mode 100644 >index 0000000..c392fd6 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug19096.perl >@@ -0,0 +1,94 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $msss = $dbh->selectall_arrayref(q| >+ SELECT kohafield, tagfield, tagsubfield, frameworkcode >+ FROM marc_subfield_structure >+ WHERE frameworkcode != '' >+ |, { Slice => {} }); >+ >+ >+ my $sth = $dbh->prepare(q| >+ SELECT kohafield >+ FROM marc_subfield_structure >+ WHERE frameworkcode = '' >+ AND tagfield = ? >+ AND tagsubfield = ? >+ |); >+ >+ my @exceptions; >+ for my $mss ( @$msss ) { >+ $sth->execute($mss->{tagfield}, $mss->{tagsubfield} ); >+ my ( $default_kohafield ) = $sth->fetchrow_array(); >+ if( $mss->{kohafield} ) { >+ push @exceptions, { frameworkcode => $mss->{frameworkcode}, tagfield => $mss->{tagfield}, tagsubfield => $mss->{tagsubfield}, kohafield => $mss->{kohafield} } if not $default_kohafield or $default_kohafield ne $mss->{kohafield}; >+ } else { >+ push @exceptions, { frameworkcode => $mss->{frameworkcode}, tagfield => $mss->{tagfield}, tagsubfield => $mss->{tagsubfield}, kohafield => q{} } if $default_kohafield; >+ } >+ } >+ >+ if (@exceptions) { >+ print >+"WARNING: The Default framework is now considered as authoritative for Koha to MARC mappings. We have found that your additional frameworks contained " >+ . scalar(@exceptions) >+ . " mapping(s) that deviate from the standard mappings. Please look at the following list and consider if you need to add them again in Default (possibly as a second mapping).\n"; >+ for my $exception (@exceptions) { >+ print "Field " >+ . $exception->{tagfield} . '$' >+ . $exception->{tagsubfield} >+ . " in framework " >+ . $exception->{frameworkcode} . ': '; >+ if ( $exception->{kohafield} ) { >+ print "Mapping to " >+ . $exception->{kohafield} >+ . " has been adjusted.\n"; >+ } >+ else { >+ print "Mapping has been reset.\n"; >+ } >+ } >+ >+ # Sync kohafield >+ >+ # Clear the destination frameworks first >+ $dbh->do(q| >+ UPDATE marc_subfield_structure >+ SET kohafield = NULL >+ WHERE frameworkcode > '' >+ AND Kohafield > '' >+ |); >+ >+ # Now copy from Default >+ my $msss = $dbh->selectall_arrayref(q| >+ SELECT kohafield, tagfield, tagsubfield >+ FROM marc_subfield_structure >+ WHERE frameworkcode = '' >+ AND kohafield > '' >+ |, { Slice => {} }); >+ my $sth = $dbh->prepare(q| >+ UPDATE marc_subfield_structure >+ SET kohafield = ? >+ WHERE frameworkcode > '' >+ AND tagfield = ? >+ AND tagsubfield = ? >+ |); >+ for my $mss (@$msss) { >+ $sth->execute( $mss->{kohafield}, $mss->{tagfield}, >+ $mss->{tagsubfield} ); >+ } >+ >+ # Clear the cache >+ my @frameworkcodes = $dbh->selectall_arrayref(q| >+ SELECT frameworkcode FROM biblio_framework WHERE frameworkcode > '' >+ |); >+ for my $frameworkcode (@frameworkcodes) { >+ Koha::Caches->get_instance->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); >+ } >+ Koha::Caches->get_instance->clear_from_cache("default_value_for_mod_marc-"); >+ } >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 19096 - Make Default authoritative for Koha to MARC mappings)\n"; >+} >diff --git a/t/db_dependent/Koha/MarcSubfieldStructures.t b/t/db_dependent/Koha/MarcSubfieldStructures.t >index d65f4cc..7a755d9 100644 >--- a/t/db_dependent/Koha/MarcSubfieldStructures.t >+++ b/t/db_dependent/Koha/MarcSubfieldStructures.t >@@ -21,7 +21,6 @@ use Modern::Perl; > > use Test::More tests => 1; > >-use Koha::MarcSubfieldStructure; > use Koha::MarcSubfieldStructures; > use Koha::Database; > >-- >2.1.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 19096
:
66333
|
66334
|
66335
|
66336
|
66337
|
66338
|
66406
|
66407
|
66408
|
66409
|
66410
|
66411
|
67508
|
67509
|
67510
|
67511
|
67512
|
67513
|
67590
|
67591
|
67592
|
67593
|
67594
|
67595
|
68205
|
68206
|
68207
|
68208
|
68209
|
68210
|
68774
|
68775
|
68776
|
68777
|
68778
|
68779
|
69629
|
69646
|
69647
| 69681