Lines 1-66
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
# Copyright 2011 Stefano Bargioni, Pontificia Università della Santa Croce - Rome |
|
|
4 |
# |
5 |
# This file is part of Koha. |
3 |
# This file is part of Koha. |
6 |
# |
4 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
5 |
# Copyright 2011 Stefano Bargioni, Pontificia Università della Santa Croce - Rome |
8 |
# terms of the GNU General Public License as published by the Free Software |
6 |
# Copyright 2015 Mark Tompsett |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
7 |
# |
10 |
# version. |
8 |
# Koha is free software; you can redistribute it and/or modify it |
|
|
9 |
# under the terms of the GNU General Public License as published by |
10 |
# the Free Software Foundation; either version 3 of the License, or |
11 |
# (at your option) any later version. |
11 |
# |
12 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 |
# GNU General Public License for more details. |
15 |
# |
17 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
18 |
# You should have received a copy of the GNU General Public License |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
|
19 |
|
20 |
|
20 |
# Written by Stefano Bargioni Pontificia Università della Santa Croce - Rome |
21 |
# Written by Stefano Bargioni Pontificia Università della Santa Croce - Rome |
21 |
# bargioni@pusc.it 2011-11-07 |
22 |
# bargioni@pusc.it 2011-11-07 |
22 |
|
23 |
|
23 |
use strict; |
24 |
# Made perlcritic nicer by Mark Tompsett 2015-10-19 |
24 |
use warnings; |
25 |
|
25 |
use MARC::Record; |
|
|
26 |
use MARC::File::XML; |
27 |
use MARC::Field; |
28 |
use C4::Biblio; |
26 |
use C4::Biblio; |
29 |
use C4::Context; |
27 |
use C4::Context; |
|
|
28 |
|
29 |
use Carp; |
30 |
use English qw( -no_match_vars ); |
30 |
use Getopt::Long; |
31 |
use Getopt::Long; |
31 |
use IO::File; |
32 |
use IO::File; |
|
|
33 |
use MARC::Field; |
34 |
use MARC::File::XML; |
35 |
use MARC::Record; |
36 |
use Modern::Perl; |
32 |
use Pod::Usage; |
37 |
use Pod::Usage; |
33 |
|
38 |
|
34 |
binmode(STDOUT, ":utf8"); |
39 |
use constant DEFAULT_RECORDS_BEFORE_FLUSH => 50; |
|
|
40 |
use constant DEFAULT_TAG_LENGTH => 3; |
41 |
use constant DEFAULT_TAG => '001'; |
42 |
use constant DEFAULT_SUBTAG => q{@}; |
43 |
use constant SINGLE_QUOTE => q{'}; |
44 |
use constant PERIOD => q{.}; |
45 |
|
46 |
binmode STDOUT, ':encoding(UTF-8)'; |
35 |
|
47 |
|
36 |
my $help = 0; |
48 |
my $help = 0; |
37 |
my $commit = 50; |
49 |
my $commit = DEFAULT_RECORDS_BEFORE_FLUSH; |
38 |
my $biblio = 0; |
50 |
my $biblio = 0; |
39 |
my $auth = 0; |
51 |
my $auth = 0; |
40 |
my $tag = '001'; |
52 |
my $tag = DEFAULT_TAG; |
41 |
my $subfield = '@'; |
53 |
my $subfield = DEFAULT_SUBTAG; |
42 |
my $verbose = 0; |
54 |
my $verbose = 0; |
43 |
|
55 |
|
44 |
GetOptions( |
56 |
GetOptions( |
45 |
'help|?|h' => \$help, |
57 |
'help|?|h' => \$help, |
46 |
'a|authorities:s' => \$auth, |
58 |
'a|authorities' => \$auth, |
47 |
'b|biblios:s' => \$biblio, |
59 |
'b|biblios' => \$biblio, |
48 |
'c|commit:n' => \$commit, |
60 |
'c|commit:n' => \$commit, |
49 |
't|tag:s' => \$tag, |
61 |
't|tag:s' => \$tag, |
50 |
's|subfield:s' => \$subfield, |
62 |
's|subfield:s' => \$subfield, |
51 |
'v|verbose' => \$verbose, |
63 |
'v|verbose' => \$verbose, |
52 |
) or pod2usage(2); |
64 |
) or pod2usage(2); |
53 |
pod2usage( -exitstatus => 0, -verbose => 2 ) if $help; |
|
|
54 |
|
65 |
|
55 |
die('No record type specified') if ( !$biblio && !$auth ); |
66 |
if ($help) { pod2usage( -exitstatus => 0, -verbose => 2 ); } |
56 |
die('You cannot specify both record types') if ( $biblio && $auth ); |
67 |
|
57 |
die("Invalid MARC tag $tag") if ( length($tag) != 3 ); |
68 |
if ( !$biblio && !$auth ) { croak ('No record type specified'); } |
58 |
die("Invalid subfield $subfield") if ( length($subfield) != 1 ); |
69 |
if ( $biblio && $auth ) { croak ('You cannot specify both record types'); } |
59 |
die('Invalid commit value') if ( $commit < 1 ); |
70 |
if ( length($tag) != DEFAULT_TAG_LENGTH ) { croak ("Invalid MARC tag $tag"); } |
|
|
71 |
if ( length($subfield) != 1 ) { croak ("Invalid subfield $subfield"); } |
72 |
if ( $commit < 1 ) { croak ('Invalid commit value'); } |
60 |
|
73 |
|
61 |
my $dbh = C4::Context->dbh; |
74 |
my $dbh = C4::Context->dbh; |
62 |
my $rows; |
75 |
my $rows; |
63 |
$|=1; # autoflush |
76 |
$OUTPUT_AUTOFLUSH = 1; # autoflush |
64 |
|
77 |
|
65 |
# check MySQL version >= 5.1. Otherwise MySQL lacks the ExtractValue XML function |
78 |
# check MySQL version >= 5.1. Otherwise MySQL lacks the ExtractValue XML function |
66 |
my $sqlv = 'select version()'; |
79 |
my $sqlv = 'select version()'; |
Lines 68-203
my $sthv = $dbh->prepare($sqlv);
Link Here
|
68 |
$sthv->execute; |
81 |
$sthv->execute; |
69 |
my ($mysql_version) = $sthv->fetchrow_array(); |
82 |
my ($mysql_version) = $sthv->fetchrow_array(); |
70 |
$sthv->finish; |
83 |
$sthv->finish; |
71 |
die('Your MySQL version $mysql_version is less than 5.1') if ($mysql_version lt '5.1'); |
84 |
if ($mysql_version lt '5.1') { croak "Your MySQL version $mysql_version is less than 5.1"; } |
72 |
|
85 |
|
73 |
# An example of $xpath: '//datafield[@tag="999"]/subfield[@code="c"]'; |
86 |
# An example of $xpath: '//datafield[@tag="999"]/subfield[@code="c"]'; |
74 |
my $xpath = "'//"; |
87 |
my $xpath = q{'//}; |
75 |
if ($tag gt '009') {$xpath .= 'datafield'} else {$xpath .= 'controlfield'}; |
88 |
if ($tag gt '009') {$xpath .= 'datafield'} else {$xpath .= 'controlfield'}; |
76 |
$xpath .= '[@tag="'.$tag.'"]'; |
89 |
$xpath .= "[\@tag=\"$tag\"]"; |
77 |
$xpath .= "/subfield[\@code=\"$subfield\"]" if ($subfield ne '@'); |
90 |
if ($subfield ne DEFAULT_SUBTAG) { |
78 |
$xpath .= "'"; |
91 |
$xpath .= "/subfield[\@code=\"$subfield\"]"; |
79 |
print 'using xpath '.$xpath."\n" if ($verbose); |
92 |
} |
|
|
93 |
$xpath .= SINGLE_QUOTE; |
94 |
if ($verbose) { print "using xpath $xpath\n"; } |
80 |
|
95 |
|
81 |
# exit; # test |
96 |
# exit; # test |
82 |
|
97 |
|
83 |
print `date` if ($verbose); |
98 |
if ($verbose) { system 'date'; } |
84 |
|
99 |
|
85 |
if ($auth) { |
100 |
if ($auth) { |
86 |
print "Keeping system numbers of authority records\n" if ($verbose); |
101 |
if ($verbose) { print "Keeping system numbers of authority records\n"; } |
87 |
# check existence of tag/subfield |
102 |
# check existence of tag/subfield |
88 |
$sqlv = "select count(*) from auth_header union select count(*) from auth_header where ExtractValue(marcxml,$xpath) != ''"; |
103 |
$sqlv = "select count(*) from auth_header union select count(*) from auth_header where ExtractValue(marcxml,$xpath) != ''"; |
89 |
$sthv = $dbh->prepare($sqlv); |
104 |
$sthv = $dbh->prepare($sqlv); |
90 |
$sthv->execute; |
105 |
$sthv->execute; |
91 |
($rows) = $sthv->fetchrow_array(); |
106 |
($rows) = $sthv->fetchrow_array(); |
92 |
my ($ctsxml) = $sthv->fetchrow_array(); # a second line can be absent |
107 |
my ($ctsxml) = $sthv->fetchrow_array(); # a second line can be absent |
93 |
if (!defined $ctsxml) {$ctsxml=$rows} |
108 |
if (!defined $ctsxml) {$ctsxml=$rows} |
94 |
print "$ctsxml of $rows records containing $tag\$$subfield\n" if ($verbose); |
109 |
if ($verbose) { print "$ctsxml of $rows records containing $tag\$$subfield\n"; } |
95 |
$sthv->finish; |
110 |
$sthv->finish; |
96 |
die("Tag and/or subfield $tag\$$subfield specified are not present in each record") if($rows-$ctsxml !=0 || $rows+$ctsxml==0); |
111 |
if($rows-$ctsxml !=0 || $rows+$ctsxml==0) { croak ("Tag and/or subfield $tag\$$subfield specified are not present in each record"); } |
97 |
|
112 |
|
98 |
print "1. dropping primary key for auth_header.authid\n" if ($verbose); |
113 |
if ($verbose) { print "1. dropping primary key for auth_header.authid\n"; } |
99 |
$dbh->do('ALTER TABLE auth_header CHANGE authid authid BIGINT(20) UNSIGNED NOT NULL'); |
114 |
else { print PERIOD; } |
100 |
$dbh->do('ALTER TABLE auth_header DROP PRIMARY KEY'); |
115 |
$dbh->do('ALTER TABLE auth_header CHANGE authid authid BIGINT(20) UNSIGNED NOT NULL'); |
101 |
print "2. filling in auth_header.authid... " if ($verbose); |
116 |
$dbh->do('ALTER TABLE auth_header DROP PRIMARY KEY'); |
102 |
$rows = $dbh->do("UPDATE auth_header SET authid=ExtractValue(marcxml,$xpath)"); |
117 |
|
103 |
print "3. rebuilding primary key for auth_header.authid\n"; |
118 |
if ($verbose) { print "2. filling in auth_header.authid...\n"; } |
104 |
$dbh->do('ALTER TABLE auth_header CHANGE authid authid BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'); |
119 |
else { print PERIOD; } |
105 |
print `date` if ($verbose); |
120 |
$rows = $dbh->do("UPDATE auth_header SET authid=ExtractValue(marcxml,$xpath)"); |
|
|
121 |
|
122 |
if ($verbose) { print "3. rebuilding primary key for auth_header.authid\n"; } |
123 |
else { print PERIOD . "\n"; } |
124 |
$dbh->do('ALTER TABLE auth_header CHANGE authid authid BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'); |
125 |
|
126 |
if ($verbose) { system 'date'; } |
106 |
} |
127 |
} |
107 |
|
128 |
|
108 |
if ($biblio) { |
129 |
if ($biblio) { |
109 |
print "Keeping system numbers of bibliographic records\n" if ($verbose); |
130 |
if ($verbose) { print "Keeping system numbers of bibliographic records\n"; } |
110 |
# check existence of tag/subfield |
131 |
# check existence of tag/subfield |
111 |
$sqlv = "select count(*) from biblioitems union select count(*) from biblioitems where ExtractValue(marcxml,$xpath) != ''"; |
132 |
$sqlv = "select count(*) from biblioitems union select count(*) from biblioitems where ExtractValue(marcxml,$xpath) != ''"; |
112 |
$sthv = $dbh->prepare($sqlv); |
133 |
$sthv = $dbh->prepare($sqlv); |
113 |
$sthv->execute; |
134 |
$sthv->execute; |
114 |
($rows) = $sthv->fetchrow_array(); |
135 |
($rows) = $sthv->fetchrow_array(); |
115 |
my ($ctsxml) = $sthv->fetchrow_array(); # a second line can be absent |
136 |
my ($ctsxml) = $sthv->fetchrow_array(); # a second line can be absent |
116 |
if (!defined $ctsxml) {$ctsxml=$rows} |
137 |
if (!defined $ctsxml) {$ctsxml=$rows} |
117 |
print "$ctsxml of $rows records containing $tag\$$subfield\n" if ($verbose); |
138 |
if ($verbose) { print "$ctsxml of $rows records containing $tag\$$subfield\n"; } |
118 |
$sthv->finish; |
139 |
$sthv->finish; |
119 |
die("Tag and/or subfield $tag\$$subfield specified are not present in each record") if($rows-$ctsxml !=0 || $rows+$ctsxml==0); |
140 |
if($rows-$ctsxml !=0 || $rows+$ctsxml==0) { croak ("Tag and/or subfield $tag\$$subfield specified are not present in each record"); } |
120 |
|
141 |
|
121 |
print "adding new columns temp_id to tables biblio, biblioitems, items\n" if ($verbose); |
142 |
if ($verbose) { print "adding new columns temp_id to tables biblio, biblioitems, items\n"; } |
122 |
$dbh->do('ALTER TABLE biblio add COLUMN temp_id int'); |
143 |
$dbh->do('ALTER TABLE biblio add COLUMN temp_id int'); |
123 |
$dbh->do('ALTER TABLE biblioitems ADD COLUMN temp_id int'); |
144 |
$dbh->do('ALTER TABLE biblioitems ADD COLUMN temp_id int'); |
124 |
$dbh->do('ALTER TABLE items ADD COLUMN temp_id int'); |
145 |
$dbh->do('ALTER TABLE items ADD COLUMN temp_id int'); |
125 |
|
146 |
|
126 |
print "filling in biblioitems.temp_id... " if ($verbose); |
147 |
if ($verbose) { print 'filling in biblioitems.temp_id... '; } |
127 |
$rows = $dbh->do("UPDATE biblioitems SET temp_id=ExtractValue(marcxml,$xpath)"); |
148 |
$rows = $dbh->do("UPDATE biblioitems SET temp_id=ExtractValue(marcxml,$xpath)"); |
128 |
print "effettuato su $rows records\n"; |
149 |
print "affected $rows records\n"; |
129 |
print "indicizzazione di biblioitems.temp_id\n"; |
150 |
print "indexing on biblioitems.temp_id\n"; |
130 |
$dbh->do('ALTER TABLE biblioitems ADD INDEX (temp_id)'); |
151 |
$dbh->do('ALTER TABLE biblioitems ADD INDEX (temp_id)'); |
131 |
|
152 |
|
132 |
print "changing biblio.biblionumber:\n" if ($verbose); |
153 |
if ($verbose) { print "changing biblio.biblionumber:\n"; } |
133 |
print "1. filling in biblio.temp_id\n"; # update with join |
154 |
print "1. filling in biblio.temp_id\n"; # update with join |
134 |
$dbh->do('UPDATE biblio, biblioitems SET biblio.temp_id = biblioitems.temp_id WHERE biblio.biblionumber = biblioitems.biblionumber'); |
155 |
$dbh->do('UPDATE biblio, biblioitems SET biblio.temp_id = biblioitems.temp_id WHERE biblio.biblionumber = biblioitems.biblionumber'); |
135 |
print "2. dropping primary key for biblio.biblionumber\n"; |
156 |
print "2. dropping primary key for biblio.biblionumber\n"; |
136 |
$dbh->do('ALTER TABLE biblio CHANGE biblionumber biblionumber INT(11) NOT NULL'); |
157 |
$dbh->do('ALTER TABLE biblio CHANGE biblionumber biblionumber INT(11) NOT NULL'); |
137 |
$dbh->do('ALTER TABLE biblio DROP PRIMARY KEY'); |
158 |
$dbh->do('ALTER TABLE biblio DROP PRIMARY KEY'); |
138 |
print "3. copying temp_id in biblio.biblionumber\n"; |
159 |
print "3. copying temp_id in biblio.biblionumber\n"; |
139 |
$dbh->do('UPDATE biblio SET biblionumber=temp_id'); |
160 |
$dbh->do('UPDATE biblio SET biblionumber=temp_id'); |
140 |
print "4. dropping column biblio.temp_id\n"; |
161 |
print "4. dropping column biblio.temp_id\n"; |
141 |
$dbh->do('ALTER TABLE biblio DROP temp_id'); |
162 |
$dbh->do('ALTER TABLE biblio DROP temp_id'); |
142 |
print "5. rebuilding primary key for biblio.biblionumber\n"; |
163 |
print "5. rebuilding primary key for biblio.biblionumber\n"; |
143 |
$dbh->do('ALTER TABLE biblio CHANGE biblionumber biblionumber INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'); |
164 |
$dbh->do('ALTER TABLE biblio CHANGE biblionumber biblionumber INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'); |
144 |
|
165 |
|
145 |
print "changing items.biblionumber and items.biblioitemnumber\n" if ($verbose); |
166 |
if ($verbose) { print "changing items.biblionumber and items.biblioitemnumber\n"; } |
146 |
print "1. filling in items.temp_id\n"; # update with join |
167 |
print "1. filling in items.temp_id\n"; # update with join |
147 |
$dbh->do('UPDATE items, biblioitems SET items.temp_id = biblioitems.temp_id WHERE items.biblionumber = biblioitems.biblioitemnumber'); |
168 |
$dbh->do('UPDATE items, biblioitems SET items.temp_id = biblioitems.temp_id WHERE items.biblionumber = biblioitems.biblioitemnumber'); |
148 |
print "2. dropping foreign key that links biblioitems to items\n" if ($verbose); |
169 |
if ($verbose) { print "2. dropping foreign key that links biblioitems to items\n"; } |
149 |
$dbh->do('ALTER TABLE items DROP FOREIGN KEY items_ibfk_1'); |
170 |
$dbh->do('ALTER TABLE items DROP FOREIGN KEY items_ibfk_1'); |
150 |
print "3. copying items.temp_id to items.biblionumber and items.biblioitemnumber\n" if ($verbose); # drop and rebuild itembibnoidx and itembinoidx indices? |
171 |
if ($verbose) { print "3. copying items.temp_id to items.biblionumber and items.biblioitemnumber\n"; } |
151 |
$dbh->do('UPDATE items SET biblionumber=temp_id, biblioitemnumber=temp_id'); |
172 |
$dbh->do('UPDATE items SET biblionumber=temp_id, biblioitemnumber=temp_id'); |
152 |
print "4. dropping column items.temp_id\n" if ($verbose); |
173 |
if ($verbose) { print "4. dropping column items.temp_id\n"; } |
153 |
$dbh->do('ALTER TABLE items DROP temp_id'); |
174 |
$dbh->do('ALTER TABLE items DROP temp_id'); |
154 |
|
175 |
|
155 |
print "modifying table biblioitems:\n" if ($verbose); |
176 |
if ($verbose) { print "modifying table biblioitems:\n"; } |
156 |
print "1. dropping foreign key and primary key in biblioitems.biblioitemnumber\n"; |
177 |
print "1. dropping foreign key and primary key in biblioitems.biblioitemnumber\n"; |
157 |
$dbh->do('ALTER TABLE biblioitems DROP FOREIGN KEY biblioitems_ibfk_1'); |
178 |
$dbh->do('ALTER TABLE biblioitems DROP FOREIGN KEY biblioitems_ibfk_1'); |
158 |
$dbh->do('ALTER TABLE biblioitems CHANGE biblioitemnumber biblioitemnumber INT(11) NOT NULL'); |
179 |
$dbh->do('ALTER TABLE biblioitems CHANGE biblioitemnumber biblioitemnumber INT(11) NOT NULL'); |
159 |
$dbh->do('ALTER TABLE biblioitems DROP PRIMARY KEY'); |
180 |
$dbh->do('ALTER TABLE biblioitems DROP PRIMARY KEY'); |
160 |
print "2. copying biblioitems.temp_id to biblioitems.biblionumber e biblioitems.biblioitemnumber\n" if ($verbose); |
181 |
if ($verbose) { print "2. copying biblioitems.temp_id to biblioitems.biblionumber e biblioitems.biblioitemnumber\n"; } |
161 |
$dbh->do('UPDATE biblioitems SET biblionumber = temp_id, biblioitemnumber = temp_id'); # drop and rebuild bibinoidx index? |
182 |
$dbh->do('UPDATE biblioitems SET biblionumber = temp_id, biblioitemnumber = temp_id'); # drop and rebuild bibinoidx index? |
162 |
print "3. rebuilding primary key and foreign key in biblioitems.biblioitemnumber\n"; |
183 |
print "3. rebuilding primary key and foreign key in biblioitems.biblioitemnumber\n"; |
163 |
$dbh->do('ALTER TABLE biblioitems CHANGE biblioitemnumber biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'); |
184 |
$dbh->do('ALTER TABLE biblioitems CHANGE biblioitemnumber biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'); |
164 |
$dbh->do('ALTER TABLE biblioitems ADD CONSTRAINT biblioitems_ibfk_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE'); |
185 |
$dbh->do('ALTER TABLE biblioitems ADD CONSTRAINT biblioitems_ibfk_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE'); |
165 |
print "4. dropping column biblioitems.temp_id and its index\n" if ($verbose); |
186 |
if ($verbose) { print "4. dropping column biblioitems.temp_id and its index\n"; } |
166 |
$dbh->do('ALTER TABLE biblioitems DROP INDEX temp_id'); |
187 |
$dbh->do('ALTER TABLE biblioitems DROP INDEX temp_id'); |
167 |
$dbh->do('ALTER TABLE biblioitems DROP temp_id'); |
188 |
$dbh->do('ALTER TABLE biblioitems DROP temp_id'); |
168 |
|
189 |
|
169 |
print `date`." changing 999c and 999d in biblioitems.marc and biblioitems.marcxml\n" if ($verbose); |
190 |
if ($verbose) { system 'echo `date` changing 999c and 999d in biblioitems.marc and biblioitems.marcxml'; } |
170 |
my $i=0; # record counter |
191 |
my $i=0; # record counter |
171 |
my $sqlu = 'UPDATE biblioitems SET marc=?, marcxml=? WHERE biblionumber=?'; |
192 |
my $sqlu = 'UPDATE biblioitems SET marc=?, marcxml=? WHERE biblionumber=?'; |
172 |
my $sthu = $dbh->prepare($sqlu); |
193 |
my $sthu = $dbh->prepare($sqlu); |
173 |
my $sql = "SELECT biblionumber FROM biblioitems ORDER BY biblionumber"; |
194 |
my $sql = 'SELECT biblionumber FROM biblioitems ORDER BY biblionumber'; |
174 |
my $sth = $dbh->prepare($sql); |
195 |
my $sth = $dbh->prepare($sql); |
175 |
$sth->execute; |
196 |
$sth->execute; |
176 |
$dbh->{AutoCommit}=0; |
197 |
$dbh->{AutoCommit}=0; |
177 |
while (my ($biblionumber) = $sth->fetchrow_array) { |
198 |
while (my ($biblionumber) = $sth->fetchrow_array) { |
178 |
my $record = GetMarcBiblio($biblionumber); |
199 |
my $biblio_record = GetMarcBiblio($biblionumber); |
179 |
my $f999 = $record->field('999'); |
200 |
my $f999 = $biblio_record->field('999'); |
180 |
$f999->update(c => $biblionumber, d => $biblionumber); |
201 |
$f999->update(c => $biblionumber, d => $biblionumber); |
181 |
my $marc = $record->as_usmarc(); |
202 |
my $marc = $biblio_record->as_usmarc(); |
182 |
my $marcxml = $record->as_xml_record(); |
203 |
my $marcxml = $biblio_record->as_xml_record(); |
183 |
$sthu->execute($marc,$marcxml,$biblionumber); |
204 |
$sthu->execute($marc,$marcxml,$biblionumber); |
184 |
$i++; |
205 |
$i++; |
185 |
if ($i%50 == 0) { |
206 |
if ( $i % $commit == 0) { |
186 |
print "\r$i"; |
207 |
print "\r$i"; |
187 |
$dbh->commit(); |
208 |
$dbh->commit(); |
188 |
} |
209 |
} |
189 |
} |
210 |
} |
190 |
print "\r$i\n"; |
211 |
print "\r$i\n"; |
191 |
$dbh->commit(); |
212 |
$dbh->commit(); |
192 |
$sthu->finish; |
213 |
$sthu->finish; |
193 |
$sth->finish; |
214 |
$sth->finish; |
194 |
print `date`."changed 999c an 999d for $i records\n" if ($verbose); |
215 |
if ($verbose) { system 'echo `date` changed 999c an 999d for ' . $i . ' records'; } |
195 |
|
216 |
|
196 |
print "rebuilding foreign key that links biblioitems to items\n" if ($verbose); |
217 |
if ($verbose) { print "rebuilding foreign key that links biblioitems to items\n"; } |
197 |
$dbh->do('ALTER TABLE items ADD CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblioitemnumber`) REFERENCES `biblioitems` (`biblioitemnumber`) ON DELETE CASCADE ON UPDATE CASCADE'); |
218 |
$dbh->do('ALTER TABLE items ADD CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblioitemnumber`) REFERENCES `biblioitems` (`biblioitemnumber`) ON DELETE CASCADE ON UPDATE CASCADE'); |
198 |
print `date` if ($verbose); |
219 |
if ($verbose) { system 'date'; } |
199 |
} |
220 |
} |
200 |
|
221 |
|
|
|
222 |
__END__ |
223 |
|
201 |
=head1 sysno_keeper.pl |
224 |
=head1 sysno_keeper.pl |
202 |
|
225 |
|
203 |
Preserve system numbers when importing MARC records into Koha. |
226 |
Preserve system numbers when importing MARC records into Koha. |
204 |
- |
|
|