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>.
21 use C4::Charset qw( SanitizeRecord );
28 my ( $help, $verbose, $confirm, $biblionumbers, $reindex, $filename,
30 my $result = GetOptions(
32 'v|verbose' => \$verbose,
33 'c|confirm' => \$confirm,
34 'biblionumbers:s' => \$biblionumbers,
35 'reindex' => \$reindex,
36 'f|filename:s' => \$filename,
37 'auto-search' => \$auto_search,
44 unless ( $filename or $biblionumbers or $auto_search ) {
48 qq{\n\tAt least one record number source should be provided.\n}
52 if ( $filename and $biblionumbers
53 or $filename and $auto_search
54 or $biblionumbers and $auto_search )
58 -message => qq{\n\tOnly one record number source should be provided.\n}
64 # We first detect if we have a file or biblos directly entered by command line
65 #or if we want to use findAmp() sub
67 @biblionumbers = biblios_to_sanitize();
71 open( my $fh, '<', $filename ) || die("Can't open $filename ($!)");
75 push @biblionumbers, split( " |,", $line );
83 qq{\n\tThis filename does not exist. Please verify the path is correct.\n}
88 @biblionumbers = split m|,|, $biblionumbers if $biblionumbers;
92 s/(^\s*|\s*$)//g for @biblionumbers;
95 @biblionumbers = grep { !/^$/ } @biblionumbers;
97 say @biblionumbers . " records to process" if $verbose;
100 for my $biblionumber (@biblionumbers) {
101 print "processing record $biblionumber..." if $verbose;
102 unless ( $biblionumber =~ m|^\d+$| ) {
103 say " skipping. ERROR: Invalid biblionumber." if $verbose;
106 my $record = C4::Biblio::GetMarcBiblio($biblionumber);
108 say " skipping. ERROR: Invalid record." if $verbose;
112 my ( $cleaned_record, $has_been_modified ) =
113 C4::Charset::SanitizeRecord( $record, $biblionumber );
114 if ($has_been_modified) {
115 my $frameworkcode = C4::Biblio::GetFrameworkCode($record);
117 C4::Biblio::ModBiblio( $cleaned_record, $biblionumber, $frameworkcode )
119 push @changes, $biblionumber;
120 say " Done!" if $verbose;
123 say " Nothing to do." if $verbose;
131 . ( $confirm ? "cleaned!" : "to clean." );
134 if ( $reindex and $confirm and @changes ) {
135 say "Now, reindexing using -b -v" if $verbose;
136 my $kohapath = C4::Context->config('intranetdir');
138 $kohapath/misc/migration_tools/rebuild_zebra.pl -b -v -where "biblionumber IN ( |
139 . join( ',', @changes ) . q| )"
144 sub biblios_to_sanitize {
145 my $dbh = C4::Context->dbh;
152 return @{ $dbh->selectcol_arrayref( $query, { Slice => {} }, ) };
157 batch_sanitize_biblios - This script sanitizes a biblio, replacing '&amp;amp;etc.' with '&' in it.
161 batch_sanitize_biblios.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex]
163 Replace '&' by '&' in a record. You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search.
171 Print a brief help message
173 =item B<-v|--verbose>
177 =item B<-c|--confirm>
179 This flag must be provided in order for the script to actually
180 sanitize records. If it is not supplied, the script will
181 only report on the record list to process.
183 =item B<--biblionumbers=BIBLIONUMBER_LIST>
185 Give a biblionumber list using this parameter. They must be separated by
188 =item B<-f|--filename=FILENAME>
190 Give a biblionumber list using a filename. One biblionumber by line or separate them with a whitespace character.
192 =item B<--auto_search>
194 Automatically search records containing "&" in biblioitems.marcxml or in the specified fields.
198 Reindex the modified records.
204 Alex Arnaud <alex.arnaud@biblibre.com>
205 Christophe Croullebois <christophe.croullebois@biblibre.com>
206 Jonathan Druart <jonathan.druart@biblibre.com>
210 Copyright 2014 BibLibre
214 This file is part of Koha.
216 Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
217 Foundation; either version 3 of the License, or (at your option) any later version.
219 You should have received a copy of the GNU General Public License along
220 with Koha; if not, write to the Free Software Foundation, Inc.,
221 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.