Bug 39526: Do not insert the pref if renamed

The upgrade DB must be idempotent
if run twice, the second pass fails with
DBI Exception: DBD::mysql::db do failed: Duplicate entry 'ElasticsearchPreventAutoTruncate' for key 'PRIMARY' at /kohadevbox/koha/C4/Installer.pm line 825

We should not insert the pref if it has been renamed already.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2025-09-22 14:56:22 +02:00 committed by Lucas Gass
parent 071b6322c7
commit 6d52128345
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 10 additions and 4 deletions

View File

@ -6,12 +6,18 @@ return {
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
$dbh->do(
q{
my ($pref_exists) = $dbh->selectrow_array(
q{SELECT COUNT(*) FROM systempreferences WHERE variable = 'ElasticsearchPreventAutoTruncate'});
# The pref is renamed in 250600017.pl, do not insert it if it has been renamed already
unless ($pref_exists) {
$dbh->do(
q{
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` )
VALUES ('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')
}
);
say $out "Added new system preference 'ESPreventAutoTruncate'";
);
say $out "Added new system preference 'ESPreventAutoTruncate'";
}
},
};