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