- # Moving subscriptions from the other record to the reference record
- my $subcount = CountSubscriptionFromBiblionumber($frombiblio);
- if ($subcount > 0) {
- $sth = $dbh->prepare("UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?");
- $sth->execute($tobiblio, $frombiblio);
-
- $sth = $dbh->prepare("UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?");
- $sth->execute($tobiblio, $frombiblio);
-
+ my $sth_subscription = $dbh->prepare("
+ UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
+ ");
+ my $sth_subscriptionhistory = $dbh->prepare("
+ UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
+ ");
+ my $sth_serial = $dbh->prepare("
+ UPDATE serial SET biblionumber = ? WHERE biblionumber = ?
+ ");
+ my $sth_suggestions = $dbh->prepare("
+ UPDATE suggestions SET biblionumber = ? WHERE biblionumber = ?
+ ");
+
+ my $report_header = {};
+ foreach my $biblionumber ($ref_biblionumber, @biblionumbers) {
+ # build report
+ my $marcrecord = GetMarcBiblio({ biblionumber => $biblionumber });
+ my %report_record = (
+ biblionumber => $biblionumber,
+ fields => {},
+ );
+ foreach my $field (@report_fields) {
+ my @marcfields = $marcrecord->field($field->{tag});
+ foreach my $marcfield (@marcfields) {
+ my $tag = $marcfield->tag();
+ if (scalar @{$field->{subfields}}) {
+ foreach my $subfield (@{$field->{subfields}}) {
+ my @values = $marcfield->subfield($subfield);
+ $report_header->{ $tag . $subfield } = 1;
+ push @{ $report_record{fields}->{$tag . $subfield} }, @values;
+ }
+ } elsif ($field->{tag} gt '009') {
+ my @marcsubfields = $marcfield->subfields();
+ foreach my $marcsubfield (@marcsubfields) {
+ my ($code, $value) = @$marcsubfield;
+ $report_header->{ $tag . $code } = 1;
+ push @{ $report_record{fields}->{ $tag . $code } }, $value;
+ }
+ } else {
+ $report_header->{ $tag . '@' } = 1;
+ push @{ $report_record{fields}->{ $tag .'@' } }, $marcfield->data();
+ }
+ }
+ }
+ push @report_records, \%report_record;