From b76fb9cf466dd4cc4eb4d382c4bfb9fa78a1fce6 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 18 Jan 2023 03:20:29 +0000 Subject: [PATCH] Bug 28267: Add warnings for database row formats This patch adds a warning on about.pl regarding database row formats other than "DYNAMIC". It points to the Koha community wiki for more information on how to resolve the problem. This patch also stops the installer if there are any database tables with a row format other than "DYNAMIC". It points to the Koha community wiki for more information on how to resolve the problem. Test plan: 0a. Apply the patch 0b. koha-plack --restart kohadev 1a. koha-mysql kohadev 1b. ALTER TABLE tags ROW_FORMAT=COMPACT; 2. Go to http://localhost:8081/cgi-bin/koha/about.pl 3. Note that there is a warning about database row formats 4a. koha-mysql kohadev 4b. ALTER TABLE tags ROW_FORMAT=DYNAMIC; 5. Go to http://localhost:8081/cgi-bin/koha/about.pl 6. Note that there is no warning about database row formats 7a. Manually change the version in Koha.pm to a higher version 7b. koha-plack --restart kohadev 8a. koha-mysql kohadev 8b. ALTER TABLE tags ROW_FORMAT=COMPACT; 9. Go to http://localhost:8081/ 10. Log into the web installer and click through until you reach a warning telling you that you have database row formats other than 'DYNAMIC' 11. Note that you can't progress with the installer until this problem is resolved 12a. koha-mysql kohadev 12b. ALTER TABLE tags ROW_FORMAT=DYNAMIC; 13. Refresh the page or redo the web installer process 14. Note that you're no longer blocked from running the installer due to database row format 15. Undo your change to Koha.pm 16. Profit Note: Due to bug 32665 you'll see an unrelated warning on step 3 Signed-off-by: Owen Leonard Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/Installer.pm | 60 +++++++++++++++++++ about.pl | 9 +++ installer/install.pl | 8 +++ .../intranet-tmpl/prog/en/modules/about.tt | 11 +++- .../prog/en/modules/installer/step2.tt | 9 +++ t/db_dependent/Koha/Installer.t | 48 +++++++++++++++ 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 Koha/Installer.pm create mode 100755 t/db_dependent/Koha/Installer.t diff --git a/Koha/Installer.pm b/Koha/Installer.pm new file mode 100644 index 0000000000..4d2f3d12ac --- /dev/null +++ b/Koha/Installer.pm @@ -0,0 +1,60 @@ +package Koha::Installer; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use C4::Context; + +=head1 NAME + +Koha::Installer - Class that provides installation related methods + +=head1 API + +=head2 Class Methods + +=cut + +=head3 check_db_row_format + +=cut + +sub check_db_row_format { + my ($class) = @_; + my %result = (); + my $database = C4::Context->config('database'); + if ($database){ + my $dbh = C4::Context->dbh; + my $sql = q# + SELECT count(table_name) + FROM information_schema.tables + WHERE + table_schema = ? + AND row_format != "Dynamic" + #; + my $sth = $dbh->prepare($sql); + $sth->execute($database); + my $row = $sth->fetchrow_arrayref; + my $count = $row->[0]; + if ($count){ + $result{count} = $count; + } + } + return \%result; +} + +1; diff --git a/about.pl b/about.pl index 886fef9c7b..f69c8747d8 100755 --- a/about.pl +++ b/about.pl @@ -55,6 +55,7 @@ use Koha::Illrequest::Config; use Koha::SearchEngine::Elasticsearch; use Koha::Logger; use Koha::Filter::MARC::ViewPolicy; +use Koha::Installer; use C4::Members::Statistics; @@ -629,6 +630,14 @@ $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs; } } +#BZ 28267: Warn administrators if there are database rows with a format other than 'DYNAMIC' +{ + my $db_row_format_result = Koha::Installer->check_db_row_format(); + if ( my $count = $db_row_format_result->{count} ){ + $template->param( warnDbRowFormat => $count ); + } +} + my %versions = C4::Context::get_versions(); $template->param( diff --git a/installer/install.pl b/installer/install.pl index f8de23e332..d7be88cdbb 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -32,6 +32,7 @@ use C4::Installer; use C4::Installer::PerlModules; use Koha; +use Koha::Installer; my $query = CGI->new; my $step = $query->param('step'); @@ -185,6 +186,13 @@ elsif ( $step && $step == 2 ) { } } $template->param( "checkgrantaccess" => $grantaccess ); + + my $db_row_format_result = Koha::Installer->check_db_row_format(); + if ( my $count = $db_row_format_result->{count} ){ + $template->param( warnDbRowFormat => $count ); + $template->param( error => "InnoDB row format" ); + } + } # End mysql connect check... elsif ( $info{dbms} eq "Pg" ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index cb36cbc284..13d6fe7349 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -267,7 +267,16 @@ [% SET warnMissingCompiledFiles = 1 %] [% END %] [% WRAPPER tab_panel tabname= "sysinfo" %] - [% IF weasyprint_missing || warnPrefRequireChoosingExistingAuthority || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatronOPACPrivacy || warnPrefAnonymousPatronAnonSuggestions || warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist || warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist || warnPrefKohaAdminEmailAddress || warnPrefOpacHiddenItems || invalid_yesno.count || warnNoActiveCurrency || warnIsRootUser || xml_config_warnings.size || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || has_ai_issues || oauth2_missing_deps || bad_yaml_prefs || warnRelationships || log4perl_errors || config_bcrypt_settings_no_set || warnHiddenBiblionumbers.size || warnConnectBroker || elasticsearch_has_missing || warnMissingCompiledFiles%] + [% IF weasyprint_missing || warnPrefRequireChoosingExistingAuthority || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatronOPACPrivacy || warnPrefAnonymousPatronAnonSuggestions || warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist || warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist || warnPrefKohaAdminEmailAddress || warnPrefOpacHiddenItems || invalid_yesno.count || warnNoActiveCurrency || warnIsRootUser || xml_config_warnings.size || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || has_ai_issues || oauth2_missing_deps || bad_yaml_prefs || warnRelationships || log4perl_errors || config_bcrypt_settings_no_set || warnHiddenBiblionumbers.size || warnConnectBroker || elasticsearch_has_missing || warnMissingCompiledFiles || warnDbRowFormat %] + [% IF ( warnDbRowFormat ) %] +

Database row format incorrect

+

Database tables with a row format other than 'DYNAMIC': [% warnDbRowFormat | html %]

+

You may experience problems upgrading to newer versions of Koha unless you update the row format for your database tables.

+

To know how to avoid this problem see the related wiki page: + Database row format +

+ [% END %] + [% IF (warnIsRootUser) %]

Warning regarding current user

You are logged in as the database administrative user. This is not recommended because some parts of Koha will not function as expected when using this account.

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step2.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step2.tt index fab5eb4355..d44cc4c2ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step2.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step2.tt @@ -49,6 +49,15 @@

Need help? For help with granting permissions, please search online for "[% dbms | $HtmlTags tag=>'code' %] manual grant permissions"

[% END %] + [% IF ( warnDbRowFormat ) %] + + [% END %] [% ELSE %]

Please create the database before continuing.

diff --git a/t/db_dependent/Koha/Installer.t b/t/db_dependent/Koha/Installer.t new file mode 100755 index 0000000000..f6b6878e61 --- /dev/null +++ b/t/db_dependent/Koha/Installer.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 1; + +use C4::Context; +use Koha::Database; +use Koha::Installer; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; + +subtest 'check_db_row_format() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $dbh = C4::Context->dbh; + $dbh->do("ALTER TABLE tags row_format=COMPACT;"); + + my $pos_result = Koha::Installer->check_db_row_format; + is($pos_result->{count},1,"Detected problem table"); + + $dbh->do("ALTER TABLE tags row_format=DYNAMIC;"); + + my $neg_result = Koha::Installer->check_db_row_format; + is($neg_result->{count},undef,"Detected no problem tables"); + + $schema->storage->txn_rollback; +}; -- 2.39.5