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 <david@davidnind.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
7c8434553a
commit
d9d473d339
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
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" );
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue