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 <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit b76fb9cf46)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
David Cook 2023-01-18 03:20:29 +00:00 committed by Martin Renvoize
parent 7921b0fdbc
commit 0abb866b49
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
6 changed files with 144 additions and 1 deletions

60
Koha/Installer.pm Normal file
View file

@ -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 <http://www.gnu.org/licenses>.
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;

View file

@ -54,6 +54,7 @@ use Koha::Illrequest::Config;
use Koha::SearchEngine::Elasticsearch;
use Koha::Logger;
use Koha::Filter::MARC::ViewPolicy;
use Koha::Installer;
use C4::Members::Statistics;
@ -624,6 +625,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(

View file

@ -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" ) {

View file

@ -267,7 +267,16 @@
[% SET warnMissingCompiledFiles = 1 %]
[% END %]
[% WRAPPER tab_panel tabname= "sysinfo" %]
[% IF 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 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 ) %]
<h2>Database row format incorrect</h2>
<p>Database tables with a row format other than 'DYNAMIC': [% warnDbRowFormat | html %]</p>
<p>You may experience problems upgrading to newer versions of Koha unless you update the row format for your database tables.</p>
<p>To know how to avoid this problem see the related wiki page:
<a href="https://wiki.koha-community.org/wiki/Database_row_format">Database row format</a>
</p>
[% END %]
[% IF (warnIsRootUser) %]
<h2>Warning regarding current user</h2>
<p>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.</p>

View file

@ -49,6 +49,15 @@
<p>Need help? For help with granting permissions, please search online for "[% dbms | $HtmlTags tag=>'code' %] manual grant permissions"
</p>
[% END %]
[% IF ( warnDbRowFormat ) %]
<div class="alert alert-danger" role="alert">
<p>Database tables with a row format other than 'DYNAMIC': [% warnDbRowFormat | html %]</p>
<p>You may experience problems upgrading to newer versions of Koha unless you update the row format for your database tables.</p>
<p>To know how to avoid this problem see the related wiki page:
<a href="https://wiki.koha-community.org/wiki/Database_row_format">Database row format</a>
</p>
</div>
[% END %]
[% ELSE %]
<div class="alert alert-danger" role="alert"><p>No database named [% dbname | $HtmlTags tag=>'code' %] detected.</p></div>
<p>Please create the database before continuing.</p>

48
t/db_dependent/Koha/Installer.t Executable file
View file

@ -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 <http://www.gnu.org/licenses>.
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;
};