From dd56960c1166960ae320025eed0dfa5bda7f77aa Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 22 Aug 2012 15:06:23 +0200 Subject: [PATCH] Bug 8218: Followup: Perltidy and QA FIX --- misc/maintenance/batchSanitizeEntity.pl | 85 ++++++++++++++++--------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/misc/maintenance/batchSanitizeEntity.pl b/misc/maintenance/batchSanitizeEntity.pl index c3b5344..7219a2b 100755 --- a/misc/maintenance/batchSanitizeEntity.pl +++ b/misc/maintenance/batchSanitizeEntity.pl @@ -18,7 +18,7 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use warnings; +use Modern::Perl; use C4::Charset; use C4::Context; use DBI; @@ -26,16 +26,16 @@ use C4::Biblio; use Getopt::Long; use Pod::Usage; -my ($biblios,$run,$want_help); +my ( $biblios, $run, $want_help, $batch ); my $result = GetOptions( - 'where=s' => \$biblios, - '--run' => \$run, - 'help|h' => \$want_help, - 'batch|b' => \$batch, + 'where=s' => \$biblios, + '--run' => \$run, + 'help|h' => \$want_help, + 'batch|b' => \$batch, ); # We check if required entries are given : -if ( not $result or $want_help or not $biblios or not $run) { +if ( not $result or $want_help or not $biblios or not $run ) { print_usage(); exit 0; } @@ -50,37 +50,35 @@ my $record; my $cleanrecord; # We first detect if we have a file or biblos directly entered by command line or if we want to use findAmp() sub : -if ($biblios eq "search"){ +if ( $biblios eq "search" ) { @biblios = findAmp(); } else { - if ($biblios =~ /\//) { - open (FILE, "$biblios") || die ("Can't open $biblios"); + if ( $biblios =~ m|/| ) { + open( FILE, "$biblios" ) || die("Can't open $biblios"); @bibliofile = ; - close (FILE); + close(FILE); } else { @biblionum = split ',', $biblios; } + # We take the biblios - @biblios = @bibliofile?@bibliofile:@biblionum; + @biblios = @bibliofile ? @bibliofile : @biblionum; } # We remove spaces -my @biblio; -foreach my $bib(@biblios) { - $bib =~ s/(^\s*|\s*$)//g; - next if $bib eq ""; - push @biblio, $bib; -} -@biblios = @biblio; +s/(^\s*|\s*$)//g for @biblios; +# Remove empty lines +@biblios = grep {!/^$/} @biblios; # We valid the input foreach my $biblio (@biblios) { - if ($biblio !~ /^\d+$/){ - print "=============== \"$biblio\" is not a biblionumber !!! ===============\n"; + if ( $biblio !~ /^\d+$/ ) { + print +"=============== \"$biblio\" is not a biblionumber !!! ===============\n"; print "=============== please verify \"$biblio\" !!! ===============\n"; - $count += 1; + $count++; } exit(1) if $count; } @@ -88,30 +86,32 @@ foreach my $biblio (@biblios) { $bibliocount = scalar @biblios; my $confirm = 0; -print "=============== $bibliocount Biblio(s) ready to be cleaned ===============\n"; -if (!$batch) { +print +"=============== $bibliocount Biblio(s) ready to be cleaned ===============\n"; +if ( !$batch ) { print "=============== You are ok ? Types yes/no :\n"; - while ($confirm == 0){ - my $prout = ; - if ($prout eq "yes\n") { - $confirm = 1; - } - elsif ($prout eq "no\n") { - print "=============== Ok, bye ===============\n"; - exit(0); - } - else { - print "======= Bad answer please types 'yes' or 'no' !!!!!!!!!!! ===============\n"; - } - } + while ( $confirm == 0 ) { + my $prout = ; + if ( $prout eq "yes\n" ) { + $confirm = 1; + } + elsif ( $prout eq "no\n" ) { + print "=============== Ok, bye ===============\n"; + exit(0); + } + else { + print +"======= Bad answer please types 'yes' or 'no' !!!!!!!!!!! ===============\n"; + } + } } -foreach my $biblio (@biblios){ +foreach my $biblio (@biblios) { print "=============== N° $biblio selected ===============\n"; - $record = GetMarcBiblio($biblio); + $record = GetMarcBiblio($biblio); $cleanrecord = SanitizeEntity($record); my $frameworkcode = GetFrameworkCode($biblio); - ModBiblio($cleanrecord, $biblio, $frameworkcode); + ModBiblio( $cleanrecord, $biblio, $frameworkcode ); print "=============== Biblio n° $biblio done ===============\n"; } @@ -135,10 +135,11 @@ _USAGE_ sub findAmp { my @bibliosearch; my $dbh = C4::Context->dbh; - my $strsth = qq{SELECT biblionumber FROM biblioitems WHERE marcxml LIKE "%amp;amp;%"}; + my $strsth = + qq{SELECT biblionumber FROM biblioitems WHERE marcxml LIKE "%amp;amp;%"}; my $sth = $dbh->prepare($strsth); $sth->execute(); - while (my $bib = $sth-> fetchrow_array()){ + while ( my $bib = $sth->fetchrow_array() ) { push @bibliosearch, $bib; } return @bibliosearch; -- 1.7.10.4