Browse Source

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_confirmed
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.

This patch is adapted from the original patch made by Olli-Antti
Kivilahti <olli-antti.kivilahti@jns.fi>.

Signed-off-by: Johanna Raisa <johanna.raisa@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Joonas Kylmälä 3 years ago
committed by Martin Renvoize
parent
commit
9c0dc6efff
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 3
      Koha/SearchEngine/Elasticsearch.pm
  2. 2
      admin/searchengine/elasticsearch/mappings.pl

3
Koha/SearchEngine/Elasticsearch.pm

@ -296,6 +296,9 @@ sub reset_elasticsearch_mappings {
my ( $self ) = @_;
my $indexes = $self->_load_elasticsearch_mappings();
Koha::SearchMarcMaps->delete;
Koha::SearchFields->delete;
while ( my ( $index_name, $fields ) = each %$indexes ) {
while ( my ( $field_name, $data ) = each %$fields ) {

2
admin/searchengine/elasticsearch/mappings.pl

@ -166,8 +166,6 @@ if ( $op eq 'edit' ) {
}
}
elsif( $op eq 'reset_confirmed' ) {
Koha::SearchMarcMaps->delete;
Koha::SearchFields->delete;
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
$clear_cache->();
push @messages, { type => 'message', code => 'success_on_reset' };

Loading…
Cancel
Save