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