Bugzilla – Attachment 69338 Details for
Bug 17885
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings throws DBD::mysql Duplicate entry exceptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17885 - Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings throws DBD::mysql Duplicate entry exceptions
Bug-17885---KohaSearchEngineElasticsearch-resetela.patch (text/plain), 3.13 KB, created by
David Bourgault
on 2017-11-24 19:31:50 UTC
(
hide
)
Description:
Bug 17885 - Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings throws DBD::mysql Duplicate entry exceptions
Filename:
MIME Type:
Creator:
David Bourgault
Created:
2017-11-24 19:31:50 UTC
Size:
3.13 KB
patch
obsolete
>From 0e710941fc824adf81ada998f6f0e127ca6088c8 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Fri, 13 Jan 2017 12:34:14 +0200 >Subject: [PATCH] Bug 17885 - > Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings throws > DBD::mysql Duplicate entry exceptions > >When executing Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings() >against populated search engine mappings tables, one gets this exception: > >DBD::mysql::st execute failed: Duplicate entry '388-73' for key 'PRIMARY' >[for Statement \"INSERT INTO `search_marc_to_field` ( `facet`, `search_field_id`, > `search_marc_map_id`, `sort`, `suggestible`) VALUES ( ?, ?, ?, ?, ? )\" with ParamValues: >0='', 1='73', 2='388', 3=undef, 4=''] at /usr/share/perl5/DBIx/Class/Storage/DBI.pm >line 1834.\nDBIx::Class::Storage::DBI::_dbh_execute(): Duplicate entry '388-73' for key >'PRIMARY' at /home/koha/Koha/Koha/SearchField.pm line 38" > >This patch fixes this, by first deleting all entries, then adding the default ones. > >If a subroutine says reset_elasticsearch_mappings(), I expect it to reset the elasticsearch >mappings without errors. >When writing tests it is better to call that one subroutine reset_elasticsearch_mappings >instead of the bunch of code in admin/searchengine/elasticsearch/mappings.pl?op=reset&i_know_what_i_am_doing=1 >Also this promotes code reuse. > >TEST PLAN: > >a. perl -e 'use Koha::SearchEngine::Elasticsearch; Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings' >b. Run misc/devel/populate_db.pl on an already populated DB and you eventually face this problem. > >After this patch, >step a. works. > >Signed-off-by: David Bourgault <david.bourgault@inlibro.com> >--- > Koha/SearchEngine/Elasticsearch.pm | 7 +++++++ > admin/searchengine/elasticsearch/mappings.pl | 1 - > 2 files changed, 7 insertions(+), 1 deletion(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index de4b18c..7cf2570 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -274,10 +274,17 @@ sub _elasticsearch_mapping_for_default { > }; > } > >+=head2 reset_elasticsearch_mappings >+ >+Deletes all search mappings and adds the default search mappings >+ >+=cut >+ > sub reset_elasticsearch_mappings { > my $mappings_yaml = C4::Context->config('intranetdir') . '/admin/searchengine/elasticsearch/mappings.yaml'; > my $indexes = LoadFile( $mappings_yaml ); > >+ Koha::SearchMarcMaps->search->delete; > while ( my ( $index_name, $fields ) = each %$indexes ) { > while ( my ( $field_name, $data ) = each %$fields ) { > my $field_type = $data->{type}; >diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl >index 7d63002..6d4b303 100755 >--- a/admin/searchengine/elasticsearch/mappings.pl >+++ b/admin/searchengine/elasticsearch/mappings.pl >@@ -101,7 +101,6 @@ elsif( $op eq 'reset' ) { > # TODO Move this feature to the interface > my $sure = $input->param('i_know_what_i_am_doing'); > if ( $sure ) { >- Koha::SearchMarcMaps->search->delete; > Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; > } > } >-- >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 17885
:
58825
|
58940
|
58941
|
69338
|
78327
|
91308
|
97198