From 029a7a36aa10371f28eb31d7412281d4d3451607 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Thu, 21 Jul 2011 10:18:55 -0400 Subject: [PATCH] Treat OCLC numbers specially in maintain_control_numbers For some reason, many records that come with OCLC numbers in the 001 field are not populated with a 003 field. This resulted in the OCLC number being thrown away entirely, rather than being moved into the 035, as there was no corresponding control number identifier field. However, given that we know that control numbers starting with "ocm" or "ocn" are special OCLC numbers, we can generate the 035 accordingly even in the absence of a 003. This update to maintain_control_numbers() teaches it to do the right thing for OCLC numbers. In addition, add an identifier search index so we can easily find records by their system control numbers (035 $a subfields). Signed-off-by: Dan Scott Signed-off-by: Bill Erickson --- Open-ILS/src/sql/Pg/002.functions.config.sql | 20 +++++++++++++++++++- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql index b857418e1a..e8c7fef5c6 100644 --- a/Open-ILS/src/sql/Pg/002.functions.config.sql +++ b/Open-ILS/src/sql/Pg/002.functions.config.sql @@ -562,20 +562,38 @@ foreach my $id_field ('001', '003') { } } +my $cn = $record->field('001')->data(); +# Special handling of OCLC numbers, often found in records that lack 003 +if ($cn =~ /^oc[nm]/) { + $cn =~ s/^oc[nm]0*(\d+)/$1/; + $record->field('003')->data('OCoLC'); +} + # Now, if we need to munge the 001, we will first push the existing 001/003 # into the 035; but if the record did not have one (and one only) 001 and 003 # to begin with, skip this process if ($munge and not $create) { - my $scn = "(" . $record->field('003')->data() . ")" . $record->field('001')->data(); + + my $scn = "(" . $record->field('003')->data() . ")" . $cn; # Do not create duplicate 035 fields unless (grep $_->subfield('a') eq $scn, @scns) { $record->insert_fields_ordered(MARC::Field->new('035', '', '', 'a' => $scn)); } + + # Update the list of SCNs to avoid duplicates + @scns = $record->field('035'); } # Set the 001/003 and update the MARC if ($create or $munge) { + my $scn = "(" . $record->field('003')->data() . ")" . $cn; + + # Do not create duplicate 035 fields + unless (grep $_->subfield('a') eq $scn, @scns) { + $record->insert_fields_ordered(MARC::Field->new('035', '', '', 'a' => $scn)); + } + $record->field('001')->data($rec_id); $record->field('003')->data($ou_cni); diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index d51043c09f..792dedf00f 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -86,6 +86,9 @@ INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) (26, 'identifier', 'tcn', oils_i18n_gettext(26, 'Title Control Number', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='901']/marc:subfield[@code='a']$$ ); INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES (27, 'identifier', 'bibid', oils_i18n_gettext(27, 'Internal ID', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='901']/marc:subfield[@code='c']$$ ); +-- 28 == authority_id in master +INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath) VALUES + (29, 'identifier', 'system_control_number', oils_i18n_gettext(28, 'System Control Number', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='035']/marc:subfield[@code="a"]$$); SELECT SETVAL('config.metabib_field_id_seq'::TEXT, (SELECT MAX(id) FROM config.metabib_field), TRUE); -- 2.11.0