|
Lines 76-81
BEGIN {
Link Here
|
| 76 |
SetImportRecordStatus |
76 |
SetImportRecordStatus |
| 77 |
GetImportRecordMatches |
77 |
GetImportRecordMatches |
| 78 |
SetImportRecordMatches |
78 |
SetImportRecordMatches |
|
|
79 |
GetImportMarcAction |
| 80 |
SetImportMarcAction |
| 79 |
); |
81 |
); |
| 80 |
} |
82 |
} |
| 81 |
|
83 |
|
|
Lines 205-211
sub AddImportBatch {
Link Here
|
| 205 |
my (@fields, @vals); |
207 |
my (@fields, @vals); |
| 206 |
foreach (qw( matcher_id template_id branchcode |
208 |
foreach (qw( matcher_id template_id branchcode |
| 207 |
overlay_action nomatch_action item_action |
209 |
overlay_action nomatch_action item_action |
| 208 |
import_status batch_type file_name comments record_type )) { |
210 |
import_status batch_type file_name comments record_type marctag )) { |
|
|
211 |
|
| 209 |
if (exists $params->{$_}) { |
212 |
if (exists $params->{$_}) { |
| 210 |
push @fields, $_; |
213 |
push @fields, $_; |
| 211 |
push @vals, $params->{$_}; |
214 |
push @vals, $params->{$_}; |
|
Lines 219-224
sub AddImportBatch {
Link Here
|
| 219 |
return $dbh->{'mysql_insertid'}; |
222 |
return $dbh->{'mysql_insertid'}; |
| 220 |
} |
223 |
} |
| 221 |
|
224 |
|
|
|
225 |
=head2 GetImportMarcAction |
| 226 |
|
| 227 |
my $marctag = GetImportMarcAction($batch_id); |
| 228 |
|
| 229 |
=cut |
| 230 |
|
| 231 |
sub GetImportMarcAction { |
| 232 |
my ($batch_id) = @_; |
| 233 |
my $dbh = C4::Context->dbh; |
| 234 |
my $sth = $dbh->prepare("SELECT * FROM import_batches WHERE import_batch_id = ?"); |
| 235 |
$sth->execute($batch_id); |
| 236 |
return $sth->fetchrow_hashref; |
| 237 |
} |
| 238 |
|
| 239 |
=head2 SetImportMarcAction |
| 240 |
|
| 241 |
SetImportMarcAction($batch_id, $marctag); |
| 242 |
|
| 243 |
=cut |
| 244 |
|
| 245 |
sub SetImportMarcAction { |
| 246 |
my ($batch_id, $marctag) = @_; |
| 247 |
my $dbh = C4::Context->dbh; |
| 248 |
my $sth = $dbh->prepare("UPDATE import_batches SET marctag = ? WHERE import_batch_id = ?"); |
| 249 |
$sth->execute($marctag, $batch_id); |
| 250 |
return; |
| 251 |
} |
| 252 |
|
| 222 |
=head2 GetImportBatch |
253 |
=head2 GetImportBatch |
| 223 |
|
254 |
|
| 224 |
my $row = GetImportBatch($batch_id); |
255 |
my $row = GetImportBatch($batch_id); |
|
Lines 323-329
sub ModAuthInBatch {
Link Here
|
| 323 |
|
354 |
|
| 324 |
=cut |
355 |
=cut |
| 325 |
|
356 |
|
| 326 |
sub BatchStageMarcRecords { |
357 |
sub BatchStageMarcRecords { |
| 327 |
my $record_type = shift; |
358 |
my $record_type = shift; |
| 328 |
my $encoding = shift; |
359 |
my $encoding = shift; |
| 329 |
my $marc_records = shift; |
360 |
my $marc_records = shift; |
|
Lines 332-337
sub BatchStageMarcRecords {
Link Here
|
| 332 |
my $branch_code = shift; |
363 |
my $branch_code = shift; |
| 333 |
my $parse_items = shift; |
364 |
my $parse_items = shift; |
| 334 |
my $leave_as_staging = shift; |
365 |
my $leave_as_staging = shift; |
|
|
366 |
my $marctag = shift; |
| 335 |
|
367 |
|
| 336 |
# optional callback to monitor status |
368 |
# optional callback to monitor status |
| 337 |
# of job |
369 |
# of job |
|
Lines 351-356
sub BatchStageMarcRecords {
Link Here
|
| 351 |
file_name => $file_name, |
383 |
file_name => $file_name, |
| 352 |
comments => $comments, |
384 |
comments => $comments, |
| 353 |
record_type => $record_type, |
385 |
record_type => $record_type, |
|
|
386 |
marctag => $marctag, |
| 354 |
} ); |
387 |
} ); |
| 355 |
if ($parse_items) { |
388 |
if ($parse_items) { |
| 356 |
SetImportBatchItemAction($batch_id, 'always_add'); |
389 |
SetImportBatchItemAction($batch_id, 'always_add'); |
|
Lines 611-616
sub BatchCommitRecords {
Link Here
|
| 611 |
$sth->execute($recordid, $rowref->{'import_record_id'}); |
644 |
$sth->execute($recordid, $rowref->{'import_record_id'}); |
| 612 |
$sth->finish(); |
645 |
$sth->finish(); |
| 613 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
646 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
|
|
647 |
} elsif ($record_result eq 'appendmarctag') { |
| 648 |
$num_updated++; |
| 649 |
$recordid = $record_match; |
| 650 |
my $tag = GetImportMarcAction($batch_id); |
| 651 |
my $marctag = $tag->{'marctag'}; |
| 652 |
my $mtag = substr($marctag,0,3); |
| 653 |
my $sub = substr($marctag,3); |
| 654 |
my $oldxml; |
| 655 |
if ($record_type eq 'biblio') { |
| 656 |
my ($count, $oldbiblio) = GetBiblio($recordid); |
| 657 |
$oldxml = GetXmlBiblio($recordid); |
| 658 |
my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}, $marc_type); |
| 659 |
foreach my $item_field ($old_marc->field($item_tag)) { |
| 660 |
$old_marc->delete_field($item_field); |
| 661 |
} |
| 662 |
$oldxml = $old_marc->as_xml($marc_type); |
| 663 |
|
| 664 |
my $sth=$dbh->prepare("SELECT * FROM marc_tag_structure WHERE tagfield=? AND frameworkcode=?"); |
| 665 |
if ($oldbiblio->{'frameworkcode'} eq '') { |
| 666 |
$sth->execute($mtag,''); |
| 667 |
} else { |
| 668 |
$sth->execute($mtag,$oldbiblio->{'frameworkcode'}); |
| 669 |
} |
| 670 |
my $data=$sth->fetchrow_hashref; |
| 671 |
|
| 672 |
if ($data->{'repeatable'} == 0) { |
| 673 |
my $new_marc = $old_marc->field($mtag); |
| 674 |
my $newvalue = $marc_record->field($mtag)->subfield($sub); |
| 675 |
my $oldvalue = $old_marc->field($mtag)->subfield($sub); |
| 676 |
##checking value if value is not duplicate update the marc tag. |
| 677 |
if ($oldvalue ne $newvalue) { |
| 678 |
$new_marc->delete_subfield(code => $sub); |
| 679 |
my $new_field = $marc_record->field($mtag); |
| 680 |
$new_field->update( $sub => $newvalue ); |
| 681 |
$old_marc->insert_fields_ordered($new_field); |
| 682 |
} |
| 683 |
} elsif($data->{'repeatable'} == 1 ) { |
| 684 |
my @value; |
| 685 |
my $i =0; |
| 686 |
my @oldvalue; |
| 687 |
my $j=0; |
| 688 |
foreach my $field_marc ($marc_record->field($mtag)) { |
| 689 |
@value[$i] = $field_marc->subfield($sub); |
| 690 |
$i = $i + 1; |
| 691 |
} |
| 692 |
foreach my $oldm ($old_marc->field($mtag)) { |
| 693 |
@oldvalue[$j] = $oldm->subfield($sub); |
| 694 |
$j = $j + 1; |
| 695 |
} |
| 696 |
for my $index (0 .. $#value) { |
| 697 |
#checking for duplicate values |
| 698 |
if ($value[$index] ne $oldvalue[$index]) { |
| 699 |
my $new = MARC::Field->new($mtag,'','',$sub => $value[$index]); |
| 700 |
$old_marc->insert_fields_ordered($new); |
| 701 |
} |
| 702 |
} |
| 703 |
} |
| 704 |
ModBiblio($old_marc, $recordid, $oldbiblio->{'frameworkcode'}); |
| 705 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
| 706 |
|
| 707 |
if ($item_result eq 'create_new') { |
| 708 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
| 709 |
$num_items_added = $bib_items_added; |
| 710 |
$num_items_errored = $bib_items_errored; |
| 711 |
} |
| 712 |
} else { |
| 713 |
$oldxml = GetAuthorityXML($recordid); |
| 714 |
ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record)); |
| 715 |
$query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?"; |
| 716 |
} |
| 717 |
my $sth = $dbh->prepare("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?"); |
| 718 |
$sth->execute($oldxml, $rowref->{'import_record_id'}); |
| 719 |
$sth = $dbh->prepare($query); |
| 720 |
$sth->execute($recordid, $rowref->{'import_record_id'}); |
| 721 |
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); |
| 722 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
| 614 |
} elsif ($record_result eq 'replace') { |
723 |
} elsif ($record_result eq 'replace') { |
| 615 |
$num_updated++; |
724 |
$num_updated++; |
| 616 |
$recordid = $record_match; |
725 |
$recordid = $record_match; |
|
Lines 1466-1471
sub _get_commit_action {
Link Here
|
| 1466 |
$bib_result = 'create_new'; |
1575 |
$bib_result = 'create_new'; |
| 1467 |
} elsif ($overlay_action eq 'ignore') { |
1576 |
} elsif ($overlay_action eq 'ignore') { |
| 1468 |
$bib_result = 'ignore'; |
1577 |
$bib_result = 'ignore'; |
|
|
1578 |
} elsif ($overlay_action eq 'appendmarctag') { |
| 1579 |
$bib_result = 'appendmarctag'; |
| 1469 |
} |
1580 |
} |
| 1470 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; |
1581 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; |
| 1471 |
} else { |
1582 |
} else { |