Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# small script that replaces '&etc.' by '&' in a record |
3 |
|
4 |
use warnings; |
5 |
use C4::Charset; |
6 |
use C4::Context; |
7 |
use DBI; |
8 |
use C4::Biblio; |
9 |
use Getopt::Long; |
10 |
use Pod::Usage; |
11 |
|
12 |
my ($biblios,$run,$want_help); |
13 |
my $result = GetOptions( |
14 |
'where=s' => \$biblios, |
15 |
'--run' => \$run, |
16 |
'help|h' => \$want_help, |
17 |
'batch|b' => \$batch, |
18 |
); |
19 |
|
20 |
# We check if required entries are given : |
21 |
if ( not $result or $want_help or not $biblios or not $run) { |
22 |
print_usage(); |
23 |
exit 0; |
24 |
} |
25 |
|
26 |
# We initialise some tools : |
27 |
my $count; |
28 |
my $bibliocount; |
29 |
my @bibliofile; |
30 |
my @biblionum; |
31 |
my @biblios; |
32 |
my $record; |
33 |
my $cleanrecord; |
34 |
|
35 |
# We first detect if we have a file or biblos directly entered by command line or if we want to use findAmp() sub : |
36 |
if ($biblios eq "search"){ |
37 |
@biblios = findAmp(); |
38 |
} |
39 |
else { |
40 |
if ($biblios =~ /\//) { |
41 |
open (FILE, "$biblios") || die ("Can't open $biblios"); |
42 |
@bibliofile = <FILE>; |
43 |
close (FILE); |
44 |
} |
45 |
else { |
46 |
@biblionum = split ',', $biblios; |
47 |
} |
48 |
# We take the biblios |
49 |
@biblios = @bibliofile?@bibliofile:@biblionum; |
50 |
} |
51 |
|
52 |
# We remove spaces |
53 |
my @biblio; |
54 |
foreach my $bib(@biblios) { |
55 |
$bib =~ s/(^\s*|\s*$)//g; |
56 |
next if $bib eq ""; |
57 |
push @biblio, $bib; |
58 |
} |
59 |
@biblios = @biblio; |
60 |
|
61 |
# We valid the input |
62 |
foreach my $biblio (@biblios) { |
63 |
if ($biblio !~ /^\d+$/){ |
64 |
print "=============== \"$biblio\" is not a biblionumber !!! ===============\n"; |
65 |
print "=============== please verify \"$biblio\" !!! ===============\n"; |
66 |
$count += 1; |
67 |
} |
68 |
exit(1) if $count; |
69 |
} |
70 |
|
71 |
$bibliocount = scalar @biblios; |
72 |
my $confirm = 0; |
73 |
|
74 |
print "=============== $bibliocount Biblio(s) ready to be cleaned ===============\n"; |
75 |
if (!$batch) { |
76 |
print "=============== You are ok ? Types yes/no :\n"; |
77 |
while ($confirm == 0){ |
78 |
my $prout = <STDIN>; |
79 |
if ($prout eq "yes\n") { |
80 |
$confirm = 1; |
81 |
} |
82 |
elsif ($prout eq "no\n") { |
83 |
print "=============== Ok, bye ===============\n"; |
84 |
exit(0); |
85 |
} |
86 |
else { |
87 |
print "======= Bad answer please types 'yes' or 'no' !!!!!!!!!!! ===============\n"; |
88 |
} |
89 |
} |
90 |
} |
91 |
|
92 |
foreach my $biblio (@biblios){ |
93 |
print "=============== N° $biblio selected ===============\n"; |
94 |
$record = GetMarcBiblio($biblio); |
95 |
$cleanrecord = SanitizeEntity($record); |
96 |
my $frameworkcode = GetFrameworkCode($biblio); |
97 |
ModBiblio($cleanrecord, $biblio, $frameworkcode); |
98 |
print "=============== Biblio n° $biblio done ===============\n"; |
99 |
} |
100 |
|
101 |
print "==============================================================\n"; |
102 |
print "=============== $bibliocount Biblios processed ===============\n"; |
103 |
|
104 |
sub print_usage { |
105 |
print <<_USAGE_; |
106 |
$0: replaces '&' by '&' in a record, you can either give some biblionumbers or a file with biblionumbers or |
107 |
|
108 |
Parameters: |
109 |
-where use this to give biblionumbers in a string with "" (separated by coma) |
110 |
or an absolute path to a file containing biblionumbers (1 by row) |
111 |
or the command 'search' that creates an array with biblionumbers with "&amp;..." |
112 |
--run run the command |
113 |
--batch run in batch mode |
114 |
--help or -h show this message. |
115 |
_USAGE_ |
116 |
} |
117 |
|
118 |
sub findAmp { |
119 |
my @bibliosearch; |
120 |
my $dbh = C4::Context->dbh; |
121 |
my $strsth = qq{SELECT biblionumber FROM biblioitems WHERE marcxml LIKE "%amp;amp;%"}; |
122 |
my $sth = $dbh->prepare($strsth); |
123 |
$sth->execute(); |
124 |
while (my $bib = $sth-> fetchrow_array()){ |
125 |
push @bibliosearch, $bib; |
126 |
} |
127 |
return @bibliosearch; |
128 |
} |