[Koha-bugs] [Bug 17885] Koha::SearchEngine::Elasticsearch-> reset_elasticsearch_mappings throws DBD::mysql Duplicate entry exceptions

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Jan 13 11:52:11 CET 2017


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17885

Olli-Antti Kivilahti <olli-antti.kivilahti at jns.fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #58825|0                           |1
        is obsolete|                            |

--- Comment #8 from Olli-Antti Kivilahti <olli-antti.kivilahti at jns.fi> ---
Created attachment 58940
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=58940&action=edit
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.

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list