From 118ca7ac41fdc40a3ac0d144a003312492830580 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) Add the -schema parameter to script too Content-Type: text/plain; charset=utf-8 Finally adding it here 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 --- Koha/Database/Commenter.pm | 6 ++++-- misc/maintenance/sync_db_comments.pl | 12 +++++++++--- 2 files changed, 13 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 5014c4ac68..bded6945fd 100755 --- a/misc/maintenance/sync_db_comments.pl +++ b/misc/maintenance/sync_db_comments.pl @@ -36,12 +36,17 @@ GetOptions( 'help|h' => \$cmd_args->{help}, 'renumber' => \$cmd_args->{renumber}, 'reset' => \$cmd_args->{reset}, + '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 }); +my $commenter = Koha::Database::Commenter->new({ + 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} ) { pod2usage( -verbose => 2 ); @@ -71,7 +76,7 @@ misc/maintenance/sync_db_comments.pl =head1 SYNOPSIS - perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-commit] [-clear|-reset|-renumber] + perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-schema SCHEMA_FILE] [-commit] [-clear|-reset|-renumber] =head1 DESCRIPTION @@ -91,9 +96,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.30.2