@@ -, +, @@ - 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. --- C4/Charset.pm | 8 ++++---- .../{batch_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%) --- a/C4/Charset.pm +++ a/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; --- a/misc/maintenance/batch_sanitize_records.pl +++ a/misc/maintenance/batch_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. --