Bug 36039: (QA follow-up): Improve audit messages

Improve messages clarity.
Show success message if no schema diff was found from audit.
Code refactor to ensure the title+message shown in UI is the same as the one shown in CLI and are all translatable.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Pedro Amorim 2024-12-24 13:09:02 +00:00 committed by Katrin Fischer
parent 42c1e109af
commit 7834d25fb4
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
4 changed files with 41 additions and 24 deletions

View File

@ -51,7 +51,10 @@ sub new {
=head3 run
Run the database audit with the given arguments, including the filename.
Compares the current database schema with the expected schema from the
`kohastructure.sql` file. Generates SQL commands to update the database schema
if differences are found. Returns a hash reference containing the differences,
a flag indicating if differences were found, a message, and a title.
=cut
@ -74,7 +77,24 @@ sub run {
}
)->compute_differences->produce_diff_sql;
return $diff;
my $diff_found = 1;
my $message = __(
"These commands are only suggestions. They are not a replacement for the database update scripts run during installations and updates.\nReview the database, the atomic update files and the table definitions in kohastructure.sql before running any of the commands below:"
);
my $title = __("Warning!");
if ( $diff =~ /No differences found/ ) {
$diff_found = 0;
$message = __("The installed database schema is correct.");
$title = __("All is well");
}
return {
diff => $diff,
diff_found => $diff_found,
message => $message,
title => $title,
};
}
}

View File

@ -929,7 +929,7 @@ sub message_broker_check {
if ( $tab eq 'database' ) {
use Koha::Database::Auditor;
my $db_auditor = Koha::Database::Auditor->new();
my $audit_diff = $db_auditor->run;
$template->param( audit_diff => $audit_diff );
my $db_audit = $db_auditor->run;
$template->param( db_audit => $db_audit );
}
output_html_with_http_headers $query, $cookie, $template->output;

View File

@ -798,19 +798,22 @@
[% BLOCK database_panel %]
[% WRAPPER tab_panel tabname= "database" bt_active = 1 %]
<h2>Database audit</h2>
[% IF db_audit.diff_found %]
<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>
[% ELSE %]
<div class="alert alert-success">
[% END %]
<h3><strong>[% db_audit.title | html %]</strong></h3>
<p><pre>[% db_audit.message | html %]</pre><p>
</div>
[% IF db_audit.diff_found %]
<div>
<p>Run the following SQL to fix the database:</p>
<pre>
<code>[% db_audit.diff | $raw %]</code>
</pre>
</div>
[% END %]
[% END # tab=database %]
[% END %]

View File

@ -11,12 +11,6 @@ GetOptions(
"filename=s" => \$filename,
) or die("Error in command line arguments\n");
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;
my $auditor = Koha::Database::Auditor->new( { filename => $filename } );
my $db_audit = $auditor->run;
print $db_audit->{title} . "\n" . $db_audit->{message} . "\n" . ( $db_audit->{diff_found} ? $db_audit->{diff} : '' );