|
Lines 21-32
use Modern::Perl;
Link Here
|
| 21 |
|
21 |
|
| 22 |
use vars qw($AUTOLOAD $context); |
22 |
use vars qw($AUTOLOAD $context); |
| 23 |
BEGIN { |
23 |
BEGIN { |
| 24 |
# Calling get_enabled_plugins here esnures that all plugin |
24 |
my $enable_plugins = 0; |
| 25 |
# modules are loaded before use and will not trigger |
25 |
if ( exists $ENV{'KOHA_CONF'} && -e $ENV{'KOHA_CONF'} ) { |
| 26 |
# a database connection reset |
26 |
require XML::Simple; |
| 27 |
Koha::Plugins->get_enabled_plugins(); |
27 |
$enable_plugins = |
|
|
28 |
XML::Simple->new->XMLin( $ENV{'KOHA_CONF'}, ForceArray => 0, KeyAttr => [] )->{'config'}->{'enable_plugins'} |
| 29 |
// 0; |
| 30 |
} |
| 31 |
|
| 32 |
if ($enable_plugins) { |
| 33 |
require Koha::Cache::Memory::Lite; |
| 34 |
my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache('enabled_plugins'); |
| 35 |
|
| 36 |
if ( !$enabled_plugins ) { |
| 37 |
require Koha::Config; |
| 38 |
my $config = Koha::Config->get_instance; |
| 39 |
|
| 40 |
# Database connection setup |
| 41 |
my $driver = $config->get('db_scheme') eq 'Pg' ? 'Pg' : 'mysql'; |
| 42 |
my $dsn = sprintf( |
| 43 |
'dbi:%s:database=%s;host=%s;port=%s', |
| 44 |
$driver, |
| 45 |
$config->get("database_test") || $config->get("database"), |
| 46 |
$config->get("hostname"), |
| 47 |
$config->get("port") || q{}, |
| 48 |
); |
| 49 |
my $attr = { RaiseError => 1, PrintError => 1 }; |
| 50 |
if ( $driver eq 'mysql' && ( $config->get("tls") // q{} ) eq 'yes' ) { |
| 51 |
$dsn .= sprintf( |
| 52 |
';mysql_ssl=1;mysql_ssl_client_key=%s;mysql_ssl_client_cert=%s;mysql_ssl_ca_file=%s', |
| 53 |
$config->get('key'), $config->get('cert'), $config->get('ca'), |
| 54 |
); |
| 55 |
$attr->{mysql_enable_utf8} = 1; |
| 56 |
} |
| 57 |
|
| 58 |
require DBI; |
| 59 |
my $dbh = DBI->connect( $dsn, $config->get("user"), $config->get("pass"), $attr ); |
| 60 |
|
| 61 |
if ($dbh) { |
| 62 |
my $tz = $config->timezone // q{}; |
| 63 |
my @queries; |
| 64 |
push @queries, "SET NAMES 'utf8mb4'" if $driver eq 'mysql'; |
| 65 |
push @queries, qq{SET time_zone = "$tz"} if $tz && $driver eq 'mysql' && $tz ne 'local'; |
| 66 |
push @queries, qq{SET TIME ZONE = "$tz"} if $tz && $driver eq 'Pg'; |
| 67 |
push @queries, 'set client_encoding = \'UTF8\'' if $driver eq 'Pg'; |
| 68 |
if ( $driver eq 'mysql' ) { |
| 69 |
my $sql_mode = |
| 70 |
( $config->get('strict_sql_modes') || $ENV{KOHA_TESTING} || ( $ENV{_} // q{} ) =~ m{prove}smx ) |
| 71 |
? 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' |
| 72 |
: 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; |
| 73 |
push @queries, qq{SET sql_mode = '$sql_mode'}; |
| 74 |
} |
| 75 |
|
| 76 |
$dbh->do($_) for grep { $_ } @queries; |
| 77 |
|
| 78 |
# Retrieve enabled plugin classes |
| 79 |
my $sth = $dbh->prepare( |
| 80 |
q{SELECT plugin_class FROM plugin_data WHERE plugin_key = ' __ENABLED__ ' AND plugin_value = 1}); |
| 81 |
$sth->execute(); |
| 82 |
my @plugin_classes = map { $_->[0] } @{ $sth->fetchall_arrayref() }; |
| 83 |
$sth->finish(); |
| 84 |
$dbh->disconnect(); |
| 85 |
|
| 86 |
# Load and instantiate plugins |
| 87 |
$enabled_plugins = []; |
| 88 |
foreach my $plugin_class (@plugin_classes) { |
| 89 |
next |
| 90 |
if !Module::Load::Conditional::can_load( |
| 91 |
modules => { $plugin_class => undef }, |
| 92 |
nocache => 1 |
| 93 |
); |
| 94 |
if ( my $plugin = eval { $plugin_class->new() } ) { |
| 95 |
push @{$enabled_plugins}, $plugin; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
Koha::Cache::Memory::Lite->set_in_cache( 'enabled_plugins', $enabled_plugins ); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 28 |
|
103 |
|
| 29 |
if ( $ENV{'HTTP_USER_AGENT'} ) { # Only hit when plack is not enabled |
104 |
if ( $ENV{'HTTP_USER_AGENT'} ) { # Only hit when plack is not enabled |
| 30 |
|
105 |
|
| 31 |
# Redefine multi_param if cgi version is < 4.08 |
106 |
# Redefine multi_param if cgi version is < 4.08 |
| 32 |
# Remove the "CGI::param called in list context" warning in this case |
107 |
# Remove the "CGI::param called in list context" warning in this case |
|
Lines 38-44
BEGIN {
Link Here
|
| 38 |
$CGI::LIST_CONTEXT_WARN = 0; |
113 |
$CGI::LIST_CONTEXT_WARN = 0; |
| 39 |
} |
114 |
} |
| 40 |
} |
115 |
} |
| 41 |
}; |
116 |
} |
| 42 |
|
117 |
|
| 43 |
use Carp qw( carp ); |
118 |
use Carp qw( carp ); |
| 44 |
use DateTime::TimeZone; |
119 |
use DateTime::TimeZone; |
| 45 |
- |
|
|