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

(-)a/C4/Context.pm (+25 lines)
Lines 821-826 sub _new_queryparser { Link Here
821
    return;
821
    return;
822
}
822
}
823
823
824
825
=head2 get_env_variables
826
my $tz_sth = C4::Context->get_env_variables();
827
828
This subroutine retrieves and returns all variable records where variable=time_zone
829
=cut
830
831
sub get_env_variables {
832
    my $dbh = C4::Context->dbh;
833
    my  $tz_sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'");
834
    return $tz_sth;
835
}
836
837
=head2 get_current_time
838
my $now_sth = C4::Context->get_current_time();
839
840
This subroutine retrieves and returns the current time
841
=cut
842
843
sub get_current_time {
844
    my $dbh = C4::Context->dbh;
845
    my $current_time = $dbh->prepare("SELECT now()");
846
    return $current_time;
847
}
848
824
=head2 userenv
849
=head2 userenv
825
850
826
  C4::Context->userenv;
851
  C4::Context->userenv;
(-)a/admin/env_tz_test.pl (-2 / +3 lines)
Lines 21-29 my ($template, $loggedinuser, $cookie) = get_template_and_user( Link Here
21
);
21
);
22
22
23
my $dbh = C4::Context->dbh;
23
my $dbh = C4::Context->dbh;
24
my  $tz_sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'");
24
my $tz_sth = C4::Context->get_env_variables();
25
$tz_sth->execute();
25
$tz_sth->execute();
26
my $now_sth = $dbh->prepare("SELECT now()");
26
27
my $now_sth = C4::Context->get_current_time();
27
$now_sth->execute();
28
$now_sth->execute();
28
29
29
print $q->header(), 
30
print $q->header(), 
(-)a/t/db_dependent/Context.t (-2 / +24 lines)
Lines 7-14 use Test::More; Link Here
7
use Test::MockModule;
7
use Test::MockModule;
8
use vars qw($debug $koha $dbh $config $ret);
8
use vars qw($debug $koha $dbh $config $ret);
9
use t::lib::Mocks;
9
use t::lib::Mocks;
10
10
use Test::More tests => 41;
11
use Koha::Database;
11
use Koha::Database;
12
use DateTime;
12
13
13
BEGIN {
14
BEGIN {
14
    $debug = $ENV{DEBUG} || 0;
15
    $debug = $ENV{DEBUG} || 0;
Lines 135-140 C4::Context->set_preference('AutoEmailOpacUser', ''); Link Here
135
my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser');
136
my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser');
136
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
137
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
137
138
139
140
sub get_env_variables {
141
     my $sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'");
142
     $sth->execute();
143
     return $sth->rows;
144
}
145
my $env_var = get_env_variables();
146
is($env_var, 1, "correct number of variables like time_zone");
147
148
sub get_current_time {
149
    my $sth = $dbh->prepare("SELECT now()");
150
    $sth->execute();
151
    return $sth->fetchrow_array;# Return a time value rather than hash value
152
}
153
my $datetime = DateTime->now;
154
my $date = $datetime->ymd;
155
my $time = $datetime->hms;
156
my $compardt = "$date $time";
157
158
my $current_time = get_current_time();
159
is($current_time, $compardt, "Correct time");
160
138
done_testing();
161
done_testing();
139
162
140
sub TransformVersionToNum {
163
sub TransformVersionToNum {
141
- 

Return to bug 18299