Bug 20665: Reset MySQL connection time zone in the OAI-PMH Provider
authorEre Maijala <ere.maijala@helsinki.fi>
Thu, 26 Apr 2018 13:08:25 +0000 (13:08 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 3 May 2018 15:46:55 +0000 (12:46 -0300)
TEST PLAN
---------
apply unit test patch
prove t/db_dependent/OAI/Server.t
-- should fail
apply this patch
prove t/db_dependent/OAI/Server.t
-- should pass
run koha qa test tools

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/OAI/Server/Repository.pm

index d677787..30ace36 100644 (file)
@@ -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;