View | Details | Raw Unified | Return to bug 18299
Collapse All | Expand All

(-)a/admin/env_tz_test.pl (-133 lines)
Lines 1-132 Link Here
1
#!/usr/bin/perl 
2
3
use strict;
4
use warnings;
5
use CGI qw ( -utf8 );
6
# use Data::Dumper;
7
8
use C4::Context;
9
use C4::Auth;
10
11
my $q = CGI->new();
12
my ($template, $loggedinuser, $cookie) = get_template_and_user(
13
    {
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,
20
    }
21
);
22
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();
28
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.")
33
	.
34
	$q->h1("Dumping ENV:") 
35
	.
36
	join("\n<br\>", map {"$_ = $ENV{$_}"} sort keys %ENV)
37
	.
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";
44
45
__END__
46
47
=pod
48
49
=head1 MULTIPLE TIME ZONE SUPPORT
50
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).
53
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. 
57
58
Only use this feature if
59
you are running multiple Kohas on the same server, and they are not in the same timezone.  
60
61
=head2 Perl
62
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.
67
68
=head2 Apache2
69
70
We affect the running perl code of Koha with the Apache directive:
71
72
SetEnv TZ "US/Central"
73
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.
77
78
=head2 Database (mysql)
79
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:
82
83
	mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
84
85
See http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html
86
87
=head2 cron/crontab
88
89
Current versions of cron in debian allow ENV variables to be set in the lines preceding
90
scheduled commands.  They will be exported to the environment of the scheduled job.  This is 
91
an example for crontab:
92
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
98
99
=head1 EXAMPLE
100
101
Try these on a command line to confirm Context is setting time_zone based on TZ:
102
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";'
105
106
export TZ="US/Central";  # or any TZ other than the current one.
107
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";'
110
111
Then update your VirtualHosts to do, for example:
112
113
	SetEnv TZ "US/Central"
114
115
Reset Apache, then on your intranet check out the debug page:
116
117
	cgi-bin/koha/admin/env_tz_test.pl
118
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.
121
122
=head1 BUGS
123
124
WARNING: Multiple timezones may or may not work under mod_perl and mod_perl2.  
125
126
=head1 AUTHOR
127
128
	Joe Atzberger
129
	atz at liblime.com
130
131
=cut
132
133
- 

Return to bug 18299