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