View | Details | Raw Unified | Return to bug 32334
Collapse All | Expand All

(-)a/misc/maintenance/sync_db_comments.pl (-11 / +11 lines)
Lines 30-43 use Koha::Database::Commenter; Link Here
30
my $cmd_args = {};
30
my $cmd_args = {};
31
GetOptions(
31
GetOptions(
32
  'clear'      => \$cmd_args->{clear},
32
  'clear'      => \$cmd_args->{clear},
33
  'commit|c'   => \$cmd_args->{commit},
33
  'database:s' => \$cmd_args->{database},
34
  'database:s' => \$cmd_args->{database},
34
  'dry_run'    => \$cmd_args->{dry_run},
35
  'help|h'     => \$cmd_args->{help},
35
  'help|h'     => \$cmd_args->{help},
36
  'renumber'   => \$cmd_args->{renumber},
36
  'renumber'   => \$cmd_args->{renumber},
37
  'reset'      => \$cmd_args->{reset},
37
  'reset'      => \$cmd_args->{reset},
38
  'table:s'    => \$cmd_args->{table},
38
  'table:s'    => \$cmd_args->{table},
39
  'verbose|v'  => \$cmd_args->{verbose},
39
  'verbose|v'  => \$cmd_args->{verbose},
40
);
40
);
41
$cmd_args->{dry_run} = !$cmd_args->{commit};
41
42
42
my $commenter = Koha::Database::Commenter->new({ database => delete $cmd_args->{database}, dbh => C4::Context->dbh });
43
my $commenter = Koha::Database::Commenter->new({ database => delete $cmd_args->{database}, dbh => C4::Context->dbh });
43
if( $cmd_args->{help} ) {
44
if( $cmd_args->{help} ) {
Lines 45-63 if( $cmd_args->{help} ) { Link Here
45
} elsif( ($cmd_args->{clear}||0) + ($cmd_args->{renumber}||0) + ($cmd_args->{reset}||0) > 1 ) {
46
} elsif( ($cmd_args->{clear}||0) + ($cmd_args->{renumber}||0) + ($cmd_args->{reset}||0) > 1 ) {
46
    print "You cannot pass the clear, renumber and reset flags together\n";
47
    print "You cannot pass the clear, renumber and reset flags together\n";
47
} elsif( delete $cmd_args->{clear} ) {
48
} elsif( delete $cmd_args->{clear} ) {
48
    alert_dry_run( $cmd_args->{dry_run} );
49
    alert_dry_run( $cmd_args );
49
    $commenter->clear( $cmd_args );
50
    $commenter->clear( $cmd_args );
50
} elsif( delete $cmd_args->{reset} ) {
51
} elsif( delete $cmd_args->{reset} ) {
51
    alert_dry_run( $cmd_args->{dry_run} );
52
    alert_dry_run( $cmd_args );
52
    $commenter->reset_to_schema( $cmd_args );
53
    $commenter->reset_to_schema( $cmd_args );
53
} elsif( delete $cmd_args->{renumber} ) {
54
} elsif( delete $cmd_args->{renumber} ) {
54
    alert_dry_run( $cmd_args->{dry_run} );
55
    alert_dry_run( $cmd_args );
55
    $commenter->renumber( $cmd_args );
56
    $commenter->renumber( $cmd_args );
56
} else {
57
} else {
57
    pod2usage( -verbose => 1 );
58
    pod2usage( -verbose => 1 );
58
}
59
}
59
60
60
sub alert_dry_run { print "-- DRY RUN\n" if $_[0]; }
61
sub alert_dry_run { print "-- DRY RUN\n" if $_[0]->{dry_run}; }
61
62
62
__END__
63
__END__
63
64
Lines 69-75 misc/maintenance/sync_db_comments.pl Link Here
69
70
70
=head1 SYNOPSIS
71
=head1 SYNOPSIS
71
72
72
    perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-dry_run] [-clear|-reset|-renumber]
73
    perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-commit] [-clear|-reset|-renumber]
73
74
74
=head1 DESCRIPTION
75
=head1 DESCRIPTION
75
76
Lines 85-102 misc/maintenance/sync_db_comments.pl Link Here
85
    misc/maintance/sync_db_comments.pl -help
86
    misc/maintance/sync_db_comments.pl -help
86
    Usage statement.
87
    Usage statement.
87
88
88
    misc/maintance/sync_db_comments.pl -clear -verbose
89
    misc/maintance/sync_db_comments.pl -clear -commit -verbose
89
    Clear all column comments in database.
90
    Clear all column comments in database.
90
    The verbose flag shows all issued ALTER TABLE statements.
91
    The verbose flag shows all issued ALTER TABLE statements.
91
92
92
    misc/maintance/sync_db_comments.pl -reset -database mydb -table items
93
    misc/maintance/sync_db_comments.pl -reset -commit -database mydb -table items
93
    Only resets comments in items table.
94
    Only resets comments in items table.
94
    Operates on specific database instead of the one from $KOHA_CONF.
95
    Operates on specific database instead of the one from $KOHA_CONF.
95
96
96
    misc/maintance/sync_db_comments.pl -renumber -dry_run
97
    misc/maintance/sync_db_comments.pl -renumber
97
    Renumbers all comments like Comment_1,2,..
98
    Renumbers all comments like Comment_1,2,..
98
    Added for testing purposes. Not meant to run on production.
99
    Added for testing purposes. Not meant to run on production.
99
    The dry_run flag allows you to see what would be done.
100
    Omitting the commit flag allows you to see what would be done (dry run).
100
101
101
=head1 ADDITIONAL COMMENTS
102
=head1 ADDITIONAL COMMENTS
102
103
103
- 

Return to bug 32334