Bugzilla – Attachment 73687 Details for
Bug 20123
Allow multiple instances of Koha to have different timezones on the same server
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20123: Allow multiple instances of Koha to have different timezones on the same server
Bug-20123-Allow-multiple-instances-of-Koha-to-have.patch (text/plain), 3.29 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-04-05 13:32:36 UTC
(
hide
)
Description:
Bug 20123: Allow multiple instances of Koha to have different timezones on the same server
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-04-05 13:32:36 UTC
Size:
3.29 KB
patch
obsolete
>From 19f0e14f1dfce3836b795a80c2d9669cd4dd0a6f Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatetsolutions.com> >Date: Thu, 1 Feb 2018 13:21:54 -0500 >Subject: [PATCH] Bug 20123: Allow multiple instances of Koha to have different > timezones on the same server > >Most of Koha depends on the local timezone of the server, except for Koha::Database which support an ENV override with the key TZ. > >We should take this a step further. We should not only accept the TZ environment variable for all of Koha, we should really be able to set the timezone in the koha conf file as well so we don't have to pass that environment variable to things like cronjobs and one-off scripts. > >Test Plan: >1) Apply this patch >2) Set a timzone in your koha_conf file, that is *not* your local time zone > Available timzones are listed here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones >3) Restart apache/plack >4) Perform some actions, check the timestamps in the database and in the > html output, note they are for the set timezone and not the local > timezone. > >Signed-off-by: Mark Tompsett <mtompset@hotmail.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Context.pm | 18 +++++++++++++++++- > Koha/Database.pm | 2 +- > t/timezones.t | 25 +++++++++++++++++++++++++ > 3 files changed, 43 insertions(+), 2 deletions(-) > create mode 100644 t/timezones.t > >diff --git a/C4/Context.pm b/C4/Context.pm >index 1eb5f88902..07e81854bd 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -969,6 +969,21 @@ sub get_versions { > return %versions; > } > >+=head2 timezone >+ >+ my $C4::Context->timzone >+ >+ Returns a timezone code for the instance of Koha >+ >+=cut >+ >+sub timezone { >+ my $self = shift; >+ >+ my $timezone = C4::Context->config('timezone') || $ENV{TZ} || 'local'; >+ >+ return $timezone; >+} > > =head2 tz > >@@ -981,7 +996,8 @@ sub get_versions { > sub tz { > my $self = shift; > if (!defined $context->{tz}) { >- $context->{tz} = DateTime::TimeZone->new(name => 'local'); >+ my $timezone = $self->timezone; >+ $context->{tz} = DateTime::TimeZone->new(name => $timezone); > } > return $context->{tz}; > } >diff --git a/Koha/Database.pm b/Koha/Database.pm >index e97c794a45..802bdc5111 100644 >--- a/Koha/Database.pm >+++ b/Koha/Database.pm >@@ -70,7 +70,7 @@ sub _new_schema { > > > my ( %encoding_attr, $encoding_query, $tz_query, $sql_mode_query ); >- my $tz = $ENV{TZ}; >+ my $tz = C4::Context->timezone; > if ( $db_driver eq 'mysql' ) { > %encoding_attr = ( mysql_enable_utf8 => 1 ); > $encoding_query = "set NAMES 'utf8mb4'"; >diff --git a/t/timezones.t b/t/timezones.t >new file mode 100644 >index 0000000000..c5463dab90 >--- /dev/null >+++ b/t/timezones.t >@@ -0,0 +1,25 @@ >+use Modern::Perl; >+ >+use C4::Context; >+ >+use Test::More tests => 3; >+use t::lib::Mocks; >+ >+$ENV{TZ} = q{}; >+t::lib::Mocks::mock_config( 'timezone', q{} ); >+is( C4::Context->timezone, 'local', >+ 'Got local timezone with no env or config timezone set' ); >+ >+$ENV{TZ} = 'Antarctica/Macquarie'; >+is( >+ C4::Context->timezone, >+ 'Antarctica/Macquarie', >+ 'Got correct timezone using ENV, overrides local time' >+); >+ >+t::lib::Mocks::mock_config( 'timezone', 'Antarctica/South_Pole' ); >+is( >+ C4::Context->timezone, >+ 'Antarctica/South_Pole', >+ 'Got correct timezone using config, overrides env' >+); >-- >2.17.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20123
:
71125
|
71839
|
71840
|
72080
|
72081
|
72202
|
72255
|
72603
|
72605
| 73687 |
73688
|
73689
|
73690
|
74043