From 76120f1d4559e44ff494772ff538f8b96666a622 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Thu, 26 Apr 2018 15:04:55 +0300 Subject: [PATCH] Bug 20665 - Reset MySQL connection time zone in the OAI-PMH Provider Test plan: 1.) Run tests in t/db_dependent/Server.t --- Koha/OAI/Server/Repository.pm | 13 +++++++++++++ t/db_dependent/OAI/Server.t | 24 +++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm index d677787..30ace36 100644 --- a/Koha/OAI/Server/Repository.pm +++ b/Koha/OAI/Server/Repository.pm @@ -115,6 +115,10 @@ sub new { # OAI-PMH handles dates in UTC, so do that on the database level to avoid need for # any conversions + my $sth = C4::Context->dbh->prepare('SELECT @@session.time_zone'); + $sth->execute(); + my ( $orig_tz ) = $sth->fetchrow(); + $self->{ mysql_orig_tz } = $orig_tz; C4::Context->dbh->prepare("SET time_zone='+00:00'")->execute(); # Check for grammatical errors in the request @@ -152,6 +156,15 @@ sub new { } +sub DESTROY { + my ( $self ) = @_; + + # Reset time zone to the original value + C4::Context->dbh->prepare("SET time_zone='" . $self->{ mysql_orig_tz } . "'")->execute() + if $self->{ mysql_orig_tz }; +} + + sub get_biblio_marcxml { my ($self, $biblionumber, $format) = @_; my $with_items = 0; diff --git a/t/db_dependent/OAI/Server.t b/t/db_dependent/OAI/Server.t index 7309c4a..f924994 100644 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -20,7 +20,7 @@ use Modern::Perl; use Test::MockTime qw/set_fixed_time restore_time/; -use Test::More tests => 29; +use Test::More tests => 30; use DateTime; use Test::MockModule; use Test::Warn; @@ -376,4 +376,26 @@ subtest 'Bug 19725: OAI-PMH ListRecords and ListIdentifiers should use biblio_me }); }; +subtest 'Bug 20665: OAI-PMH Provider should reset the MySQL connection time zone' => sub { + plan tests => 2; + + # Set time zone to SYSTEM so that it can be checked later + $dbh->do("SET time_zone='SYSTEM'"); + + + test_query('ListIdentifiers without metadataPrefix', {verb => 'ListIdentifiers'}, { + error => { + code => 'badArgument', + content => "Required argument 'metadataPrefix' was undefined", + }, + }); + + my $sth = C4::Context->dbh->prepare('SELECT @@session.time_zone'); + $sth->execute(); + my ( $tz ) = $sth->fetchrow(); + + ok ( $tz eq 'SYSTEM', 'MySQL connection time zone is SYSTEM' ); +}; + + $schema->storage->txn_rollback; -- 2.7.4