View | Details | Raw Unified | Return to bug 23137
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch.pm (+7 lines)
Lines 26-31 use Koha::Exceptions::Config; Link Here
26
use Koha::Exceptions::Elasticsearch;
26
use Koha::Exceptions::Elasticsearch;
27
use Koha::SearchFields;
27
use Koha::SearchFields;
28
use Koha::SearchMarcMaps;
28
use Koha::SearchMarcMaps;
29
use Koha::Caches;
29
use C4::Heading;
30
use C4::Heading;
30
31
31
use Carp;
32
use Carp;
Lines 382-387 sub reset_elasticsearch_mappings { Link Here
382
            }
383
            }
383
        }
384
        }
384
    }
385
    }
386
387
    my $cache = Koha::Caches->get_instance();
388
    $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
389
    $cache->clear_from_cache('elasticsearch_search_fields_opac');
390
391
    # FIXME return the mappings?
385
}
392
}
386
393
387
# This overrides the accessor provided by Class::Accessor so that if
394
# This overrides the accessor provided by Class::Accessor so that if
(-)a/admin/searchengine/elasticsearch/mappings.pl (-8 / +5 lines)
Lines 78-89 my $update_mappings = sub { Link Here
78
    }
78
    }
79
};
79
};
80
80
81
my $cache = Koha::Caches->get_instance();
82
my $clear_cache = sub {
83
    $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
84
    $cache->clear_from_cache('elasticsearch_search_fields_opac');
85
};
86
87
if ( $op eq 'edit' ) {
81
if ( $op eq 'edit' ) {
88
82
89
    $schema->storage->txn_begin;
83
    $schema->storage->txn_begin;
Lines 170-182 if ( $op eq 'edit' ) { Link Here
170
    } else {
164
    } else {
171
        push @messages, { type => 'message', code => 'success_on_update' };
165
        push @messages, { type => 'message', code => 'success_on_update' };
172
        $schema->storage->txn_commit;
166
        $schema->storage->txn_commit;
173
        $clear_cache->();
167
168
        my $cache = Koha::Caches->get_instance();
169
        $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
170
        $cache->clear_from_cache('elasticsearch_search_fields_opac');
171
174
        $update_mappings->();
172
        $update_mappings->();
175
    }
173
    }
176
}
174
}
177
elsif( $op eq 'reset_confirmed' ) {
175
elsif( $op eq 'reset_confirmed' ) {
178
    Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
176
    Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
179
    $clear_cache->();
180
    push @messages, { type => 'message', code => 'success_on_reset' };
177
    push @messages, { type => 'message', code => 'success_on_reset' };
181
}
178
}
182
elsif( $op eq 'reset_confirm' ) {
179
elsif( $op eq 'reset_confirm' ) {
(-)a/misc/search_tools/rebuild_elasticsearch.pl (-4 lines)
Lines 112-118 use Koha::MetadataRecord::Authority; Link Here
112
use Koha::BiblioUtils;
112
use Koha::BiblioUtils;
113
use Koha::SearchEngine::Elasticsearch;
113
use Koha::SearchEngine::Elasticsearch;
114
use Koha::SearchEngine::Elasticsearch::Indexer;
114
use Koha::SearchEngine::Elasticsearch::Indexer;
115
use Koha::Caches;
116
use MARC::Field;
115
use MARC::Field;
117
use MARC::Record;
116
use MARC::Record;
118
use Modern::Perl;
117
use Modern::Perl;
Lines 156-164 _sanity_check(); Link Here
156
155
157
if ($reset){
156
if ($reset){
158
    Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
157
    Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
159
    my $cache = Koha::Caches->get_instance();
160
    $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
161
    $cache->clear_from_cache('elasticsearch_search_fields_opac');
162
    $delete = 1;
158
    $delete = 1;
163
}
159
}
164
160
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t (-2 / +10 lines)
Lines 17-26 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 5;
21
use Test::MockModule;
21
use Test::MockModule;
22
22
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::Caches;
24
25
25
my $indexes = {
26
my $indexes = {
26
    'authorities' => {
27
    'authorities' => {
Lines 54-61 Koha::SearchFields->search->delete; Link Here
54
Koha::SearchMarcMaps->search->delete;
55
Koha::SearchMarcMaps->search->delete;
55
$schema->resultset('SearchMarcToField')->search->delete;
56
$schema->resultset('SearchMarcToField')->search->delete;
56
57
58
57
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
59
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
58
60
61
my $cache = Koha::Caches->get_instance();
62
is( $cache->get_from_cache('elasticsearch_search_fields_staff_client'), undef, 'Cache has been flushed by reset_elasticsearch_mappings' );
63
59
my $search_fields = Koha::SearchFields->search({});
64
my $search_fields = Koha::SearchFields->search({});
60
is($search_fields->count, 2, 'There is 2 search fields after reset');
65
is($search_fields->count, 2, 'There is 2 search fields after reset');
61
66
Lines 66-68 my $title_sf = Koha::SearchFields->search({ name => 'title' })->next; Link Here
66
is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
71
is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
67
72
68
$schema->storage->txn_rollback;
73
$schema->storage->txn_rollback;
69
- 
74
75
$cache = Koha::Caches->get_instance();
76
$cache->clear_from_cache('elasticsearch_search_fields_staff_client');
77
$cache->clear_from_cache('elasticsearch_search_fields_opac');

Return to bug 23137