Bug 14487: Noise best detected under Debian 8
[koha.git] / admin / env_tz_test.pl
blobeb6a4b11ffbb05e10c0976018e126b1afbd6ff0f
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use CGI;
6 # use Data::Dumper;
8 use C4::Context;
9 use C4::Auth;
11 my $q = CGI->new();
12 my ($template, $loggedinuser, $cookie) = get_template_and_user(
14 template_name => "admin/admin-home.tt", # whatever, we don't really use the template anyway.
15 query => $q,
16 type => "intranet",
17 authnotrequired => 0,
18 flagsrequired => {parameters => 'parameters_remaining_permissions'},
19 debug => 1,
23 my $dbh = C4::Context->dbh;
24 my $tz_sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'");
25 $tz_sth->execute();
26 my $now_sth = $dbh->prepare("SELECT now()");
27 $now_sth->execute();
29 print $q->header(),
30 $q->html(
31 $q->body(
32 $q->p("This is a test for debugging purposes. It isn't supposed to look pretty.")
34 $q->h1("Dumping ENV:")
36 join("\n<br\>", map {"$_ = $ENV{$_}"} sort keys %ENV)
38 $q->h1("Checking different TIME elements in the system:")
39 . "\n" . $q->p("perl localime: " . localtime)
40 . "\n" . $q->p( "system(date): " . `date`)
41 . "\n" . $q->p( "mysql dbh (Context) time_zone : " . $tz_sth->fetchrow)
42 . "\n" . $q->p( "mysql dbh (Context) now() : " . $now_sth->fetchrow)
43 )), "\n";
45 __END__
47 =pod
49 =head1 MULTIPLE TIME ZONE SUPPORT
51 Koha supports running multiple instances on the same server, even if they need to be homed
52 in different timezones. However, your database must have the timezones installed (see below).
54 If you are only running one installation of Koha, and want to change the timezone of the server,
55 please do NOT use this feature at all, and instead set your system timezone via the OS. If you
56 are running multiple Kohas, all in the same timezone, do the same.
58 Only use this feature if
59 you are running multiple Kohas on the same server, and they are not in the same timezone.
61 =head2 Perl
63 For the most part, in execution perl will respect the environmental
64 variable TZ, if it is set. This affects calls to localtime() and other similar functions.
65 Remember that the environment will be different for different users, and for cron jobs.
66 See the example below.
68 =head2 Apache2
70 We affect the running perl code of Koha with the Apache directive:
72 SetEnv TZ "US/Central"
74 This should be added inside the VirtualHost definition for the intended Koha instance. In
75 almost ALL cases, be sure to set it for both INTRANET and OPAC VirtualHosts. Remember this
76 does not affect the command line environment for any terminal sessions, or your cron jobs.
78 =head2 Database (mysql)
80 Your MySQL installation must be configured with appropriate time zones. This extends beyond
81 Koha and affects mysql itself. On debian, for example, you can use:
83 mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
85 See http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html
87 =head2 cron/crontab
89 Current versions of cron in debian allow ENV variables to be set in the lines preceeding
90 scheduled commands. They will be exported to the environment of the scheduled job. This is
91 an example for crontab:
93 TZ="US/Central"
94 # m h dom mon dow command
95 0 1 * * * /home/liblime/kohaclone/misc/cronjobs/overdue_notices.pl
96 15 * * * * /home/liblime/kohaclone/misc/cronjobs/process_message_queue.pl
97 */10 * * * * /home/liblime/kohaclone/misc/migration_tools/rebuild_zebra.pl -b -z >/dev/null
99 =head1 EXAMPLE
101 Try these on a command line to confirm Context is setting time_zone based on TZ:
103 perl -MC4::Context -e 'my $dbh=C4::Context->dbh; my $tz_sth=$dbh->prepare(q(SHOW VARIABLES LIKE "time_zone"));
104 $tz_sth->execute(); print "mysql dbh (Context) time_zone : " . $tz_sth->fetchrow, "\n";'
106 export TZ="US/Central"; # or any TZ other than the current one.
108 perl -MC4::Context -e 'my $dbh=C4::Context->dbh; my $tz_sth=$dbh->prepare(q(SHOW VARIABLES LIKE "time_zone"));
109 $tz_sth->execute(); print "mysql dbh (Context) time_zone : " . $tz_sth->fetchrow, "\n";'
111 Then update your VirtualHosts to do, for example:
113 SetEnv TZ "US/Central"
115 Reset Apache, then on your intranet check out the debug page:
117 cgi-bin/koha/admin/env_tz_test.pl
119 The TZ that Koha has in effect and the TZ from the database should be displayed at the bottom.
120 Hopefully they match what you set.
122 =head1 BUGS
124 WARNING: Multiple timezones may or may not work under mod_perl and mod_perl2.
126 =head1 AUTHOR
128 Joe Atzberger
129 atz at liblime.com
131 =cut