Merge branch 'new/enh/bug_4877'
[srvgit] / misc / migration_tools / rebuild_zebra.pl
index dadf43f..fa87f22 100755 (executable)
@@ -323,19 +323,17 @@ sub export_marc_records_from_sth {
                 my @items = GetItemsInfo($record_number);
                 if (@items){
                     my $record = MARC::Record->new;
+                    $record->encoding('UTF-8');
                     my @itemsrecord;
                     foreach my $item (@items){
                         my $record = Item2Marc($item, $record_number);                        
                         push @itemsrecord, $record->field($itemtag);
                     }
                     $record->insert_fields_ordered(@itemsrecord);
-                    my $itemsxml=$record->as_xml_record();
-                    my $searchstring = '<record>\n';
-                    my $index = index($itemsxml, '<record>\n', 0);
-                    $itemsxml = substr($itemsxml, $index + length($searchstring));
-                    $searchstring = '</record>';
-                    $marcxml = substr($marcxml, 0, index($marcxml, $searchstring));
-                    $marcxml .= $itemsxml;
+                    my $itemsxml = $record->as_xml_record();
+                    $marcxml =
+                        substr($marcxml, 0, length($marcxml)-10) .
+                        substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10);
                 }
             }
             if ( $marcxml ) {
@@ -433,10 +431,7 @@ sub get_corrected_marc_record {
 
     if (defined $marc) {
         fix_leader($marc);
-        if ($record_type eq 'biblio') {
-            my $succeeded = fix_biblio_ids($marc, $record_number);
-            return unless $succeeded;
-        } else {
+        if ($record_type eq 'authority') {
             fix_authority_id($marc, $record_number);
         }
         if (C4::Context->preference("marcflavour") eq "UNIMARC") {
@@ -468,7 +463,7 @@ sub get_raw_marc_record {
             $fetch_sth->finish();
             return unless $marc;
         } else {
-            eval { $marc = GetMarcBiblio($record_number); };
+            eval { $marc = GetMarcBiblio($record_number, 1); };
             if ($@ || !$marc) {
                 # here we do warn since catching an exception
                 # means that the bib was found but failed
@@ -477,8 +472,6 @@ sub get_raw_marc_record {
                 return;
             }
         }
-        # ITEM
-        C4::Biblio::EmbedItemsInMarcBiblio($marc, $record_number);
     } else {
         eval { $marc = GetAuthority($record_number); };
         if ($@) {