Bugzilla – Attachment 52226 Details for
Bug 16708
ElasticSearch - Fix authority reindexing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16708: Fix authority reindex for ElasticSearch
Bug-16708-Fix-authority-reindex-for-ElasticSearch.patch (text/plain), 5.91 KB, created by
Jonathan Druart
on 2016-06-10 13:27:10 UTC
(
hide
)
Description:
Bug 16708: Fix authority reindex for ElasticSearch
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-06-10 13:27:10 UTC
Size:
5.91 KB
patch
obsolete
>From c32c2c155a781d5c8a2894786465128fd92645d6 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 10 Jun 2016 14:23:08 +0100 >Subject: [PATCH] Bug 16708: Fix authority reindex for ElasticSearch > >The changes made to Koha::Authority has not been correctly fixed. >The code of Koha::Authority has been moved bo >Koha::MetadataRecord::Authority by bug 15380. > >Test plan: > perl misc/search_tools/rebuild_elastic_search.pl -a -v >should success >--- > Koha/Authority.pm | 50 ------------------------- > Koha/MetadataRecord/Authority.pm | 57 +++++++++++++++++++++++++++-- > misc/search_tools/rebuild_elastic_search.pl | 6 +-- > 3 files changed, 57 insertions(+), 56 deletions(-) > >diff --git a/Koha/Authority.pm b/Koha/Authority.pm >index fec63d3..b533fd7 100644 >--- a/Koha/Authority.pm >+++ b/Koha/Authority.pm >@@ -45,54 +45,4 @@ sub _type { > return 'AuthHeader'; > } > >-=head2 get_all_authorities_iterator >- >- my $it = Koha::Authority->get_all_authorities_iterator(); >- >-This will provide an iterator object that will, one by one, provide the >-Koha::Authority of each authority. >- >-The iterator is a Koha::MetadataIterator object. >- >-=cut >- >-sub get_all_authorities_iterator { >- my $database = Koha::Database->new(); >- my $schema = $database->schema(); >- my $rs = >- $schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } }, >- { columns => [qw/ authid authtypecode marcxml /] } ); >- my $next_func = sub { >- my $row = $rs->next(); >- return if !$row; >- my $authid = $row->authid; >- my $authtypecode = $row->authtypecode; >- my $marcxml = $row->marcxml; >- >- my $record = eval { >- MARC::Record->new_from_xml( >- StripNonXmlChars($marcxml), >- 'UTF-8', >- ( >- C4::Context->preference("marcflavour") eq "UNIMARC" >- ? "UNIMARCAUTH" >- : C4::Context->preference("marcflavour") >- ) >- ); >- }; >- confess $@ if ($@); >- $record->encoding('UTF-8'); >- >- # I'm not sure why we don't use the authtypecode from the database, >- # but this is how the original code does it. >- require C4::AuthoritiesMarc; >- $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record); >- >- my $auth = __PACKAGE__->new( $record, $authid, $authtypecode ); >- >- return $auth; >- }; >- return Koha::MetadataIterator->new($next_func); >-} >- > 1; >diff --git a/Koha/MetadataRecord/Authority.pm b/Koha/MetadataRecord/Authority.pm >index da218af..9adf320 100644 >--- a/Koha/MetadataRecord/Authority.pm >+++ b/Koha/MetadataRecord/Authority.pm >@@ -52,13 +52,14 @@ Create a new Koha::MetadataRecord::Authority object based on the provided record > =cut > > sub new { >- my $class = shift; >- my $record = shift; >+ my ( $class, $record, $params ) = @_; > >+ $params //= {}; > my $self = $class->SUPER::new( > { > 'record' => $record, >- 'schema' => lc C4::Context->preference("marcflavour") >+ 'schema' => lc C4::Context->preference("marcflavour"), >+ %$params, > } > ); > >@@ -154,4 +155,54 @@ sub authorized_heading { > return; > } > >+=head2 get_all_authorities_iterator >+ >+ my $it = Koha::Authority->get_all_authorities_iterator(); >+ >+This will provide an iterator object that will, one by one, provide the >+Koha::Authority of each authority. >+ >+The iterator is a Koha::MetadataIterator object. >+ >+=cut >+ >+sub get_all_authorities_iterator { >+ my $database = Koha::Database->new(); >+ my $schema = $database->schema(); >+ my $rs = >+ $schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } }, >+ { columns => [qw/ authid authtypecode marcxml /] } ); >+ my $next_func = sub { >+ my $row = $rs->next(); >+ return if !$row; >+ my $authid = $row->authid; >+ my $authtypecode = $row->authtypecode; >+ my $marcxml = $row->marcxml; >+ >+ my $record = eval { >+ MARC::Record->new_from_xml( >+ StripNonXmlChars($marcxml), >+ 'UTF-8', >+ ( >+ C4::Context->preference("marcflavour") eq "UNIMARC" >+ ? "UNIMARCAUTH" >+ : C4::Context->preference("marcflavour") >+ ) >+ ); >+ }; >+ confess $@ if ($@); >+ $record->encoding('UTF-8'); >+ >+ # I'm not sure why we don't use the authtypecode from the database, >+ # but this is how the original code does it. >+ require C4::AuthoritiesMarc; >+ $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record); >+ >+ my $auth = __PACKAGE__->new( $record, { authid => $authid, id => $authid, authtypecode => $authtypecode } ); >+ >+ return $auth; >+ }; >+ return Koha::MetadataIterator->new($next_func); >+} >+ > 1; >diff --git a/misc/search_tools/rebuild_elastic_search.pl b/misc/search_tools/rebuild_elastic_search.pl >index af536f0..66d0cbb 100755 >--- a/misc/search_tools/rebuild_elastic_search.pl >+++ b/misc/search_tools/rebuild_elastic_search.pl >@@ -84,7 +84,7 @@ Full documentation. > use autodie; > use Getopt::Long; > use C4::Context; >-use Koha::Authority; >+use Koha::MetadataRecord::Authority; > use Koha::BiblioUtils; > use Koha::ElasticSearch::Indexer; > use MARC::Field; >@@ -144,11 +144,11 @@ if ($index_authorities) { > $next = sub { > my $r = shift @biblionumbers; > return () unless defined $r; >- my $a = Koha::Authority->get_from_authid($r); >+ my $a = Koha::MetadataRecord::Authority->get_from_authid($r); > return ($r, $a->record); > }; > } else { >- my $records = Koha::Authority->get_all_authorities_iterator(); >+ my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator(); > $next = sub { > $records->next(); > } >-- >2.8.1
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 16708
:
52226
|
52695
|
52696