From e0e6390193d30bc4a247ec4566d6490b4c023237 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 --- Open-ILS/src/sql/Pg/002.functions.config.sql | 20 +++++++++++++++++++- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 2 ++ 2 files changed, 21 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 4574c8381c..227292947f 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 9cf3bbca3c..d5387632e4 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -97,6 +97,8 @@ INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) (27, 'identifier', 'bibid', oils_i18n_gettext(27, 'Internal ID', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='901']/marc:subfield[@code='c']$$ ); INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, search_field, facet_field) VALUES (28, 'identifier', 'authority_id', oils_i18n_gettext(28, 'Authority Record ID', 'cmf', 'label'), 'marcxml', '//marc:datafield/marc:subfield[@code="0"]', FALSE, TRUE); +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