From 33abe9392a502b0e9146c13c112305c95c617fe3 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Wed, 23 Apr 2025 09:25:04 +0000 Subject: [PATCH] Bug 39526: Unify syspref variable names to Elasticsearch We currently have a sysprefs named "Elasticsearch*" and some name only "ES*". This patch unifies the names to always start with "Elasticsearch". Test plan: * Start koha-testing-docker, open the staff interface and go to Administration. * Enter "Elasticsearch" into the System Preference search box and click "search" * You will find a bunch of sysprefs * Now search for "ESPreventAutoTruncate", which should find one match * Apply the patch * run (in ktd) the script `updatedatabase` * You should see output like DEV atomic update /kohadevbox/koha/installer/data/mysql/atomicupdate/bug_39526_unify_syspref_variable_names_for_elasticsearch.pl [09:35:03]: Bug 39526 - Unify system preference variable names for Elasticsearch Renamed system preference 'ES..' to 'Elasticsearch..' * Go again to to sysprefs and search again for "Elasticsearch" * you should now find "ElasticsearchPreventAutoTruncate" * Search for "ESPreventAutoTruncate", which should show "No system preferences matched your search for .." (and the list of ALL sysprefs) Please note that the qa script explains about installer/data/mysql/mandatory/sysprefs.sql, but the last line is not touched by this patch, so not sure why this happens. Sponsored-by: HKS3 Signed-off-by: Roman Dolny --- .../SearchEngine/Elasticsearch/QueryBuilder.pm | 4 ++-- ...syspref_variable_names_for_elasticsearch.pl | 18 ++++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 4 ++-- .../modules/admin/preferences/searching.pref | 2 +- .../SearchEngine/Elasticsearch/QueryBuilder.t | 10 +++++----- 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_39526_unify_syspref_variable_names_for_elasticsearch.pl diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index c1b5449113..d91b096453 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1402,7 +1402,7 @@ sub _is_safe_to_auto_truncate { # Do not auto truncate fields that should not be auto truncated, # primarily various types of identifiers, above all record identifiers. # Other search fields that should not be auto truncated can be defined - # with ESPreventAutoTruncate syspref. + # with ElasticsearchPreventAutoTruncate syspref. my %do_not_autotruncate_fields; my $cache = Koha::Caches->get_instance(); my $cache_key = 'elasticsearch_search_do_not_autotruncate'; @@ -1428,7 +1428,7 @@ sub _is_safe_to_auto_truncate { # processing of the syspref is done outside cache since the systempreference # can be modified and the modification should be reflected in the # $do_not_autotruncate_fields array - my $prevent_autotruncate = C4::Context->preference('ESPreventAutoTruncate'); + my $prevent_autotruncate = C4::Context->preference('ElasticsearchPreventAutoTruncate'); for my $field ( split( /\s*[,;|]\s*/, $prevent_autotruncate ) ) { $do_not_autotruncate_fields{$field} = 1; } diff --git a/installer/data/mysql/atomicupdate/bug_39526_unify_syspref_variable_names_for_elasticsearch.pl b/installer/data/mysql/atomicupdate/bug_39526_unify_syspref_variable_names_for_elasticsearch.pl new file mode 100755 index 0000000000..0a9cb7e148 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_39526_unify_syspref_variable_names_for_elasticsearch.pl @@ -0,0 +1,18 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "39526", + description => "Unify system preference variable names for Elasticsearch", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Do you stuffs here + $dbh->do( + q{update systempreferences set variable = REGEXP_REPLACE(variable, '^ES', 'Elasticsearch') where variable like 'ES%'} + ); + + say $out "Renamed system preference 'ES..' to 'Elasticsearch..'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index ab0bc8ee80..c6bafd9957 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -236,6 +236,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL), ('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL), ('ElasticsearchMARCFormat', 'base64ISO2709', 'base64ISO2709|ARRAY', 'Elasticsearch MARC format. ISO2709 format is recommended as it is faster and takes less space, whereas array is searchable.', 'Choice'), +('ElasticsearchPreventAutoTruncate', 'barcode|control-number|control-number-identifier|date-of-acquisition|date-of-publication|date-time-last-modified|identifier-standard|isbn|issn|itype|lc-card-number|number-local-acquisition|other-control-number|record-control-number', NULL, 'List of searchfields (separated by | or ,) that should not be autotruncated by Elasticsearch even if QueryAutoTruncate is set to Yes', 'free'), ('EmailAddressForPatronRegistrations', '', '', ' If you choose EmailAddressForPatronRegistrations you have to enter a valid email address: ', 'free'), ('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'), ('EmailFieldPrecedence','email|emailpro|B_email','','Ordered list of patron email fields to use when AutoEmailPrimaryAddress is set to first valid','multiple'), @@ -261,7 +262,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ERMProviderEbscoApiKey', '', '', 'API key for EBSCO', 'free'), ('ERMProviderEbscoCustomerID', '', '', 'Customer ID for EBSCO', 'free'), ('ERMProviders', 'local', 'local|ebsco', 'Set the providers for the ERM module', 'Choice'), -('ESPreventAutoTruncate', 'barcode|control-number|control-number-identifier|date-of-acquisition|date-of-publication|date-time-last-modified|identifier-standard|isbn|issn|itype|lc-card-number|number-local-acquisition|other-control-number|record-control-number', NULL, 'List of searchfields (separated by | or ,) that should not be autotruncated by Elasticsearch even if QueryAutoTruncate is set to Yes', 'free'), ('ExcludeHolidaysFromMaxPickUpDelay', '0', NULL, 'If ON, reserves max pickup delay takes into accountthe closed days.', 'YesNo'), ('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'), ('ExpireReservesAutoFill','0',NULL,'Automatically fill the next hold with a automatically canceled expired waiting hold.','YesNo'), @@ -879,4 +879,4 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'), ('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'), ('z3950Status','','','This syspref allows to define custom YAML based rules for marking items unavailable in z3950 results.','Textarea') -; \ No newline at end of file +; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index b9bbf80083..cad582d18e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -104,7 +104,7 @@ Searching: - "the option for staff with permission to create/edit custom saved search filters." - - "List of search fields (separated by | or ,) that should not be autotruncated by Elasticsearch even if QueryAutoTruncate is set to 'Yes':" - - pref: ESPreventAutoTruncate + - pref: ElasticsearchPreventAutoTruncate class: long - - pref: SearchCancelledAndInvalidISBNandISSN diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 79380ee7c1..8db8439ab1 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -419,8 +419,8 @@ subtest 'build_query tests' => sub { "all quoted strings are unaltered if more than one in query" ); - # Reset ESPreventAutoTruncate syspref - t::lib::Mocks::mock_preference( 'ESPreventAutoTruncate', '' ); + # Reset ElasticsearchPreventAutoTruncate syspref + t::lib::Mocks::mock_preference( 'ElasticsearchPreventAutoTruncate', '' ); ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] ); is( @@ -457,14 +457,14 @@ subtest 'build_query tests' => sub { "query of specific field including period and quoted is not truncated, field name is converted to lower case" ); - # Set ESPreventAutoTruncate syspref - t::lib::Mocks::mock_preference( 'ESPreventAutoTruncate', 'barcode' ); + # Set ElasticsearchPreventAutoTruncate syspref + t::lib::Mocks::mock_preference( 'ElasticsearchPreventAutoTruncate', 'barcode' ); ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] ); is( $query->{query}{query_string}{query}, '(barcode:123456)', - "query of specific field excluded by ESPreventAutoTruncate is not truncated" + "query of specific field excluded by ElasticsearchPreventAutoTruncate is not truncated" ); ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:123456'] ); -- 2.39.5