From 3b4aab475fa84043f8a9b5a1800a1e1d200a770e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 17 Mar 2023 07:46:44 +0000 Subject: [PATCH] Bug 32334: (follow-up) Improvement for schema parameter Essentially only adds a warn, some cosmetic changes too. Test plan: Copy your kohastructure to xx.sql. Run sync_db_comments.pl -schema xx.sql. You will see usage. Run sync_db_comments.pl -schema xyz.sql. You will see a warn and the usage statement. Signed-off-by: Marcel de Rooy Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- Koha/Database/Commenter.pm | 6 ++++-- misc/maintenance/sync_db_comments.pl | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Koha/Database/Commenter.pm b/Koha/Database/Commenter.pm index 2b37067c76..fb4048f1dc 100644 --- a/Koha/Database/Commenter.pm +++ b/Koha/Database/Commenter.pm @@ -77,7 +77,7 @@ sub new { unless ref($self->{dbh}) eq DBI_HANDLE_CLASS; $self->{database} //= ( $self->{dbh}->selectrow_array('SELECT DATABASE()') )[0]; - $self->_find_schema unless $self->{schema_file}; + $self->_find_schema; $self->{schema_info} = {}; return $self; @@ -159,7 +159,9 @@ sub renumber { sub _find_schema { my $self = shift; my $rootdir = C4::Context->config('intranetdir'); - if( -e "$rootdir/". KOHA_STRUCTURE ) { + if( $self->{schema_file} ) { + warn "File ". $self->{schema_file}. " not found!\n" if !-e $self->{schema_file}; + } elsif( -e "$rootdir/". KOHA_STRUCTURE ) { $self->{schema_file} = "$rootdir/". KOHA_STRUCTURE; } elsif( -e "$rootdir/intranet/cgi-bin/". KOHA_STRUCTURE ) { $self->{schema_file} = "$rootdir/intranet/cgi-bin/". KOHA_STRUCTURE; diff --git a/misc/maintenance/sync_db_comments.pl b/misc/maintenance/sync_db_comments.pl index 07ee001cb6..57cbdef381 100755 --- a/misc/maintenance/sync_db_comments.pl +++ b/misc/maintenance/sync_db_comments.pl @@ -36,14 +36,14 @@ GetOptions( 'help|h' => \$cmd_args->{help}, 'renumber' => \$cmd_args->{renumber}, 'reset' => \$cmd_args->{reset}, - 'schema:s' => \$cmd_args->{schema}, + 'schema:s' => \$cmd_args->{schema_file}, 'table:s' => \$cmd_args->{table}, 'verbose|v' => \$cmd_args->{verbose}, ); $cmd_args->{dry_run} = !$cmd_args->{commit}; my $commenter = Koha::Database::Commenter->new({ - database => delete $cmd_args->{database}, dbh => C4::Context->dbh, schema_file => delete $cmd_args->{schema}, + database => delete $cmd_args->{database}, dbh => C4::Context->dbh, schema_file => delete $cmd_args->{schema_file}, }); my $messages = $cmd_args->{verbose} || $cmd_args->{dry_run} ? [] : undef; if( $cmd_args->{help} ) { @@ -94,9 +94,10 @@ misc/maintenance/sync_db_comments.pl Clear all column comments in database. The verbose flag shows all issued ALTER TABLE statements. - misc/maintance/sync_db_comments.pl -reset -commit -database mydb -table items + misc/maintance/sync_db_comments.pl -reset -commit -database mydb -table items -schema newstructure.sql Only resets comments in items table. Operates on specific database instead of the one from $KOHA_CONF. + Reads the schema from the specified file instead of default one. misc/maintance/sync_db_comments.pl -renumber Renumbers all comments like Comment_1,2,.. -- 2.39.5