Lines 255-261
sub AddBiblioToBatch {
Link Here
|
255 |
my $z3950random = shift; |
255 |
my $z3950random = shift; |
256 |
my $update_counts = @_ ? shift : 1; |
256 |
my $update_counts = @_ ? shift : 1; |
257 |
|
257 |
|
258 |
my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'biblio', $encoding, $z3950random); |
258 |
my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'biblio', $encoding, $z3950random, C4::Context->preference('marcflavour')); |
259 |
_add_biblio_fields($import_record_id, $marc_record); |
259 |
_add_biblio_fields($import_record_id, $marc_record); |
260 |
_update_batch_record_counts($batch_id) if $update_counts; |
260 |
_update_batch_record_counts($batch_id) if $update_counts; |
261 |
return $import_record_id; |
261 |
return $import_record_id; |
Lines 270-276
sub AddBiblioToBatch {
Link Here
|
270 |
sub ModBiblioInBatch { |
270 |
sub ModBiblioInBatch { |
271 |
my ($import_record_id, $marc_record) = @_; |
271 |
my ($import_record_id, $marc_record) = @_; |
272 |
|
272 |
|
273 |
_update_import_record_marc($import_record_id, $marc_record); |
273 |
_update_import_record_marc($import_record_id, $marc_record, C4::Context->preference('marcflavour')); |
274 |
_update_biblio_fields($import_record_id, $marc_record); |
274 |
_update_biblio_fields($import_record_id, $marc_record); |
275 |
|
275 |
|
276 |
} |
276 |
} |
Lines 278-284
sub ModBiblioInBatch {
Link Here
|
278 |
=head2 AddAuthToBatch |
278 |
=head2 AddAuthToBatch |
279 |
|
279 |
|
280 |
my $import_record_id = AddAuthToBatch($batch_id, $record_sequence, |
280 |
my $import_record_id = AddAuthToBatch($batch_id, $record_sequence, |
281 |
$marc_record, $encoding, $z3950random, $update_counts); |
281 |
$marc_record, $encoding, $z3950random, $update_counts, [$marc_type]); |
282 |
|
282 |
|
283 |
=cut |
283 |
=cut |
284 |
|
284 |
|
Lines 289-296
sub AddAuthToBatch {
Link Here
|
289 |
my $encoding = shift; |
289 |
my $encoding = shift; |
290 |
my $z3950random = shift; |
290 |
my $z3950random = shift; |
291 |
my $update_counts = @_ ? shift : 1; |
291 |
my $update_counts = @_ ? shift : 1; |
|
|
292 |
my $marc_type = shift || C4::Context->preference('marcflavour'); |
293 |
|
294 |
$marc_type = 'UNIMARCAUTH' if $marc_type eq 'UNIMARC'; |
292 |
|
295 |
|
293 |
my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'auth', $encoding, $z3950random); |
296 |
my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'auth', $encoding, $z3950random, $marc_type); |
294 |
_add_auth_fields($import_record_id, $marc_record); |
297 |
_add_auth_fields($import_record_id, $marc_record); |
295 |
_update_batch_record_counts($batch_id) if $update_counts; |
298 |
_update_batch_record_counts($batch_id) if $update_counts; |
296 |
return $import_record_id; |
299 |
return $import_record_id; |
Lines 305-311
sub AddAuthToBatch {
Link Here
|
305 |
sub ModAuthInBatch { |
308 |
sub ModAuthInBatch { |
306 |
my ($import_record_id, $marc_record) = @_; |
309 |
my ($import_record_id, $marc_record) = @_; |
307 |
|
310 |
|
308 |
_update_import_record_marc($import_record_id, $marc_record); |
311 |
my $marcflavour = C4::Context->preference('marcflavour'); |
|
|
312 |
_update_import_record_marc($import_record_id, $marc_record, $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : 'USMARC'); |
309 |
|
313 |
|
310 |
} |
314 |
} |
311 |
|
315 |
|
Lines 354-359
sub BatchStageMarcRecords {
Link Here
|
354 |
SetImportBatchItemAction($batch_id, 'ignore'); |
358 |
SetImportBatchItemAction($batch_id, 'ignore'); |
355 |
} |
359 |
} |
356 |
|
360 |
|
|
|
361 |
my $marc_type = C4::Context->preference('marcflavour'); |
362 |
$marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth'); |
357 |
my @invalid_records = (); |
363 |
my @invalid_records = (); |
358 |
my $num_valid = 0; |
364 |
my $num_valid = 0; |
359 |
my $num_items = 0; |
365 |
my $num_items = 0; |
Lines 368-374
sub BatchStageMarcRecords {
Link Here
|
368 |
&$progress_callback($rec_num); |
374 |
&$progress_callback($rec_num); |
369 |
} |
375 |
} |
370 |
my ($marc_record, $charset_guessed, $char_errors) = |
376 |
my ($marc_record, $charset_guessed, $char_errors) = |
371 |
MarcToUTF8Record($marc_blob, C4::Context->preference("marcflavour"), $encoding); |
377 |
MarcToUTF8Record($marc_blob, $marc_type, $encoding); |
372 |
|
378 |
|
373 |
$encoding = $charset_guessed unless $encoding; |
379 |
$encoding = $charset_guessed unless $encoding; |
374 |
|
380 |
|
Lines 384-390
sub BatchStageMarcRecords {
Link Here
|
384 |
$num_items += scalar(@import_items_ids); |
390 |
$num_items += scalar(@import_items_ids); |
385 |
} |
391 |
} |
386 |
} elsif ($record_type eq 'auth') { |
392 |
} elsif ($record_type eq 'auth') { |
387 |
$import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0); |
393 |
$import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0, $marc_type); |
388 |
} |
394 |
} |
389 |
} |
395 |
} |
390 |
} |
396 |
} |
Lines 430-436
sub AddItemsToImportBiblio {
Link Here
|
430 |
|
436 |
|
431 |
if ($#import_items_ids > -1) { |
437 |
if ($#import_items_ids > -1) { |
432 |
_update_batch_record_counts($batch_id) if $update_counts; |
438 |
_update_batch_record_counts($batch_id) if $update_counts; |
433 |
_update_import_record_marc($import_record_id, $marc_record); |
439 |
_update_import_record_marc($import_record_id, $marc_record, C4::Context->preference('marcflavour')); |
434 |
} |
440 |
} |
435 |
return @import_items_ids; |
441 |
return @import_items_ids; |
436 |
} |
442 |
} |
Lines 545-550
sub BatchCommitRecords {
Link Here
|
545 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
551 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
546 |
WHERE import_batch_id = ?"); |
552 |
WHERE import_batch_id = ?"); |
547 |
$sth->execute($batch_id); |
553 |
$sth->execute($batch_id); |
|
|
554 |
my $marcflavour = C4::Context->preference('marcflavour'); |
548 |
my $rec_num = 0; |
555 |
my $rec_num = 0; |
549 |
while (my $rowref = $sth->fetchrow_hashref) { |
556 |
while (my $rowref = $sth->fetchrow_hashref) { |
550 |
$record_type = $rowref->{'record_type'}; |
557 |
$record_type = $rowref->{'record_type'}; |
Lines 557-562
sub BatchCommitRecords {
Link Here
|
557 |
next; |
564 |
next; |
558 |
} |
565 |
} |
559 |
|
566 |
|
|
|
567 |
my $marc_type; |
568 |
if ($marcflavour eq 'UNIMARC' && $record_type eq 'auth') { |
569 |
$marc_type = 'UNIMARCAUTH'; |
570 |
} elsif ($marcflavour eq 'UNIMARC') { |
571 |
$marc_type = 'UNIMARC'; |
572 |
} else { |
573 |
$marc_type = 'USMARC'; |
574 |
} |
560 |
my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'}); |
575 |
my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'}); |
561 |
|
576 |
|
562 |
if ($record_type eq 'biblio') { |
577 |
if ($record_type eq 'biblio') { |
Lines 602-612
sub BatchCommitRecords {
Link Here
|
602 |
|
617 |
|
603 |
# remove item fields so that they don't get |
618 |
# remove item fields so that they don't get |
604 |
# added again if record is reverted |
619 |
# added again if record is reverted |
605 |
my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}); |
620 |
my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}, $marc_type); |
606 |
foreach my $item_field ($old_marc->field($item_tag)) { |
621 |
foreach my $item_field ($old_marc->field($item_tag)) { |
607 |
$old_marc->delete_field($item_field); |
622 |
$old_marc->delete_field($item_field); |
608 |
} |
623 |
} |
609 |
$oldxml = $old_marc->as_xml(); |
624 |
$oldxml = $old_marc->as_xml($marc_type); |
610 |
|
625 |
|
611 |
ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); |
626 |
ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); |
612 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
627 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
Lines 725-736
sub BatchRevertRecords {
Link Here
|
725 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
740 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
726 |
WHERE import_batch_id = ?"); |
741 |
WHERE import_batch_id = ?"); |
727 |
$sth->execute($batch_id); |
742 |
$sth->execute($batch_id); |
|
|
743 |
my $marc_type; |
744 |
my $marcflavour = C4::Context->preference('marcflavour'); |
728 |
while (my $rowref = $sth->fetchrow_hashref) { |
745 |
while (my $rowref = $sth->fetchrow_hashref) { |
729 |
$record_type = $rowref->{'record_type'}; |
746 |
$record_type = $rowref->{'record_type'}; |
730 |
if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') { |
747 |
if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') { |
731 |
$num_ignored++; |
748 |
$num_ignored++; |
732 |
next; |
749 |
next; |
733 |
} |
750 |
} |
|
|
751 |
if ($marcflavour eq 'UNIMARC' && $record_type eq 'auth') { |
752 |
$marc_type = 'UNIMARCAUTH'; |
753 |
} elsif ($marcflavour eq 'UNIMARC') { |
754 |
$marc_type = 'UNIMARC'; |
755 |
} else { |
756 |
$marc_type = 'USMARC'; |
757 |
} |
734 |
|
758 |
|
735 |
my $record_result = _get_revert_action($overlay_action, $rowref->{'overlay_status'}, $rowref->{'status'}); |
759 |
my $record_result = _get_revert_action($overlay_action, $rowref->{'overlay_status'}, $rowref->{'status'}); |
736 |
|
760 |
|
Lines 750-756
sub BatchRevertRecords {
Link Here
|
750 |
} |
774 |
} |
751 |
} elsif ($record_result eq 'restore') { |
775 |
} elsif ($record_result eq 'restore') { |
752 |
$num_reverted++; |
776 |
$num_reverted++; |
753 |
my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'}); |
777 |
my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'}, $marc_type); |
754 |
if ($record_type eq 'biblio') { |
778 |
if ($record_type eq 'biblio') { |
755 |
my $biblionumber = $rowref->{'matched_biblionumber'}; |
779 |
my $biblionumber = $rowref->{'matched_biblionumber'}; |
756 |
my ($count, $oldbiblio) = GetBiblio($biblionumber); |
780 |
my ($count, $oldbiblio) = GetBiblio($biblionumber); |
Lines 1321-1333
sub SetImportRecordMatches {
Link Here
|
1321 |
# internal functions |
1345 |
# internal functions |
1322 |
|
1346 |
|
1323 |
sub _create_import_record { |
1347 |
sub _create_import_record { |
1324 |
my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random) = @_; |
1348 |
my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random, $marc_type) = @_; |
1325 |
|
1349 |
|
1326 |
my $dbh = C4::Context->dbh; |
1350 |
my $dbh = C4::Context->dbh; |
1327 |
my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, |
1351 |
my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, |
1328 |
record_type, encoding, z3950random) |
1352 |
record_type, encoding, z3950random) |
1329 |
VALUES (?, ?, ?, ?, ?, ?, ?)"); |
1353 |
VALUES (?, ?, ?, ?, ?, ?, ?)"); |
1330 |
$sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml(), |
1354 |
$sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type), |
1331 |
$record_type, $encoding, $z3950random); |
1355 |
$record_type, $encoding, $z3950random); |
1332 |
my $import_record_id = $dbh->{'mysql_insertid'}; |
1356 |
my $import_record_id = $dbh->{'mysql_insertid'}; |
1333 |
$sth->finish(); |
1357 |
$sth->finish(); |
Lines 1335-1346
sub _create_import_record {
Link Here
|
1335 |
} |
1359 |
} |
1336 |
|
1360 |
|
1337 |
sub _update_import_record_marc { |
1361 |
sub _update_import_record_marc { |
1338 |
my ($import_record_id, $marc_record) = @_; |
1362 |
my ($import_record_id, $marc_record, $marc_type) = @_; |
1339 |
|
1363 |
|
1340 |
my $dbh = C4::Context->dbh; |
1364 |
my $dbh = C4::Context->dbh; |
1341 |
my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ? |
1365 |
my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ? |
1342 |
WHERE import_record_id = ?"); |
1366 |
WHERE import_record_id = ?"); |
1343 |
$sth->execute($marc_record->as_usmarc(), $marc_record->as_xml(C4::Context->preference('marcflavour')), $import_record_id); |
1367 |
$sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $import_record_id); |
1344 |
$sth->finish(); |
1368 |
$sth->finish(); |
1345 |
} |
1369 |
} |
1346 |
|
1370 |
|