From cde18cf2901cba5ac986e7772bb9e419115c72d4 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 26 Nov 2014 17:56:37 +1300 Subject: [PATCH] Bug 11998 - fix some compile warnings This lazy-loads C4::Context and some other modules so that they can be be safely used by C4::Context without introducing problematic circular dependencies. Signed-off-by: Brendan Gallagher --- C4/Log.pm | 13 ++++++++----- Koha/Database.pm | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/C4/Log.pm b/C4/Log.pm index 80c3493..9bdee99 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -24,9 +24,6 @@ package C4::Log; use strict; use warnings; -use C4::Context; -use C4::Dates qw(format_date); - use vars qw($VERSION @ISA @EXPORT); BEGIN { @@ -68,6 +65,8 @@ number is set to 0, which is the same as the superlibrarian's number. sub logaction { my ($modulename, $actionname, $objectnumber, $infos)=@_; + # Require on demand so we can be called from C4::Context; + require C4::Context; # Get ID of logged in user. if called from a batch job, # no user session exists and C4::Context->userenv() returns # the scalar '0'. @@ -97,6 +96,7 @@ C<$status> is a hasref like this example: #' sub GetLogStatus { + require C4::Context; my %hash; $hash{BorrowersLog} = C4::Context->preference("BorrowersLog"); $hash{CataloguingLog} = C4::Context->preference("CataloguingLog"); @@ -122,7 +122,8 @@ returns a table of hash containing who did what on which object at what time #' sub displaylog { - my ($modulename, @filters) = @_; + my ($modulename, @filters) = @_; + require C4::Context; my $dbh = C4::Context->dbh; my $strsth=qq| SELECT action_logs.timestamp, action_logs.action, action_logs.info, @@ -173,10 +174,11 @@ sub displaylog { my @results; my $count; my $hilighted=1; + require C4::Dates; while (my $data = $sth->fetchrow_hashref){ $data->{hilighted} = ($hilighted>0); $data->{info} =~ s/\n//g; - $data->{day} = format_date($data->{timestamp}); + $data->{day} = C4::Dates::format_date($data->{timestamp}); push @results, $data; $count++; $hilighted = -$hilighted; @@ -202,6 +204,7 @@ sub GetLogs { my $object = shift; my $info = shift; + require C4::Context; my $iso_datefrom = C4::Dates->new($datefrom,C4::Context->preference("dateformat"))->output('iso'); my $iso_dateto = C4::Dates->new($dateto,C4::Context->preference("dateformat"))->output('iso'); diff --git a/Koha/Database.pm b/Koha/Database.pm index 5587570..5291924 100644 --- a/Koha/Database.pm +++ b/Koha/Database.pm @@ -34,7 +34,7 @@ Koha::Database use Modern::Perl; use Carp; -use C4::Context; +use Koha::Schema; use base qw(Class::Accessor); use vars qw($database); @@ -47,7 +47,7 @@ __PACKAGE__->mk_accessors(qw( )); # returns it. sub _new_schema { - require Koha::Schema; + require C4::Context; my $context = C4::Context->new(); # we are letting C4::Context->dbh not set the RaiseError handle attribute -- 1.7.10.4