From 813aaa69699d98cdef11ed7097fcf426df2f68ef Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Oct 2023 10:51:38 -0300 Subject: [PATCH] Bug 34064: Tidy script Signed-off-by: Tomas Cohen Arazi --- misc/maintenance/audit_database.pl | 43 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/misc/maintenance/audit_database.pl b/misc/maintenance/audit_database.pl index d64f9bbc43..ac287c2571 100755 --- a/misc/maintenance/audit_database.pl +++ b/misc/maintenance/audit_database.pl @@ -13,19 +13,21 @@ GetOptions( "filename=s" => \$filename, ) or die("Error in command line arguments\n"); -if ( ! -f $filename ){ +if ( !-f $filename ) { die("Filename '$filename' does not exist\n"); } -my $sql_schema = get_kohastructure({ filename => $filename, }); -my $db_schema = get_db(); +my $sql_schema = get_kohastructure( { filename => $filename, } ); +my $db_schema = get_db(); -if ($sql_schema && $db_schema){ - my $diff = SQL::Translator::Diff->new({ - output_db => 'MySQL', - source_schema => $db_schema, - target_schema => $sql_schema, - })->compute_differences->produce_diff_sql; +if ( $sql_schema && $db_schema ) { + my $diff = SQL::Translator::Diff->new( + { + output_db => 'MySQL', + source_schema => $db_schema, + target_schema => $sql_schema, + } + )->compute_differences->produce_diff_sql; print $diff; print "\n"; @@ -38,9 +40,9 @@ if ($sql_schema && $db_schema){ sub get_db { my $database_name = C4::Context->config("database"); print "Parsing schema for database '$database_name'\n"; - my $dbh = C4::Context->dbh; + my $dbh = C4::Context->dbh; my $parser = SQL::Translator->new( - parser => 'DBI', + parser => 'DBI', parser_args => { dbh => $dbh, }, @@ -50,20 +52,19 @@ sub get_db { #NOTE: Hack the schema to remove autoincrement #Otherwise, that difference will cause options for all tables to be reset unnecessarily my @tables = $schema->get_tables(); - foreach my $table (@tables){ - my @new_options = (); + foreach my $table (@tables) { + my @new_options = (); my $replace_options = 0; - my $options = $table->{options}; - foreach my $hashref (@$options){ - if ( $hashref->{AUTO_INCREMENT} ){ + my $options = $table->{options}; + foreach my $hashref (@$options) { + if ( $hashref->{AUTO_INCREMENT} ) { $replace_options = 1; - } - else { - push(@new_options,$hashref); + } else { + push( @new_options, $hashref ); } } - if ($replace_options){ - @{$table->{options}} = @new_options; + if ($replace_options) { + @{ $table->{options} } = @new_options; } } return $schema; -- 2.39.5