From af8c1ba574c61aabf0bcd8d1c9a518ea7efa1aff Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 3 May 2024 10:09:58 +0100 Subject: [PATCH] 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 Signed-off-by: JesseM Signed-off-by: Kyle M Hall --- Koha/Database/Auditor.pm | 27 ++------------- about.pl | 4 +-- .../intranet-tmpl/prog/en/modules/about.tt | 34 ++++++++++++------- misc/maintenance/audit_database.pl | 10 +++++- 4 files changed, 34 insertions(+), 41 deletions(-) diff --git a/Koha/Database/Auditor.pm b/Koha/Database/Auditor.pm index 520387bccce..ff0dc8533f4 100644 --- a/Koha/Database/Auditor.pm +++ b/Koha/Database/Auditor.pm @@ -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. diff --git a/about.pl b/about.pl index f11b7ecd203..f0e8f3b7230 100755 --- a/about.pl +++ b/about.pl @@ -908,8 +908,8 @@ if ( $tab eq 'history' ) { 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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index f32079eae89..e48d2922357 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -36,24 +36,24 @@ [% WRAPPER tab_item linktab = 1 tabname = "about" bt_active = tab == "about" %] Server information [% END %] [% WRAPPER tab_item linktab = 1 tabname = "perl" bt_active = tab == "perl" %] Perl modules [% END %] [% WRAPPER tab_item linktab = 1 tabname = "sysinfo" bt_active = tab == "sysinfo" %] System information [% END %] + [% WRAPPER tab_item linktab = 1 tabname = "database" bt_active = tab == "database" %] Database audit [% END %] [% WRAPPER tab_item linktab = 1 tabname = "team" bt_active = tab == "team" %] Koha team [% END %] [% WRAPPER tab_item linktab = 1 tabname = "licenses" bt_active = tab == "licenses" %] Licenses [% END %] [% WRAPPER tab_item linktab = 1 tabname = "translations" bt_active = tab == "translations" %] Translations [% END %] [% WRAPPER tab_item linktab = 1 tabname = "history" bt_active = tab == "history" %] Timeline [% END %] [% WRAPPER tab_item linktab = 1 tabname = "dedications" bt_active = tab == "dedications" %] Dedications [% END %] - [% WRAPPER tab_item linktab = 1 tabname = "database" bt_active = tab == "database" %] Database audit [% 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 %] @@ -781,6 +781,25 @@ [% END # tab=sysinfo %] [% END %] +[% BLOCK database_panel %] + [% WRAPPER tab_panel tabname= "database" bt_active = 1 %] +

Database audit

+
+

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 %]
+        
+
+ [% END # tab=database %] +[% END %] + [% BLOCK team_panel %] [% WRAPPER tab_panel tabname= "team" bt_active = 1 %]

Special thanks to the following organizations

@@ -1343,14 +1362,3 @@

[% END # tab=dedications %] [% END %] - -[% BLOCK database_panel %] - [% WRAPPER tab_panel tabname= "database" bt_active = 1 %] -

Database audit

-

Run the following SQL to fix the database:

- - [% audit_diff | html %] - -

[% audit_warning | html %]

- [% END # tab=database %] -[% END %] \ No newline at end of file diff --git a/misc/maintenance/audit_database.pl b/misc/maintenance/audit_database.pl index cd624305c3b..2d821b692aa 100755 --- a/misc/maintenance/audit_database.pl +++ b/misc/maintenance/audit_database.pl @@ -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; -- 2.30.2