Bug 41682: Sync DB and sysprefs.sql for new and upgraded installs

This patch removes the discrepancies and put in sync the
systempreferences table for new and upgraded installations.

Main changes:
* Set options to NULL when options=""
* Fix explanation when different
* Fix wrong order (some rows had options=explanation)
* Fix wrong type "Yes/No" => "YesNo"
* Remove StaffLoginBranchBasedOnIP: both StaffLoginLibraryBasedOnIP and
  StaffLoginBranchBasedOnIP are in the DB for upgraded installs
* Remove the 'showsql' from the test. If we need it back then it must be
  a maintenance script.
* Improve the tests:
  * Compare sysprefs.sql and the DB content for options, explanation and type
  * Catch type not defined
  * Catch incorrect YesNo values (must be 0 or 1)

Later:
* Add a C4::Installer sub to add new syspref:
  add_pref(
      {
          variable    => $variable,
          value       => $value,
          options     => $options,
          explanation => $explanation,
          type        => $type
      }
  );
* Clean 'type' and make it an ENUM
* Make it easy to run the test for devs (should be in xt but we need it
  in t/db_dependent for packages - FIXME?)
* Run the tests on upgraded installs on CI

Test plan:
0. Apply the "tests" patch only
1. prove it
=> It fails loudly
2. Apply the DB change and run updatedatabase, prove the tests
=> they pass
3. Test upgraded installs:
  * checkout v24.05.00 (the version we use for Jenkins'
    Koha_Main_MariaDB_update job)
  * reset_all
  * checkout the branch with this patchset
  * updatabase
  * prove t/db_dependent/check_sysprefs.t
  => Should be green

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2026-01-22 10:41:24 +01:00 committed by Lucas Gass
parent 42c2fc7dbf
commit 409c804bc1
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 538 additions and 393 deletions

View File

@ -0,0 +1,145 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
return {
bug_number => "41682",
description => "Fix syspref discrepancies between new and upgraded installs",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
# Use BINARY to force a case-sensitive comparison
# => the "Renamed" does not always appear in the output
$dbh->do(
q{
UPDATE systempreferences
SET variable="OPACItemLocation"
WHERE BINARY variable="OpacItemLocation"
}
);
# DELETE StaffLoginBranchBasedOnIP if exists. It is now StaffLoginLibraryBasedOnIP
$dbh->do(
q{
DELETE FROM systempreferences
WHERE variable="StaffLoginBranchBasedOnIP"
}
);
my $new_explanations = {
AcquisitionsDefaultEmailAddress => q{Default email address that acquisition notices are sent from},
AdvancedSearchLanguages =>
q{ISO 639-2 codes of languages you wish to see appear as an Advanced search option. Example: eng|fre|ita},
AllowMultipleIssuesOnABiblio => q{Allow/Don't allow patrons to check out multiple items from one biblio},
Babeltheque => q{Turn ON Babeltheque content - See babeltheque.com to subscribe to this service},
BlockExpiredPatronOpacActions =>
q{Specific actions expired patrons of this category are blocked from performing. OPAC actions blocked based on the patron category take priority over this preference.},
ChildNeedsGuarantor => q{If ON, a child patron must have a guarantor when adding the patron.},
DefaultPatronSearchMethod =>
q{Choose which search method to use by default when searching with PatronAutoComplete},
displayFacetCount => q{If enabled, display the number of facet counts},
EnableBooking => q{If enabled, activate every functionalities related with Bookings module},
HoldCancellationRequestSIP => q{Option to set holds cancelled via SIP as cancelation requests},
HoldRatioDefault => q{Default value for the hold ratio report},
ILLModule => q{If ON, enables the interlibrary loans module.},
OPACLoginLabelTextContent => q{Control the text displayed on the login form},
OpacHiddenItems =>
q{This syspref allows to define custom rules for hiding specific items at the OPAC. See https://wiki.koha-community.org/wiki/OpacHiddenItems for more information.},
OPACShowLibraries =>
q{If enabled, a "Libraries" link appears in the OPAC pointing to a page with library information},
OpacSuppressionRedirect =>
q{Redirect the opac detail page for suppressed records to an explanatory page (otherwise redirect to 404 error page)},
OPACVirtualCard => q{If ON, the patron virtual library card tab in the OPAC will be enabled},
OPACVirtualCardBarcode =>
q{Specify the type of barcode to be used in the patron virtual library card tab in the OPAC},
PatronSelfRegistrationEmailMustBeUnique =>
q{If set, the field borrowers.email will be considered as a unique field on self-registering},
PatronSelfRegistrationPrefillForm =>
q{Display password and prefill login form after a patron has self-registered},
PreventWithdrawingItemsStatus => q{Prevent the withdrawing of items based on certain statuses},
RoundFinesAtPayment =>
q{If enabled any fines with fractions of a cent will be rounded to the nearest cent when payments are collected. e.g. 1.004 will be paid off by a 1.00 payment},
SessionRestrictionByIP =>
q{Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.},
SeparateHoldingsByGroup =>
q{Separate current branch holdings and holdings from libraries in the same library groups},
ShowHeadingUse =>
q{Show whether MARC21 authority record contains an established heading that conforms to descriptive cataloguing rules, and can therefore be used as a main/added entry, or subject, or series title},
SuggestionsLog => q{If ON, log purchase suggestion changes},
SuspendHoldsIntranet => q{Allow holds to be suspended from the intranet.},
SuspendHoldsOpac => q{Allow holds to be suspended from the OPAC.},
UpdateItemLostStatusWhenPaid =>
q{Allows the status of lost items to be automatically changed to lost and paid for when paid for},
UpdateItemLostStatusWhenWriteoff =>
q{Allows the status of lost items to be automatically changed to lost and paid for when written off},
UpdateNotForLoanStatusOnCheckout =>
qq{This is a list of value pairs. When an item is checked out, if its not for loan value matches the value on the left, then the items not for loan value will be updated to the value on the right. \nE.g. '-1: 0' will cause an item that was set to 'Ordered' to now be available for loan. Each pair of values should be on a separate line.},
};
for my $variable ( sort { lc($a) cmp lc($b) } keys %$new_explanations ) {
my $explanation = $new_explanations->{$variable};
$dbh->do(
q{
UPDATE systempreferences
SET explanation=?
WHERE variable=?
}, undef, $explanation, $variable
);
}
# AlwaysLoadCheckoutsTable and CircConfirmItemParts has "Yes/No" instead of "YesNo"
$dbh->do(
q{
UPDATE systempreferences
SET type="YesNo"
WHERE type="Yes/No"
}
);
$dbh->do(
q{
UPDATE systempreferences
SET value="0"
WHERE type="YesNo" AND value=""
}
);
$dbh->do(
q{
UPDATE systempreferences
SET options=NULL
WHERE type="YesNo";
}
);
$dbh->do(
q{
UPDATE systempreferences
SET options=NULL
WHERE options='' OR options='NULL';
}
);
$dbh->do(
q{
UPDATE systempreferences
SET options='starts_with|contains'
WHERE variable="DefaultPatronSearchMethod";
}
);
$dbh->do(
q{
UPDATE systempreferences
SET type='Free'
WHERE variable="OpacKohaUrl";
}
);
$dbh->do(
q{
UPDATE systempreferences
SET type='Free'
WHERE variable="OPACLoginLabelTextContent";
}
);
},
};

File diff suppressed because one or more lines are too long