use Koha::Exceptions::Elasticsearch;
use Koha::SearchFields;
use Koha::SearchMarcMaps;
+use Koha::Caches;
use C4::Heading;
use Carp;
}
}
}
+
+ my $cache = Koha::Caches->get_instance();
+ $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
+ $cache->clear_from_cache('elasticsearch_search_fields_opac');
+
+ # FIXME return the mappings?
}
# This overrides the accessor provided by Class::Accessor so that if
}
};
-my $cache = Koha::Caches->get_instance();
-my $clear_cache = sub {
- $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
- $cache->clear_from_cache('elasticsearch_search_fields_opac');
-};
-
if ( $op eq 'edit' ) {
$schema->storage->txn_begin;
} else {
push @messages, { type => 'message', code => 'success_on_update' };
$schema->storage->txn_commit;
- $clear_cache->();
+
+ my $cache = Koha::Caches->get_instance();
+ $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
+ $cache->clear_from_cache('elasticsearch_search_fields_opac');
+
$update_mappings->();
}
}
elsif( $op eq 'reset_confirmed' ) {
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
- $clear_cache->();
push @messages, { type => 'message', code => 'success_on_reset' };
}
elsif( $op eq 'reset_confirm' ) {
use Koha::BiblioUtils;
use Koha::SearchEngine::Elasticsearch;
use Koha::SearchEngine::Elasticsearch::Indexer;
-use Koha::Caches;
use MARC::Field;
use MARC::Record;
use Modern::Perl;
if ($reset){
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
- my $cache = Koha::Caches->get_instance();
- $cache->clear_from_cache('elasticsearch_search_fields_staff_client');
- $cache->clear_from_cache('elasticsearch_search_fields_opac');
$delete = 1;
}
use Modern::Perl;
-use Test::More tests => 4;
+use Test::More tests => 5;
use Test::MockModule;
use Koha::Database;
+use Koha::Caches;
my $indexes = {
'authorities' => {
Koha::SearchMarcMaps->search->delete;
$schema->resultset('SearchMarcToField')->search->delete;
+
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
+my $cache = Koha::Caches->get_instance();
+is( $cache->get_from_cache('elasticsearch_search_fields_staff_client'), undef, 'Cache has been flushed by reset_elasticsearch_mappings' );
+
my $search_fields = Koha::SearchFields->search({});
is($search_fields->count, 2, 'There is 2 search fields after reset');
is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
$schema->storage->txn_rollback;
+
+$cache = Koha::Caches->get_instance();
+$cache->clear_from_cache('elasticsearch_search_fields_staff_client');
+$cache->clear_from_cache('elasticsearch_search_fields_opac');