From 7484b455a7b4187d86df001d4acfe80ec8d3f1a6 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 1 Dec 2015 12:00:10 +0100 Subject: [PATCH] Bug 15188 - remove_unused_authorities.pl exit if all authorities should be deleted --- misc/migration_tools/remove_unused_authorities.pl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/misc/migration_tools/remove_unused_authorities.pl b/misc/migration_tools/remove_unused_authorities.pl index 2509318..f48cb39 100755 --- a/misc/migration_tools/remove_unused_authorities.pl +++ b/misc/migration_tools/remove_unused_authorities.pl @@ -30,9 +30,11 @@ use Getopt::Long; my @authtypes; my $want_help = 0; my $test = 0; +my $force = 0; GetOptions( 'aut|authtypecode:s' => \@authtypes, 't|test' => \$test, + 'f|force' => \$force, 'h|help' => \$want_help ); @@ -59,6 +61,7 @@ $rqselect->execute; my $counter=0; my $totdeleted=0; my $totundeleted=0; +my @to_delete; while (my $data=$rqselect->fetchrow_hashref){ my $query; $query= "an=".$data->{'authid'}; @@ -72,13 +75,29 @@ while (my $data=$rqselect->fetchrow_hashref){ print "$counter\n" unless $counter++ % 100; # if found, delete, otherwise, just count if ($used>=$thresholdmin and $used<=$thresholdmax){ - DelAuthority($data->{'authid'}) unless $test; + push @to_delete, $data->{'authid'}; $totdeleted++; } else { $totundeleted++; } } +if ($totdeleted >= $counter && !$force) { + print "\nTo many authorities to deleted ($totdeleted)\n"; + print "Please check zebra daemon is running. Use --force option to delete all authorities\n"; + exit; +} + +unless ($totdeleted) { + print "\n Nothing to delete\n"; + exit 1; +} + +unless ($test) { + print "Deleting $totdeleted ...\n"; + DelAuthority($_) for @to_delete; +} + print "$counter authorities parsed, $totdeleted deleted and $totundeleted unchanged because used\n"; -- 1.7.10.4