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

(-)a/C4/Charset.pm (-4 / +4 lines)
Lines 429-435 sub nsb_clean { Link Here
429
SanitizeRecord($marcrecord);
429
SanitizeRecord($marcrecord);
430
430
431
Sanitize a record
431
Sanitize a record
432
This routine is called in the maintenance script misc/maintenance/batch_sanitize_records.pl.
432
This routine is called in the maintenance script misc/maintenance/sanitize_records.pl.
433
It cleans any string with '&...', replacing it by '&'
433
It cleans any string with '&...', replacing it by '&'
434
434
435
=cut
435
=cut
Lines 444-450 sub SanitizeRecord { Link Here
444
    foreach my $field ( $record->fields() ) {
444
    foreach my $field ( $record->fields() ) {
445
        if ( $field->is_control_field() ) {
445
        if ( $field->is_control_field() ) {
446
            my $value           = $field->data();
446
            my $value           = $field->data();
447
            my $sanitized_value = _entity_clean($value);
447
            my $sanitized_value = _clean_ampersand($value);
448
            $record_modified = 1 if $sanitized_value ne $value;
448
            $record_modified = 1 if $sanitized_value ne $value;
449
            $field->update($sanitized_value);
449
            $field->update($sanitized_value);
450
        }
450
        }
Lines 456-462 sub SanitizeRecord { Link Here
456
                  if $url_field eq $field->tag()
456
                  if $url_field eq $field->tag()
457
                      and $url_subfield eq $subfield->[0];
457
                      and $url_subfield eq $subfield->[0];
458
                my $value           = $subfield->[1];
458
                my $value           = $subfield->[1];
459
                my $sanitized_value = _entity_clean($value);
459
                my $sanitized_value = _clean_ampersand($value);
460
                push @new_subfields, $subfield->[0] => $sanitized_value;
460
                push @new_subfields, $subfield->[0] => $sanitized_value;
461
                $record_modified = 1 if $sanitized_value ne $value;
461
                $record_modified = 1 if $sanitized_value ne $value;
462
            }
462
            }
Lines 481-487 sub SanitizeRecord { Link Here
481
    return $record, $record_modified;
481
    return $record, $record_modified;
482
}
482
}
483
483
484
sub _entity_clean {
484
sub _clean_ampersand {
485
    my ($string) = @_;
485
    my ($string) = @_;
486
    $string =~ s/(&)(amp;)+/$1/g;
486
    $string =~ s/(&)(amp;)+/$1/g;
487
    return $string;
487
    return $string;
(-)a/misc/maintenance/batch_sanitize_records.pl (-5 / +14 lines)
Lines 26-32 use Getopt::Long; Link Here
26
use Pod::Usage;
26
use Pod::Usage;
27
27
28
my ( $help, $verbose, $confirm, $biblionumbers, $reindex, $filename,
28
my ( $help, $verbose, $confirm, $biblionumbers, $reindex, $filename,
29
    $auto_search );
29
    $auto_search, $fix_ampersand );
30
my $result = GetOptions(
30
my $result = GetOptions(
31
    'h|help'          => \$help,
31
    'h|help'          => \$help,
32
    'v|verbose'       => \$verbose,
32
    'v|verbose'       => \$verbose,
Lines 35-42 my $result = GetOptions( Link Here
35
    'reindex'         => \$reindex,
35
    'reindex'         => \$reindex,
36
    'f|filename:s'    => \$filename,
36
    'f|filename:s'    => \$filename,
37
    'auto-search'     => \$auto_search,
37
    'auto-search'     => \$auto_search,
38
    'fix-ampersand'   => \$fix_ampersand,
38
) || pod2usage(1);
39
) || pod2usage(1);
39
40
41
# This script only fix ampersand at the moment.
42
# It is enabled by default.
43
$fix_ampersand = 1;
44
40
if ($help) {
45
if ($help) {
41
    pod2usage(0);
46
    pod2usage(0);
42
}
47
}
Lines 154-166 sub biblios_to_sanitize { Link Here
154
159
155
=head1 NAME
160
=head1 NAME
156
161
157
batch_sanitize_biblios - This script sanitizes a biblio, replacing '&etc.' with '&' in it.
162
sanitize_records - This script sanitizes a record.
158
163
159
=head1 SYNOPSIS
164
=head1 SYNOPSIS
160
165
161
batch_sanitize_biblios.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex]
166
sanitize_records.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex] [--fix-ampersand]
162
167
163
Replace '&' by '&' in a record. You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search.
168
You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search.
164
169
165
=head1 OPTIONS
170
=head1 OPTIONS
166
171
Lines 193-198 Give a biblionumber list using a filename. One biblionumber by line or separate Link Here
193
198
194
Automatically search records containing "&" in biblioitems.marcxml or in the specified fields.
199
Automatically search records containing "&" in biblioitems.marcxml or in the specified fields.
195
200
201
=item B<--fix-ampersand>
202
203
Replace '&amp;' by '&' in the records.
204
Replace '&amp;amp;amp;etc.' with '&amp;' in the records.
205
196
=item B<--reindex>
206
=item B<--reindex>
197
207
198
Reindex the modified records.
208
Reindex the modified records.
199
- 

Return to bug 8218