From: Bill Erickson Date: Tue, 25 Oct 2016 21:06:03 +0000 (-0400) Subject: JBAS-1437 Backstage 010z replace records X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b7962653a58265dac54aa2e4af536ae32195c73b;p=working%2FEvergreen.git JBAS-1437 Backstage 010z replace records Replace authority records whose 010a matches the 010z value for inbound records. Also avoid looking up deleted records when looking for matches. Signed-off-by: Bill Erickson --- diff --git a/KCLS/backstage/process-backstage-files.pl b/KCLS/backstage/process-backstage-files.pl index de0fa646b4..27d96dd553 100755 --- a/KCLS/backstage/process-backstage-files.pl +++ b/KCLS/backstage/process-backstage-files.pl @@ -306,6 +306,8 @@ sub handle_modified_auths { while (my $record = $marc_batch->next()) { my @matches = find_matching_auths($record); + push(@matches, find_replaced_auths($record)); + my $marcxml = clean_marc($record->as_xml_record()); if (@matches) { @@ -351,6 +353,25 @@ sub insert_auth { if $new_auth_ctr % $log_mod == 0; } +# Return ID's of authority records that should be replaced by the +# current record. Checks for records whose 010$a equals the 010$z of +# the current record. +# 010$z == Canceled/invalid LC control number +sub find_replaced_auths { + my $record = shift; + + my $subfield = $record->subfield('010', 'z'); + return () unless $subfield; + + $match_auth_sth->execute('010', $subfield); + my $matches = $match_auth_sth->fetchall_arrayref; + my @ids = map {$_->[0]} @$matches; + + announce('INFO', "Auth 010z=$subfield matched records: @ids") if @ids; + + return @ids; +} + # Return ID's of matching authority records. Matching tries: # 001 -> 010a -> 035a. sub find_matching_auths { @@ -365,12 +386,10 @@ sub find_matching_auths { $match_auth_001_sth->execute($subfield); my $matches = $match_auth_001_sth->fetchall_arrayref; - - if (@$matches) { # DEBUGGING... - my @ids = map {$_->[0]} @$matches; - announce('INFO', "Auth 001=$subfield matched records: @ids"); - } - return map {$_->[0]} @$matches if @$matches; + my @ids = map {$_->[0]} @$matches; + announce('INFO', + "Auth 001=$subfield matched records: @ids") if @ids; + return @ids; } } @@ -387,7 +406,10 @@ sub find_matching_auths { $match_auth_sth->execute($tag, $subfield); my $matches = $match_auth_sth->fetchall_arrayref; - return map {$_->[0]} @$matches; + my @ids = map {$_->[0]} @$matches; + announce('INFO', "Auth ${tag}a=$subfield matched records: @ids") if @ids; + + return @ids; } sub prepare_statements { @@ -419,18 +441,24 @@ sub prepare_statements { SQL $match_auth_sth = $db_handle->prepare(<<" SQL"); - SELECT DISTINCT(record) - FROM authority.full_rec + SELECT DISTINCT(rec.id) + FROM authority.record_entry rec + JOIN authority.full_rec frec ON (frec.record = rec.id) WHERE - tag = ? - AND subfield = 'a' - AND value = NACO_NORMALIZE(?, 'a') + NOT rec.deleted + AND frec.tag = ? + AND frec.subfield = 'a' + AND frec.value = NACO_NORMALIZE(?, 'a') SQL $match_auth_001_sth = $db_handle->prepare(<<" SQL"); - SELECT DISTINCT(record) - FROM authority.full_rec - WHERE tag = '001' AND value = ? + SELECT DISTINCT(rec.id) + FROM authority.record_entry rec + JOIN authority.full_rec frec ON (frec.record = rec.id) + WHERE + NOT rec.deleted + AND frec.tag = '001' + AND frec.value = ? SQL }