Bugzilla – Attachment 69646 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: Use raw SQL queries instead for the update DB entry
Bug-19096-Use-raw-SQL-queries-instead-for-the-upda.patch (text/plain), 5.01 KB, created by
Jonathan Druart
on 2017-12-08 14:29:48 UTC
(
hide
)
Description:
Bug 19096: Use raw SQL queries instead for the update DB entry
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-12-08 14:29:48 UTC
Size:
5.01 KB
patch
obsolete
>From 8761a994808c7b0ad922585fef18a34923f45213 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 8 Dec 2017 10:50:51 -0300 >Subject: [PATCH] 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. >--- > Koha/Util/Dbrev.pm | 84 +++++++++++++++++++++++++++++++++++------------------- > 1 file changed, 55 insertions(+), 29 deletions(-) > >diff --git a/Koha/Util/Dbrev.pm b/Koha/Util/Dbrev.pm >index 7346558aa5..db5ada15cd 100644 >--- a/Koha/Util/Dbrev.pm >+++ b/Koha/Util/Dbrev.pm >@@ -22,9 +22,8 @@ package Koha::Util::Dbrev; > > use Modern::Perl; > >-use Koha::BiblioFrameworks; >+use C4::Context; > use Koha::Caches; >-use Koha::MarcSubfieldStructures; > > =head1 NAME > >@@ -54,19 +53,40 @@ The routines in this modules are called in OO style as class methods. > sub sync_kohafield { > my ( $class ) = @_; > >+ my $dbh = C4::Context->dbh; >+ > # Clear the destination frameworks first >- Koha::MarcSubfieldStructures->search({ frameworkcode => { '>', q{} }, kohafield => { '>', q{} } })->update({ kohafield => undef }); >+ $dbh->do(q| >+ UPDATE marc_subfield_structure >+ SET kohafield = NULL >+ WHERE frameworkcode > '' >+ AND Kohafield > '' >+ |); > > # Now copy from Default >- my $rs = Koha::MarcSubfieldStructures->search({ frameworkcode => q{}, kohafield => { '>', q{} } }); >- while( my $rec = $rs->next ) { >- Koha::MarcSubfieldStructures->search({ frameworkcode => { '>', q{} }, tagfield => $rec->tagfield, tagsubfield => $rec->tagsubfield })->update({ kohafield => $rec->kohafield }); >+ 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} ); > } > >+ my @frameworkcodes = $dbh->selectall_arrayref(q| > # Clear the cache >- my @fw = Koha::BiblioFrameworks->search({ frameworkcode => { '>', q{} } })->get_column('frameworkcode'); >- foreach( @fw ) { >- Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$_" ); >+ 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-"); > } >@@ -84,29 +104,35 @@ sub sync_kohafield { > =cut > > sub get_kohafield_exceptions { >- my ( $class, $params ) = @_; >- >- # Too bad that DBIx is not very helpful here >- my $default = Koha::MarcSubfieldStructures->search({ >- frameworkcode => q{}, >- kohafield => { '>' => '' }, >- }); >- my $other = Koha::MarcSubfieldStructures->search({ >- frameworkcode => { '!=' => q{} }, >- }, { order_by => { -asc => [ qw/tagfield tagsubfield/ ] } }); >- >- # Compare >- my @return; >- while( my $rec = $other->next ) { >- my @tags = ( $rec->tagfield, $rec->tagsubfield ); >- my $defa = $default->find( q{}, @tags ); >- if( $rec->kohafield ) { >- push @return, [ $rec->frameworkcode, @tags, $rec->kohafield ] if !$defa || !$defa->kohafield || $defa->kohafield ne $rec->kohafield; >+ my ( $class ) = @_; >+ >+ my $dbh = C4::Context->dbh; >+ my $msss = $dbh->selectall_arrayref(q| >+ SELECT kohafield, tagfield, tagsubfield >+ 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, [ $mss->{frameworkcode}, $mss->{tagfield}, $mss->{tagsubfield}, $mss->{kohafield} ] if not $default_kohafield or $default_kohafield ne $mss->{kohafield}; > } else { >- push @return, [ $rec->frameworkcode, @tags, q{} ] if $defa && $defa->kohafield; >+ push @exceptions, [ $mss->{frameworkcode}, $mss->{tagfield}, $mss->{tagsubfield}, q{} ] if $default_kohafield; > } > } >- return \@return; >+ return \@exceptions; > } > > =head1 AUTHOR >-- >2.11.0
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