From 12b9584215fcfb7366f052f5a1274ed0358488f7 Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Wed, 15 Feb 2023 12:49:16 +0000
Subject: [PATCH] Bug 32334: (QA follow-up) Invert dry run mode to commit
 parameter

Note: This is only done (and 'needed') for the command line, not
for the module subroutines.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 misc/maintenance/sync_db_comments.pl | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/misc/maintenance/sync_db_comments.pl b/misc/maintenance/sync_db_comments.pl
index ffeb930e96e..c5eb8cfdbc1 100755
--- a/misc/maintenance/sync_db_comments.pl
+++ b/misc/maintenance/sync_db_comments.pl
@@ -30,14 +30,15 @@ use Koha::Database::Commenter;
 my $cmd_args = {};
 GetOptions(
   'clear'      => \$cmd_args->{clear},
+  'commit|c'   => \$cmd_args->{commit},
   'database:s' => \$cmd_args->{database},
-  'dry_run'    => \$cmd_args->{dry_run},
   'help|h'     => \$cmd_args->{help},
   'renumber'   => \$cmd_args->{renumber},
   'reset'      => \$cmd_args->{reset},
   '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 });
 if( $cmd_args->{help} ) {
@@ -45,19 +46,19 @@ if( $cmd_args->{help} ) {
 } elsif( ($cmd_args->{clear}||0) + ($cmd_args->{renumber}||0) + ($cmd_args->{reset}||0) > 1 ) {
     print "You cannot pass the clear, renumber and reset flags together\n";
 } elsif( delete $cmd_args->{clear} ) {
-    alert_dry_run( $cmd_args->{dry_run} );
+    alert_dry_run( $cmd_args );
     $commenter->clear( $cmd_args );
 } elsif( delete $cmd_args->{reset} ) {
-    alert_dry_run( $cmd_args->{dry_run} );
+    alert_dry_run( $cmd_args );
     $commenter->reset_to_schema( $cmd_args );
 } elsif( delete $cmd_args->{renumber} ) {
-    alert_dry_run( $cmd_args->{dry_run} );
+    alert_dry_run( $cmd_args );
     $commenter->renumber( $cmd_args );
 } else {
     pod2usage( -verbose => 1 );
 }
 
-sub alert_dry_run { print "-- DRY RUN\n" if $_[0]; }
+sub alert_dry_run { print "-- DRY RUN\n" if $_[0]->{dry_run}; }
 
 __END__
 
@@ -69,7 +70,7 @@ misc/maintenance/sync_db_comments.pl
 
 =head1 SYNOPSIS
 
-    perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-dry_run] [-clear|-reset|-renumber]
+    perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-commit] [-clear|-reset|-renumber]
 
 =head1 DESCRIPTION
 
@@ -85,18 +86,18 @@ misc/maintenance/sync_db_comments.pl
     misc/maintance/sync_db_comments.pl -help
     Usage statement.
 
-    misc/maintance/sync_db_comments.pl -clear -verbose
+    misc/maintance/sync_db_comments.pl -clear -commit -verbose
     Clear all column comments in database.
     The verbose flag shows all issued ALTER TABLE statements.
 
-    misc/maintance/sync_db_comments.pl -reset -database mydb -table items
+    misc/maintance/sync_db_comments.pl -reset -commit -database mydb -table items
     Only resets comments in items table.
     Operates on specific database instead of the one from $KOHA_CONF.
 
-    misc/maintance/sync_db_comments.pl -renumber -dry_run
+    misc/maintance/sync_db_comments.pl -renumber
     Renumbers all comments like Comment_1,2,..
     Added for testing purposes. Not meant to run on production.
-    The dry_run flag allows you to see what would be done.
+    Omitting the commit flag allows you to see what would be done (dry run).
 
 =head1 ADDITIONAL COMMENTS
 
-- 
2.25.1