Lines 20-49
use Time::HiRes qw(gettimeofday);
Link Here
|
20 |
|
20 |
|
21 |
use Getopt::Long; |
21 |
use Getopt::Long; |
22 |
my ( $input_marc_file, $number) = ('', 0); |
22 |
my ( $input_marc_file, $number) = ('', 0); |
23 |
my ($version, $confirm, $test_parameter); |
23 |
my ($help, $confirm, $test_parameter); |
|
|
24 |
my ($updateUpstream, $updateDownstream, $limitedColumns); |
24 |
GetOptions( |
25 |
GetOptions( |
25 |
'c' => \$confirm, |
26 |
'c|confirm' => \$confirm, |
26 |
'h' => \$version, |
27 |
'h|help' => \$help, |
27 |
't' => \$test_parameter, |
28 |
't|test' => \$test_parameter, |
|
|
29 |
'u|upstream' => \$updateUpstream, |
30 |
'd|downstream' => \$updateDownstream, |
31 |
'columns:s' => \$limitedColumns, |
28 |
); |
32 |
); |
29 |
|
33 |
|
30 |
if ($version || (!$confirm)) { |
34 |
my $helpText = <<EOF |
31 |
print <<EOF |
35 |
This script rebuilds the non-MARC DB from the MARC values and vice versa. |
32 |
This script rebuilds the non-MARC DB from the MARC values. |
|
|
33 |
You can/must use it when you change your mapping. |
36 |
You can/must use it when you change your mapping. |
34 |
|
37 |
|
35 |
Example: you decide to map biblio.title to 200\$a (it was previously mapped to 610\$a). |
38 |
Example: you decide to map biblio.title to 200\$a (it was previously mapped to 610\$a). |
36 |
Run this script or you will have strange results in OPAC ! |
39 |
Run this script or you will have strange results in OPAC ! |
37 |
|
40 |
|
|
|
41 |
-h | --help This friendly helper! |
42 |
-u | --upstream Update MARC Records from the database columns using "Koha to MARC mappings". |
43 |
-d | --downstream Update database columns from the MARC Records using "Koha to MARC mappings". |
44 |
-c | --confirm Confirm, that you want to batch modify all of your Bibliographic records. |
45 |
It is better to double check your mappings now since this operation cannot be undone. |
46 |
This will take a long time... |
47 |
-t | --test Test only, change nothing in DB |
48 |
--columns NOT IMPLEMENTED YET! Limit the updates to this list of table |
49 |
columns, instead of updating all "Koha to MARC mappings". |
50 |
Example: --columns "biblioitems.publicationyear, biblioitems.datereceived, biblio.copyrightdate" |
51 |
Only columns for tables biblio and biblioitems are supported. |
52 |
|
38 |
Syntax: |
53 |
Syntax: |
39 |
\t./batchRebuildBiblioTables.pl -h (or without arguments => shows this screen) |
54 |
./batchRebuildBiblioTables.pl --help |
40 |
\t./batchRebuildBiblioTables.pl -c (c like confirm => rebuild non marc DB (may be long) |
55 |
./batchRebuildBiblioTables.pl --test --upstream |
41 |
\t-t => test only, change nothing in DB |
56 |
./batchRebuildBiblioTables.pl --confirm --downstream |
42 |
EOF |
57 |
EOF |
43 |
; |
58 |
; |
44 |
exit; |
59 |
|
|
|
60 |
if ($help) { |
61 |
print $helpText; |
62 |
exit(); |
63 |
} |
64 |
if (not($updateUpstream) && not($updateDownstream)) { |
65 |
print $helpText."\n\nyou must choose either --upstream or --downstream !\n"; |
66 |
exit(); |
67 |
} |
68 |
if (!$confirm) { |
69 |
print $helpText."\n\nRead the help file!\n"; |
70 |
exit(); |
71 |
} |
72 |
my @limitedColumns = split(/\s*,\s*/,$limitedColumns); |
73 |
if ($limitedColumns && scalar(@limitedColumns) == 0) { |
74 |
print $helpText."\n\nCouldn't parse --columns '$limitedColumns'!\n"; |
75 |
exit(); |
76 |
} |
77 |
elsif (scalar(@limitedColumns)) { |
78 |
@limitedColumns = undef; |
79 |
#TODO limited columns parsing. |
45 |
} |
80 |
} |
46 |
|
81 |
|
|
|
82 |
|
47 |
my $dbh = C4::Context->dbh; |
83 |
my $dbh = C4::Context->dbh; |
48 |
my $i=0; |
84 |
my $i=0; |
49 |
my $starttime = time(); |
85 |
my $starttime = time(); |
Lines 56-61
my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
Link Here
|
56 |
# $dbh->do("lock tables biblio write, biblioitems write, items write, marc_biblio write, marc_subfield_table write, marc_blob_subfield write, marc_word write, marc_subfield_structure write, stopwords write"); |
92 |
# $dbh->do("lock tables biblio write, biblioitems write, items write, marc_biblio write, marc_subfield_table write, marc_blob_subfield write, marc_word write, marc_subfield_structure write, stopwords write"); |
57 |
my $sth = $dbh->prepare("SELECT biblionumber FROM biblio"); |
93 |
my $sth = $dbh->prepare("SELECT biblionumber FROM biblio"); |
58 |
$sth->execute; |
94 |
$sth->execute; |
|
|
95 |
|
96 |
if ($updateUpstream) { |
97 |
while (my ($biblionumber) = $sth->fetchrow) { |
98 |
DB_ToRecord($biblionumber, \@limitedColumns); |
99 |
} |
100 |
exit(); |
101 |
} |
102 |
|
103 |
|
59 |
# my ($biblionumbermax) = $sth->fetchrow; |
104 |
# my ($biblionumbermax) = $sth->fetchrow; |
60 |
# warn "$biblionumbermax <<=="; |
105 |
# warn "$biblionumbermax <<=="; |
61 |
my @errors; |
106 |
my @errors; |
Lines 63-70
while (my ($biblionumber)= $sth->fetchrow) {
Link Here
|
63 |
#now, parse the record, extract the item fields, and store them in somewhere else. |
108 |
#now, parse the record, extract the item fields, and store them in somewhere else. |
64 |
my $record = GetMarcBiblio($biblionumber); |
109 |
my $record = GetMarcBiblio($biblionumber); |
65 |
if (not defined $record) { |
110 |
if (not defined $record) { |
66 |
push @errors, $biblionumber; |
111 |
push @errors, $biblionumber; |
67 |
next; |
112 |
next; |
68 |
} |
113 |
} |
69 |
my @fields = $record->field($tagfield); |
114 |
my @fields = $record->field($tagfield); |
70 |
my @items; |
115 |
my @items; |
Lines 101-103
sub localNEWmodbiblio {
Link Here
|
101 |
C4::Biblio::_koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio ); |
146 |
C4::Biblio::_koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio ); |
102 |
return 1; |
147 |
return 1; |
103 |
} |
148 |
} |
104 |
- |
149 |
|
|
|
150 |
sub DB_ToRecord { |
151 |
my ($biblionumber) = @_; |
152 |
|
153 |
my $errors = C4::Biblio::UpdateKohaToMarc($biblionumber); |
154 |
print "bn: $biblionumber, $errors\n" if $errors; |
155 |
} |