From bd4f3d5691bcd454e4c7e8e713e981e3b61d1b09 Mon Sep 17 00:00:00 2001
From: Jared Camins-Esakov <jcamins@cpbibliography.com>
Date: Sat, 11 May 2013 16:07:43 -0400
Subject: [PATCH] [PASSED QA] Bug 10230: show correct matching record

The correct matching record was not always shown on the manage staged
MARC page. This patch corrects the issue and provides the template with
the appropriate ID for the matched record regardless what type of record
it is.

To test:
1) Create a matching record for authorities. For MARC21, the following
   is a good choice:
   Matching rule code:  AUTHPER
   Description:         Personal name main entry
   Match threshold:     999
   Record type:         Authority record
   [Match point 1:]
    Search index:   mainmainentry
    Score:          1000
    Tag:            100
    Subfields:      a
2) Create a record that has the appropriate fields for being matched
   with that rule (if you don't already have one).
3) Save the authority record as MARC (Unicode/UTF-8).
4) Stage the file choosing your new matching rule.
5) Note that with these patches, you get a link to the existing
   authority and without them you could get any number of strange
   things.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script. Additional tests done:
- staged bibliographic records and matched with different
  rules and actions. Undid the import.
- staged autohrity recods and matched with the example rule.
  Undid the import.
---
 tools/manage-marc-import.pl |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl
index 32d3645..25f7769 100755
--- a/tools/manage-marc-import.pl
+++ b/tools/manage-marc-import.pl
@@ -365,12 +365,17 @@ sub import_records_list {
 
         my $match = GetImportRecordMatches($record->{'import_record_id'}, 1);
         my $match_citation = '';
+        my $match_id;
         if ($#$match > -1) {
             if ($match->[0]->{'record_type'} eq 'biblio') {
                 $match_citation .= $match->[0]->{'title'} if defined($match->[0]->{'title'});
                 $match_citation .= ' ' . $match->[0]->{'author'} if defined($match->[0]->{'author'});
+                $match_id = $match->[0]->{'biblionumber'};
             } elsif ($match->[0]->{'record_type'} eq 'auth') {
-                $match_citation .= $match->[0]->{'authorized_heading'} if defined($match->[0]->{'authorized_heading'});
+                if (defined($match->[0]->{'authorized_heading'})) {
+                    $match_citation .= $match->[0]->{'authorized_heading'};
+                    $match_id = $match->[0]->{'candidate_match_id'};
+                }
             }
         }
 
@@ -383,7 +388,7 @@ sub import_records_list {
             overlay_status           => $record->{'overlay_status'},
             # Sorry about the match_id being from the "biblionumber" field;
             # as it turns out, any match id will go in biblionumber
-            match_id                 => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0,
+            match_id                 => $match_id,
             match_citation           => $match_citation,
             match_score              => $#$match > -1 ? $match->[0]->{'score'} : 0,
             record_type              => $record->{'record_type'},
-- 
1.7.9.5