From 3443056e15d7f2cc36e137a5ac50580375f3e1e4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Nov 2014 16:09:04 +0100 Subject: [PATCH] Bug 8218: qa followup This patch - rename _entity_clean as _clean_ampersand - rename the script to sanitize_records.pl - add a --fix-ampersand switch (the only one FOR NOW, enabled by default) so it is obvious what the script does. - make POD and usage reflect this changes. Signed-off-by: Tomas Cohen Arazi --- C4/Charset.pm | 8 ++++---- ...sanitize_records.pl => sanitize_records.pl} | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) rename misc/maintenance/{batch_sanitize_records.pl => sanitize_records.pl} (90%) diff --git a/C4/Charset.pm b/C4/Charset.pm index e56422fced..e43404bce2 100644 --- a/C4/Charset.pm +++ b/C4/Charset.pm @@ -429,7 +429,7 @@ sub nsb_clean { SanitizeRecord($marcrecord); Sanitize a record -This routine is called in the maintenance script misc/maintenance/batch_sanitize_records.pl. +This routine is called in the maintenance script misc/maintenance/sanitize_records.pl. It cleans any string with '&amp;...', replacing it by '&' =cut @@ -444,7 +444,7 @@ sub SanitizeRecord { foreach my $field ( $record->fields() ) { if ( $field->is_control_field() ) { my $value = $field->data(); - my $sanitized_value = _entity_clean($value); + my $sanitized_value = _clean_ampersand($value); $record_modified = 1 if $sanitized_value ne $value; $field->update($sanitized_value); } @@ -456,7 +456,7 @@ sub SanitizeRecord { if $url_field eq $field->tag() and $url_subfield eq $subfield->[0]; my $value = $subfield->[1]; - my $sanitized_value = _entity_clean($value); + my $sanitized_value = _clean_ampersand($value); push @new_subfields, $subfield->[0] => $sanitized_value; $record_modified = 1 if $sanitized_value ne $value; } @@ -481,7 +481,7 @@ sub SanitizeRecord { return $record, $record_modified; } -sub _entity_clean { +sub _clean_ampersand { my ($string) = @_; $string =~ s/(&)(amp;)+/$1/g; return $string; diff --git a/misc/maintenance/batch_sanitize_records.pl b/misc/maintenance/sanitize_records.pl similarity index 90% rename from misc/maintenance/batch_sanitize_records.pl rename to misc/maintenance/sanitize_records.pl index b164ec225e..b9caa4bfb7 100755 --- a/misc/maintenance/batch_sanitize_records.pl +++ b/misc/maintenance/sanitize_records.pl @@ -26,7 +26,7 @@ use Getopt::Long; use Pod::Usage; my ( $help, $verbose, $confirm, $biblionumbers, $reindex, $filename, - $auto_search ); + $auto_search, $fix_ampersand ); my $result = GetOptions( 'h|help' => \$help, 'v|verbose' => \$verbose, @@ -35,8 +35,13 @@ my $result = GetOptions( 'reindex' => \$reindex, 'f|filename:s' => \$filename, 'auto-search' => \$auto_search, + 'fix-ampersand' => \$fix_ampersand, ) || pod2usage(1); +# This script only fix ampersand at the moment. +# It is enabled by default. +$fix_ampersand = 1; + if ($help) { pod2usage(0); } @@ -154,13 +159,13 @@ sub biblios_to_sanitize { =head1 NAME -batch_sanitize_biblios - This script sanitizes a biblio, replacing '&amp;amp;etc.' with '&' in it. +sanitize_records - This script sanitizes a record. =head1 SYNOPSIS -batch_sanitize_biblios.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex] +sanitize_records.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex] [--fix-ampersand] -Replace '&' by '&' in a record. You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search. +You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search. =head1 OPTIONS @@ -193,6 +198,11 @@ Give a biblionumber list using a filename. One biblionumber by line or separate Automatically search records containing "&" in biblioitems.marcxml or in the specified fields. +=item B<--fix-ampersand> + +Replace '&' by '&' in the records. +Replace '&amp;amp;etc.' with '&' in the records. + =item B<--reindex> Reindex the modified records. -- 2.39.5