From c55d197a1115958a1d21d6f98363b4e7789fb857 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 24 Dec 2024 13:09:02 +0000 Subject: [PATCH] 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. --- Koha/Database/Auditor.pm | 24 ++++++++++++++++-- about.pl | 4 +-- .../intranet-tmpl/prog/en/modules/about.tt | 25 +++++++++++-------- misc/maintenance/audit_database.pl | 12 +++------ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/Koha/Database/Auditor.pm b/Koha/Database/Auditor.pm index fd01ac4be83..cd78db36e66 100644 --- a/Koha/Database/Auditor.pm +++ b/Koha/Database/Auditor.pm @@ -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, + }; } } diff --git a/about.pl b/about.pl index 2d9419fd455..afb58e95556 100755 --- a/about.pl +++ b/about.pl @@ -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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index 9b5692c18a6..a0412157e63 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -798,19 +798,22 @@ [% BLOCK database_panel %] [% WRAPPER tab_panel tabname= "database" bt_active = 1 %]

Database audit

+ [% IF db_audit.diff_found %]
-

WARNING!!!

-

- These commands are only suggestions! They are not a replacement for updatedatabase.pl!
- Review the database, updatedatabase.pl, and kohastructure.sql before making any changes!
-

-
-
-

Run the following SQL to fix the database:

-
-            [% audit_diff | $raw %]
-        
+ [% ELSE %] +
+ [% END %] +

[% db_audit.title %]

+

[% db_audit.message %]

+ [% IF db_audit.diff_found %] +
+

Run the following SQL to fix the database:

+
+                    [% db_audit.diff | $raw %]
+                
+
+ [% END %] [% END # tab=database %] [% END %] diff --git a/misc/maintenance/audit_database.pl b/misc/maintenance/audit_database.pl index 2d821b692aa..f99bc899a94 100755 --- a/misc/maintenance/audit_database.pl +++ b/misc/maintenance/audit_database.pl @@ -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} : '' ); -- 2.39.5