3 # This file is part of Koha.
5 # Copyright 2014 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use C4
::Charset
qw( SanitizeRecord );
30 my ( $help, $verbose, $confirm, $biblionumbers, $reindex, $filename,
31 $auto_search, $fix_ampersand );
32 my $result = GetOptions
(
34 'v|verbose' => \
$verbose,
35 'c|confirm' => \
$confirm,
36 'biblionumbers:s' => \
$biblionumbers,
37 'reindex' => \
$reindex,
38 'f|filename:s' => \
$filename,
39 'auto-search' => \
$auto_search,
40 'fix-ampersand' => \
$fix_ampersand,
43 # This script only fix ampersand at the moment.
44 # It is enabled by default.
51 unless ( $filename or $biblionumbers or $auto_search ) {
55 qq{\n\tAt least one record number source should be provided
.\n}
59 if ( $filename and $biblionumbers
60 or $filename and $auto_search
61 or $biblionumbers and $auto_search )
65 -message
=> qq{\n\tOnly one record number source should be provided
.\n}
71 # We first detect if we have a file or biblos directly entered by command line
72 #or if we want to use findAmp() sub
74 @biblionumbers = biblios_to_sanitize
();
78 open( my $fh, '<', $filename ) || die("Can't open $filename ($!)");
82 push @biblionumbers, split( " |,", $line );
90 qq{\n\tThis filename does
not exist
. Please verify the path is correct
.\n}
95 @biblionumbers = split m
|,|, $biblionumbers if $biblionumbers;
99 s/(^\s*|\s*$)//g for @biblionumbers;
102 @biblionumbers = grep { !/^$/ } @biblionumbers;
104 say @biblionumbers . " records to process" if $verbose;
107 for my $biblionumber (@biblionumbers) {
108 print "processing record $biblionumber..." if $verbose;
109 unless ( $biblionumber =~ m
|^\d
+$| ) {
110 say " skipping. ERROR: Invalid biblionumber." if $verbose;
113 my $record = C4
::Biblio
::GetMarcBiblio
({ biblionumber
=> $biblionumber });
115 say " skipping. ERROR: Invalid record." if $verbose;
119 my ( $cleaned_record, $has_been_modified ) =
120 C4
::Charset
::SanitizeRecord
( $record, $biblionumber );
121 if ($has_been_modified) {
122 my $frameworkcode = C4
::Biblio
::GetFrameworkCode
($record);
124 C4
::Biblio
::ModBiblio
( $cleaned_record, $biblionumber, $frameworkcode )
126 push @changes, $biblionumber;
127 say " Done!" if $verbose;
130 say " Nothing to do." if $verbose;
138 . ( $confirm ?
"cleaned!" : "to clean." );
141 if ( $reindex and $confirm and @changes ) {
142 say "Now, reindexing using -b -v" if $verbose;
143 my $kohapath = C4
::Context
->config('intranetdir');
145 $kohapath/misc/migration_tools
/rebuild_zebra
.pl
-b
-v
-where
"biblionumber IN ( |
146 . join( ',', @changes ) . q| )"
151 sub biblios_to_sanitize
{
152 my $dbh = C4
::Context
->dbh;
156 WHERE format = 'marcxml'
158 AND metadata LIKE "%&amp;%"
160 return @
{ $dbh->selectcol_arrayref( $query, { Slice
=> {} }, C4
::Context
->preference('marcflavour') ) };
165 sanitize_records - This script sanitizes a record.
169 sanitize_records.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex] [--fix-ampersand]
171 You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search.
179 Print a brief help message
181 =item B<-v|--verbose>
185 =item B<-c|--confirm>
187 This flag must be provided in order for the script to actually
188 sanitize records. If it is not supplied, the script will
189 only report on the record list to process.
191 =item B<--biblionumbers=BIBLIONUMBER_LIST>
193 Give a biblionumber list using this parameter. They must be separated by
196 =item B<-f|--filename=FILENAME>
198 Give a biblionumber list using a filename. One biblionumber by line or separate them with a whitespace character.
200 =item B<--auto-search>
202 Automatically search records containing "&" in biblio_metadata.metadata or in the specified fields.
204 =item B<--fix-ampersand>
206 Replace '&' by '&' in the records.
207 Replace '&amp;amp;etc.' with '&' in the records.
211 Reindex the modified records.
217 Alex Arnaud <alex.arnaud@biblibre.com>
218 Christophe Croullebois <christophe.croullebois@biblibre.com>
219 Jonathan Druart <jonathan.druart@biblibre.com>
223 Copyright 2014 BibLibre
227 This file is part of Koha.
229 # Koha is free software; you can redistribute it and/or modify it
230 # under the terms of the GNU General Public License as published by
231 # the Free Software Foundation; either version 3 of the License, or
232 # (at your option) any later version.
234 # Koha is distributed in the hope that it will be useful, but
235 # WITHOUT ANY WARRANTY; without even the implied warranty of
236 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
237 # GNU General Public License for more details.
239 # You should have received a copy of the GNU General Public License
240 # along with Koha; if not, see <http://www.gnu.org/licenses>.