|
Lines 32-50
BEGIN {
Link Here
|
| 32 |
if ($enable_plugins) { |
32 |
if ($enable_plugins) { |
| 33 |
require Koha::Cache::Memory::Lite; |
33 |
require Koha::Cache::Memory::Lite; |
| 34 |
my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache('enabled_plugins'); |
34 |
my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache('enabled_plugins'); |
| 35 |
|
|
|
| 36 |
if ( !$enabled_plugins ) { |
35 |
if ( !$enabled_plugins ) { |
| 37 |
require Koha::Config; |
36 |
require Koha::Config; |
| 38 |
my $config = Koha::Config->get_instance; |
37 |
my $config = Koha::Config->get_instance; |
| 39 |
|
|
|
| 40 |
# Database connection setup |
| 41 |
my $driver = $config->get('db_scheme') eq 'Pg' ? 'Pg' : 'mysql'; |
38 |
my $driver = $config->get('db_scheme') eq 'Pg' ? 'Pg' : 'mysql'; |
| 42 |
my $dsn = sprintf( |
39 |
my $dsn = sprintf( |
| 43 |
'dbi:%s:database=%s;host=%s;port=%s', |
40 |
'dbi:%s:database=%s;host=%s;port=%s', |
| 44 |
$driver, |
41 |
$driver, |
| 45 |
$config->get("database_test") || $config->get("database"), |
42 |
$config->get('database_test') || $config->get('database'), |
| 46 |
$config->get("hostname"), |
43 |
$config->get('hostname'), |
| 47 |
$config->get("port") || q{}, |
44 |
$config->get('port') || q{}, |
| 48 |
); |
45 |
); |
| 49 |
my $attr = { RaiseError => 1, PrintError => 1 }; |
46 |
my $attr = { RaiseError => 1, PrintError => 1 }; |
| 50 |
if ( $driver eq 'mysql' && ( $config->get("tls") // q{} ) eq 'yes' ) { |
47 |
if ( $driver eq 'mysql' && ( $config->get("tls") // q{} ) eq 'yes' ) { |
|
Lines 52-63
BEGIN {
Link Here
|
| 52 |
';mysql_ssl=1;mysql_ssl_client_key=%s;mysql_ssl_client_cert=%s;mysql_ssl_ca_file=%s', |
49 |
';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'), |
50 |
$config->get('key'), $config->get('cert'), $config->get('ca'), |
| 54 |
); |
51 |
); |
| 55 |
$attr->{mysql_enable_utf8} = 1; |
52 |
$attr->{'mysql_enable_utf8'} = 1; |
| 56 |
} |
53 |
} |
| 57 |
|
54 |
|
| 58 |
require DBI; |
55 |
require DBI; |
| 59 |
my $dbh = DBI->connect( $dsn, $config->get("user"), $config->get("pass"), $attr ); |
56 |
my $dbh = DBI->connect( $dsn, $config->get('user'), $config->get('pass'), $attr ); |
| 60 |
|
|
|
| 61 |
if ($dbh) { |
57 |
if ($dbh) { |
| 62 |
my $tz = $config->timezone // q{}; |
58 |
my $tz = $config->timezone // q{}; |
| 63 |
my @queries; |
59 |
my @queries; |
|
Lines 75-102
BEGIN {
Link Here
|
| 75 |
|
71 |
|
| 76 |
$dbh->do($_) for grep { $_ } @queries; |
72 |
$dbh->do($_) for grep { $_ } @queries; |
| 77 |
|
73 |
|
| 78 |
# Retrieve enabled plugin classes |
74 |
my $table_exists = 0; |
| 79 |
my $sth = $dbh->prepare( |
75 |
if ( $driver eq 'mysql' ) { |
| 80 |
q{SELECT plugin_class FROM plugin_data WHERE plugin_key = ' __ENABLED__ ' AND plugin_value = 1}); |
76 |
$table_exists = $dbh->selectrow_array( |
| 81 |
$sth->execute(); |
77 |
<<~'SQL' |
| 82 |
my @plugin_classes = map { $_->[0] } @{ $sth->fetchall_arrayref() }; |
78 |
SELECT COUNT(*) FROM information_schema.tables |
| 83 |
$sth->finish(); |
79 |
WHERE table_schema = DATABASE() AND table_name = 'plugin_data' |
|
|
80 |
SQL |
| 81 |
); |
| 82 |
} elsif ( $driver eq 'Pg' ) { |
| 83 |
$table_exists = $dbh->selectrow_array( |
| 84 |
<<~'SQL' |
| 85 |
SELECT COUNT(*) FROM pg_catalog.pg_tables |
| 86 |
WHERE tablename = 'plugin_data' |
| 87 |
SQL |
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
my @plugin_classes; |
| 92 |
if ($table_exists) { |
| 93 |
my $sth = $dbh->prepare( |
| 94 |
<<~'SQL' |
| 95 |
SELECT plugin_class FROM plugin_data WHERE plugin_key = '__ENABLED__' AND plugin_value = 1 |
| 96 |
SQL |
| 97 |
); |
| 98 |
$sth->execute(); |
| 99 |
@plugin_classes = map { $_->[0] } @{ $sth->fetchall_arrayref() }; |
| 100 |
$sth->finish(); |
| 101 |
} |
| 84 |
$dbh->disconnect(); |
102 |
$dbh->disconnect(); |
| 85 |
|
103 |
|
| 86 |
# Load and instantiate plugins |
104 |
if (@plugin_classes) { |
| 87 |
$enabled_plugins = []; |
105 |
$enabled_plugins = []; |
| 88 |
foreach my $plugin_class (@plugin_classes) { |
106 |
require Module::Load::Conditional; |
| 89 |
next |
107 |
foreach my $plugin_class (@plugin_classes) { |
| 90 |
if !Module::Load::Conditional::can_load( |
108 |
next |
| 91 |
modules => { $plugin_class => undef }, |
109 |
if !Module::Load::Conditional::can_load( |
| 92 |
nocache => 1 |
110 |
modules => { $plugin_class => undef }, |
| 93 |
); |
111 |
nocache => 1 |
| 94 |
if ( my $plugin = eval { $plugin_class->new() } ) { |
112 |
); |
| 95 |
push @{$enabled_plugins}, $plugin; |
113 |
if ( my $plugin = eval { $plugin_class->new() } ) { |
|
|
114 |
push @{$enabled_plugins}, $plugin; |
| 115 |
} |
| 96 |
} |
116 |
} |
| 97 |
} |
117 |
} |
| 98 |
|
118 |
|
| 99 |
Koha::Cache::Memory::Lite->set_in_cache( 'enabled_plugins', $enabled_plugins ); |
119 |
Koha::Cache::Memory::Lite->set_in_cache( 'enabled_plugins', $enabled_plugins ) if $enabled_plugins; |
| 100 |
} |
120 |
} |
| 101 |
} |
121 |
} |
| 102 |
} |
122 |
} |
| 103 |
- |
|
|