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) {
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 {
$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;
}
}
$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 {
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
}