Bugzilla – Attachment 174282 Details for
Bug 38384
General fix for plugins breaking database transactions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38384: Prevent initialization failure by checking for existence of plugin_data first
Bug-38384-Prevent-initialization-failure-by-checki.patch (text/plain), 5.29 KB, created by
Paul Derscheid
on 2024-11-08 16:10:42 UTC
(
hide
)
Description:
Bug 38384: Prevent initialization failure by checking for existence of plugin_data first
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2024-11-08 16:10:42 UTC
Size:
5.29 KB
patch
obsolete
>From 2a37b796a4205f75592f132d84c5acb1b3a994cc Mon Sep 17 00:00:00 2001 >From: Paul Derscheid <paul.derscheid@lmscloud.de> >Date: Fri, 8 Nov 2024 16:08:59 +0000 >Subject: [PATCH] Bug 38384: Prevent initialization failure by checking for > existence of plugin_data first > >--- > C4/Context.pm | 72 ++++++++++++++++++++++++++++++++------------------- > 1 file changed, 46 insertions(+), 26 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 8164da044b..bfb6f87681 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -32,19 +32,16 @@ BEGIN { > if ($enable_plugins) { > require Koha::Cache::Memory::Lite; > my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache('enabled_plugins'); >- > if ( !$enabled_plugins ) { > require Koha::Config; > my $config = Koha::Config->get_instance; >- >- # Database connection setup > my $driver = $config->get('db_scheme') eq 'Pg' ? 'Pg' : 'mysql'; > my $dsn = sprintf( > 'dbi:%s:database=%s;host=%s;port=%s', > $driver, >- $config->get("database_test") || $config->get("database"), >- $config->get("hostname"), >- $config->get("port") || q{}, >+ $config->get('database_test') || $config->get('database'), >+ $config->get('hostname'), >+ $config->get('port') || q{}, > ); > my $attr = { RaiseError => 1, PrintError => 1 }; > if ( $driver eq 'mysql' && ( $config->get("tls") // q{} ) eq 'yes' ) { >@@ -52,12 +49,11 @@ BEGIN { > ';mysql_ssl=1;mysql_ssl_client_key=%s;mysql_ssl_client_cert=%s;mysql_ssl_ca_file=%s', > $config->get('key'), $config->get('cert'), $config->get('ca'), > ); >- $attr->{mysql_enable_utf8} = 1; >+ $attr->{'mysql_enable_utf8'} = 1; > } > > require DBI; >- my $dbh = DBI->connect( $dsn, $config->get("user"), $config->get("pass"), $attr ); >- >+ my $dbh = DBI->connect( $dsn, $config->get('user'), $config->get('pass'), $attr ); > if ($dbh) { > my $tz = $config->timezone // q{}; > my @queries; >@@ -75,28 +71,52 @@ BEGIN { > > $dbh->do($_) for grep { $_ } @queries; > >- # Retrieve enabled plugin classes >- my $sth = $dbh->prepare( >- q{SELECT plugin_class FROM plugin_data WHERE plugin_key = ' __ENABLED__ ' AND plugin_value = 1}); >- $sth->execute(); >- my @plugin_classes = map { $_->[0] } @{ $sth->fetchall_arrayref() }; >- $sth->finish(); >+ my $table_exists = 0; >+ if ( $driver eq 'mysql' ) { >+ $table_exists = $dbh->selectrow_array( >+ <<~'SQL' >+ SELECT COUNT(*) FROM information_schema.tables >+ WHERE table_schema = DATABASE() AND table_name = 'plugin_data' >+ SQL >+ ); >+ } elsif ( $driver eq 'Pg' ) { >+ $table_exists = $dbh->selectrow_array( >+ <<~'SQL' >+ SELECT COUNT(*) FROM pg_catalog.pg_tables >+ WHERE tablename = 'plugin_data' >+ SQL >+ ); >+ } >+ >+ my @plugin_classes; >+ if ($table_exists) { >+ my $sth = $dbh->prepare( >+ <<~'SQL' >+ SELECT plugin_class FROM plugin_data WHERE plugin_key = '__ENABLED__' AND plugin_value = 1 >+ SQL >+ ); >+ $sth->execute(); >+ @plugin_classes = map { $_->[0] } @{ $sth->fetchall_arrayref() }; >+ $sth->finish(); >+ } > $dbh->disconnect(); > >- # Load and instantiate plugins >- $enabled_plugins = []; >- foreach my $plugin_class (@plugin_classes) { >- next >- if !Module::Load::Conditional::can_load( >- modules => { $plugin_class => undef }, >- nocache => 1 >- ); >- if ( my $plugin = eval { $plugin_class->new() } ) { >- push @{$enabled_plugins}, $plugin; >+ if (@plugin_classes) { >+ $enabled_plugins = []; >+ require Module::Load::Conditional; >+ foreach my $plugin_class (@plugin_classes) { >+ next >+ if !Module::Load::Conditional::can_load( >+ modules => { $plugin_class => undef }, >+ nocache => 1 >+ ); >+ if ( my $plugin = eval { $plugin_class->new() } ) { >+ push @{$enabled_plugins}, $plugin; >+ } > } > } > >- Koha::Cache::Memory::Lite->set_in_cache( 'enabled_plugins', $enabled_plugins ); >+ Koha::Cache::Memory::Lite->set_in_cache( 'enabled_plugins', $enabled_plugins ) if $enabled_plugins; > } > } > } >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38384
:
174150
|
174264
|
174265
|
174280
| 174282