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,
29 $auto_search, $fix_ampersand );
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,
38 'fix-ampersand' => \
$fix_ampersand,
41 # This script only fix ampersand at the moment.
42 # It is enabled by default.
49 unless ( $filename or $biblionumbers or $auto_search ) {
53 qq{\n\tAt least one record number source should be provided
.\n}
57 if ( $filename and $biblionumbers
58 or $filename and $auto_search
59 or $biblionumbers and $auto_search )
63 -message
=> qq{\n\tOnly one record number source should be provided
.\n}
69 # We first detect if we have a file or biblos directly entered by command line
70 #or if we want to use findAmp() sub
72 @biblionumbers = biblios_to_sanitize
();
76 open( my $fh, '<', $filename ) || die("Can't open $filename ($!)");
80 push @biblionumbers, split( " |,", $line );
88 qq{\n\tThis filename does
not exist
. Please verify the path is correct
.\n}
93 @biblionumbers = split m
|,|, $biblionumbers if $biblionumbers;
97 s/(^\s*|\s*$)//g for @biblionumbers;
100 @biblionumbers = grep { !/^$/ } @biblionumbers;
102 say @biblionumbers . " records to process" if $verbose;
105 for my $biblionumber (@biblionumbers) {
106 print "processing record $biblionumber..." if $verbose;
107 unless ( $biblionumber =~ m
|^\d
+$| ) {
108 say " skipping. ERROR: Invalid biblionumber." if $verbose;
111 my $record = C4
::Biblio
::GetMarcBiblio
($biblionumber);
113 say " skipping. ERROR: Invalid record." if $verbose;
117 my ( $cleaned_record, $has_been_modified ) =
118 C4
::Charset
::SanitizeRecord
( $record, $biblionumber );
119 if ($has_been_modified) {
120 my $frameworkcode = C4
::Biblio
::GetFrameworkCode
($record);
122 C4
::Biblio
::ModBiblio
( $cleaned_record, $biblionumber, $frameworkcode )
124 push @changes, $biblionumber;
125 say " Done!" if $verbose;
128 say " Nothing to do." if $verbose;
136 . ( $confirm ?
"cleaned!" : "to clean." );
139 if ( $reindex and $confirm and @changes ) {
140 say "Now, reindexing using -b -v" if $verbose;
141 my $kohapath = C4
::Context
->config('intranetdir');
143 $kohapath/misc/migration_tools
/rebuild_zebra
.pl
-b
-v
-where
"biblionumber IN ( |
144 . join( ',', @changes ) . q| )"
149 sub biblios_to_sanitize
{
150 my $dbh = C4
::Context
->dbh;
157 return @
{ $dbh->selectcol_arrayref( $query, { Slice
=> {} }, ) };
162 sanitize_records - This script sanitizes a record.
166 sanitize_records.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--biblionumbers=BIBLIONUMBER_LIST] [-f|--filename=FILENAME] [--auto-search] [--reindex] [--fix-ampersand]
168 You can either give some biblionumbers or a file with biblionumbers or ask for an auto-search.
176 Print a brief help message
178 =item B<-v|--verbose>
182 =item B<-c|--confirm>
184 This flag must be provided in order for the script to actually
185 sanitize records. If it is not supplied, the script will
186 only report on the record list to process.
188 =item B<--biblionumbers=BIBLIONUMBER_LIST>
190 Give a biblionumber list using this parameter. They must be separated by
193 =item B<-f|--filename=FILENAME>
195 Give a biblionumber list using a filename. One biblionumber by line or separate them with a whitespace character.
197 =item B<--auto_search>
199 Automatically search records containing "&" in biblioitems.marcxml or in the specified fields.
201 =item B<--fix-ampersand>
203 Replace '&' by '&' in the records.
204 Replace '&amp;amp;etc.' with '&' in the records.
208 Reindex the modified records.
214 Alex Arnaud <alex.arnaud@biblibre.com>
215 Christophe Croullebois <christophe.croullebois@biblibre.com>
216 Jonathan Druart <jonathan.druart@biblibre.com>
220 Copyright 2014 BibLibre
224 This file is part of Koha.
226 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
227 Foundation; either version 3 of the License, or (at your option) any later version.
229 You should have received a copy of the GNU General Public License along
230 with Koha; if not, write to the Free Software Foundation, Inc.,
231 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.