From 9bbd54ae4ee5e91388181c8a2699c6ca85168441 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 22 Jun 2023 00:56:12 +0000 Subject: [PATCH] Bug 34088: Short circuit database upgrade check If the database version and the code version are the same, we should short circuit and exit immediately. --- Koha/Installer.pm | 40 ++++++++++++++++++++++++++ installer/data/mysql/updatedatabase.pl | 2 ++ 2 files changed, 42 insertions(+) create mode 100644 Koha/Installer.pm diff --git a/Koha/Installer.pm b/Koha/Installer.pm new file mode 100644 index 0000000000..2df4620037 --- /dev/null +++ b/Koha/Installer.pm @@ -0,0 +1,40 @@ +package Koha::Installer; + +use Modern::Perl; + +require Koha; +require Koha::Database; + +sub import { + my $dbh = Koha::Database::dbh(); + my $sql = "SELECT value FROM systempreferences WHERE variable = 'Version'"; + my $sth = $dbh->prepare($sql); + $sth->execute(); + my $row = $sth->fetchrow_arrayref(); + my $db_version = $row->[0]; + my $koha_version = Koha->version; + my $code_version = TransformToNum($koha_version); + if ($db_version == $code_version){ + exit; + } +} + +=head2 TransformToNum + +Transform the Koha version from a 4 parts string +to a number, with just 1 . + +=cut + +sub TransformToNum { + my $version = shift; + # remove the 3 last . to have a Perl number + $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; + # three X's at the end indicate that you are testing patch with dbrev + # change it into 999 + # prevents error on a < comparison between strings (should be: lt) + $version =~ s/XXX$/999/; + return $version; +} + +1; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index c95fdf3e3c..9597fad73e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -27,6 +27,8 @@ # NOTE: Please keep the version in kohaversion.pl up-to-date! +use Koha::Installer; + use Modern::Perl; use feature 'say'; -- 2.30.2