Bug 36039: (follow-up) Move view logic to script/template

This patch updates the module as suggested by David to handle just the
diff code and leaves the display logic up to the templates and script.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: JesseM <jesse@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2024-05-03 10:09:58 +01:00 committed by Katrin Fischer
parent 6940167048
commit 534fba2691
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
4 changed files with 34 additions and 41 deletions

View File

@ -44,15 +44,12 @@ sub new {
my ( $class, $params ) = @_;
my $self = bless $params // {}, $class;
$self->{filename} = $params->{filename} // './installer/data/mysql/kohastructure.sql';
$self->{is_cli} = $params->{is_cli};
return $self;
}
=head3 run
Run the database audit with the given arguments, including the filename
and whether it is a command-line interface(CLI).
Returns $diff only if $is_cli is false. Else it just prints $diff.
Run the database audit with the given arguments, including the filename.
=cut
@ -60,9 +57,6 @@ sub run {
my ( $self, $args ) = @_;
if ( !-f $self->{filename} ) {
unless ( $self->{is_cli} ) {
return 'Database schema file not found';
}
die("Filename '$self->{filename}' does not exist\n");
}
@ -78,27 +72,10 @@ sub run {
}
)->compute_differences->produce_diff_sql;
return $diff unless $self->{is_cli};
print $diff . $self->get_warning;
return $diff;
}
}
=head3 get_warning
Retrieve a warning message.
=cut
sub get_warning {
my ($self) = @_;
return
"\n"
. "WARNING!!!\n"
. "These commands are only suggestions! They are not a replacement for updatedatabase.pl!\n"
. "Review the database, updatedatabase.pl, and kohastructure.sql before making any changes!\n" . "\n";
}
=head3 _get_db
Retrieves the database schema, removes auto-increment from the schema, and returns the modified schema.

View File

@ -928,8 +928,8 @@ sub message_broker_check {
if ( $tab eq 'database' ) {
use Koha::Database::Auditor;
my $db_auditor = Koha::Database::Auditor->new( { is_cli => 0 } );
my $db_auditor = Koha::Database::Auditor->new();
my $audit_diff = $db_auditor->run;
$template->param( audit_diff => $audit_diff, audit_warning => $db_auditor->get_warning );
$template->param( audit_diff => $audit_diff );
}
output_html_with_http_headers $query, $cookie, $template->output;

View File

@ -36,24 +36,24 @@
[% WRAPPER tab_item linktab = 1 tabname = "about" bt_active = tab == "about" %] <span>Server information</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "perl" bt_active = tab == "perl" %] <span>Perl modules</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "sysinfo" bt_active = tab == "sysinfo" %] <span>System information</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "database" bt_active = tab == "database" %] <span>Database audit</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "team" bt_active = tab == "team" %] <span>Koha team</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "licenses" bt_active = tab == "licenses" %] <span>Licenses</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "translations" bt_active = tab == "translations" %] <span>Translations</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "history" bt_active = tab == "history" %] <span>Timeline</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "dedications" bt_active = tab == "dedications" %] <span>Dedications</span> [% END %]
[% WRAPPER tab_item linktab = 1 tabname = "database" bt_active = tab == "database" %] <span>Database audit</span> [% END %]
[% END %]
[% WRAPPER tab_panels %]
[% SWITCH tab %]
[% CASE 'about' %] [% PROCESS about_panel %]
[% CASE 'perl' %] [% PROCESS perl_panel %]
[% CASE 'sysinfo' %] [% PROCESS sysinfo_panel %]
[% CASE 'database' %] [% PROCESS database_panel %]
[% CASE 'team' %] [% PROCESS team_panel %]
[% CASE 'licenses' %] [% PROCESS licenses_panel %]
[% CASE 'translations' %] [% PROCESS translations_panel %]
[% CASE 'history' %] [% PROCESS history_panel %]
[% CASE 'dedications' %] [% PROCESS dedications_panel %]
[% CASE 'database' %] [% PROCESS database_panel %]
[% CASE %] [% PROCESS about_panel %]
[% END %]
[% END %]
@ -795,6 +795,25 @@
[% END # tab=sysinfo %]
[% END %]
[% BLOCK database_panel %]
[% WRAPPER tab_panel tabname= "database" bt_active = 1 %]
<h2>Database audit</h2>
<div class="alert alert-warning">
<h3>WARNING!!!</h3>
<p>
These commands are only suggestions! They are not a replacement for updatedatabase.pl!<br />
Review the database, updatedatabase.pl, and kohastructure.sql before making any changes!<br />
</p>
</div>
<div>
<p>Run the following SQL to fix the database:</p>
<pre>
<code>[% audit_diff | $raw %]</code>
</pre>
</div>
[% END # tab=database %]
[% END %]
[% BLOCK team_panel %]
[% WRAPPER tab_panel tabname= "team" bt_active = 1 %]
<h2>Special thanks to the following organizations</h2>
@ -1352,14 +1371,3 @@
</p>
[% END # tab=dedications %]
[% END %]
[% BLOCK database_panel %]
[% WRAPPER tab_panel tabname= "database" bt_active = 1 %]
<h2>Database audit</h2>
<p>Run the following SQL to fix the database:</p>
<code>
[% audit_diff | html %]
</code>
<p class="alert alert-warning">[% audit_warning | html %]</p>
[% END # tab=database %]
[% END %]

View File

@ -11,4 +11,12 @@ GetOptions(
"filename=s" => \$filename,
) or die("Error in command line arguments\n");
Koha::Database::Auditor->new( { filename => $filename, is_cli => 1 } )->run;
my $auditor = Koha::Database::Auditor->new( { filename => $filename } );
my $diff = $auditor->run;
my $warning = "\n"
. "WARNING!!!\n"
. "These commands are only suggestions! They are not a replacement for updatedatabase.pl!\n"
. "Review the database, updatedatabase.pl, and kohastructure.sql before making any changes!\n" . "\n";
print $diff . $warning;