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

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

Return to bug 38384