From d9d473d3399c85d1705ec18c7c85e17b7f30b366 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 20 Jan 2023 09:34:57 +0000 Subject: [PATCH] Bug 32687: Get server version in Context::get_versions Test plan: Run t/db_dependent/Context.t Check About/Server information/MySQL version. Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- C4/Context.pm | 9 +++++++-- t/db_dependent/Context.t | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 1aec1232f3..3819529dc2 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -820,20 +820,25 @@ Gets various version info, for core Koha packages, Currently called from carp ha # A little example sub to show more debugging info for CGI::Carp sub get_versions { - my %versions; + my ( %versions, $mysqlVersion ); $versions{kohaVersion} = Koha::version(); $versions{kohaDbVersion} = C4::Context->preference('version'); $versions{osVersion} = join(" ", POSIX::uname()); $versions{perlVersion} = $]; + + my $dbh = C4::Context->dbh; + $mysqlVersion = $dbh->get_info(18) if $dbh; # SQL_DBMS_VER + { no warnings qw(exec); # suppress warnings if unable to find a program in $PATH - $versions{mysqlVersion} = `mysql -V`; + $mysqlVersion ||= `mysql -V`; # fallback to sql client version? $versions{apacheVersion} = (`apache2ctl -v`)[0]; $versions{apacheVersion} = `httpd -v` unless $versions{apacheVersion} ; $versions{apacheVersion} = `httpd2 -v` unless $versions{apacheVersion} ; $versions{apacheVersion} = `apache2 -v` unless $versions{apacheVersion} ; $versions{apacheVersion} = `/usr/sbin/apache2 -v` unless $versions{apacheVersion} ; } + $versions{mysqlVersion} = $mysqlVersion; return %versions; } diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t index 88539fe34b..67587b4798 100755 --- a/t/db_dependent/Context.t +++ b/t/db_dependent/Context.t @@ -16,7 +16,8 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; +use Test::MockModule; use C4::Context; use Koha::Database; @@ -147,3 +148,24 @@ subtest 'Zconn' => sub { $oConnection = C4::Context->Zconn('biblioserver', 1); is($oConnection->option('async'), 1, "ZOOM connection is asynchronous"); }; + +subtest 'get_versions' => sub { + plan tests => 2; + + my $dbh = C4::Context->dbh; + my $mod = Test::MockModule->new( 'C4::Context' ); + my $no_dbh; + $mod->mock( 'dbh', sub { return $no_dbh ? undef : $dbh; } ); + + my $client = `mysql -V`; + my $server = ( C4::Context->dbh->selectrow_array("SHOW VARIABLES LIKE 'version'") )[1]; + my $server_version; + if( $server =~ /(\d+(\.\d+)+)/ ) { + $server_version = $1; + $server_version =~ s/\./\\./g; + } + my $v; + like( $v = { C4::Context::get_versions }->{mysqlVersion}, qr/$server_version/, "Server version $v found" ); + $no_dbh = 1; + is( $v = { C4::Context::get_versions }->{mysqlVersion}, $client, "Client version $v found" ); +}; -- 2.39.5